@bouzuya/irkit
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

node-irkit

An IRKit Device / Internet HTTP API wrapper for Node.js.

Installation

npm install @bouzuya/irkit

Usage

See example/.

IRKitDevice (IRKit Device HTTP API)

import { IRKitDevice, Message, Security } from '@bouzuya/irkit';

const main = async () => {
  // options.ip or `process.env.IRKIT_DEVICE_IP`
  const device = new IRKitDevice({ ip: '192.168.1.1' });

  // IRKitDevice.prototype.getMessages()
  // GET /messages
  const message: Message = await device.getMessages();
  if (message !== null) {
    console.log(message);
    // {"format":"raw","freq":38,"data":[18031, ...]}
  }

  // IRKitDevice.prototype.postMessages()
  // POST /messages
  await device.postMessages({
    format: 'raw',
    freq: 38,
    data: [ /* ... */ ]
  });

  // IRKitDevice.prototype.postKeys()
  // POST /keys
  const keys = await device.postKeys();
  console.log(keys);
  // {"clienttoken":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}

  // IRKitDevice.prototype.postWifi()
  // POST /wifi
  await device.postWifi({
    devicekey: /* ... */,
    password: /* ... */,
    security: Security.WPA_WPA2,
    ssid: /* ... */
  });
};

main();

IRKit (IRKit Internet HTTP API)

import { IRKit, IRKitDevice } from '@bouzuya/irkit';

const main = async () => {
  const device = new IRKitDevice({ ip: '192.168.1.1' });
  const client = new IRKit();

  // IRKit.prototype.postKeys()
  // POST /1/keys
  const { clienttoken } = await device.postKeys();
  const keys = await client.postKeys({ clienttoken });
  console.log(keys);
  // { deviceid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', clientkey: 'XXXXXXXXXXXXXXXXXXXXXXX' }

  // IRKit.prototype.postMessages()
  // POST /1/messages
  const messages = await client.postMessages({
    clientkey: keys.clientkey,
    deviceid: keys.deviceid,
    message: {
      format: 'raw',
      freq: 38,
      data: [ /* ... */ ]
    }
  });

  // IRKit.prototype.getMessages()
  // GET /1/messages
  const messages = await client.getMessages({
    clientkey: keys.clientkey
  });
  if (messages !== null) {
    console.log(messages);
    // {"message":{"format":"raw","freq":38,"data":[18031,...]},"hostname":"IRKitD2A4","deviceid":"FBEC7F5148274DADB608799D43175FD1"}
  }

  // IRKit.prototype.postClients()
  // POST /1/clients
  const clients = await client.postClients({
    apikey: keys.apikey
  });
  console.log(clients);
  // {"clientkey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}

  // IRKit.prototype.postDevices()
  // POST /1/devices
  const devices = await client.postDevices({
    clientkey: keys.clientkey
  });
  console.log(devices);
  // {"devicekey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","deviceid":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}

  // IRKit.prototype.postDoor()
  // POST /1/door
  const door = await client.postDoor({
    clientkey: keys.clientkey,
    deviceid: devices.deviceid
  });
  console.log(door);
  // {"hostname":"IRKitXXXX"}


  // IRKit.prototype.postApps()
  // POST /1/door
  const app = await client.postApps({
    email: 'mail@example.com'
  });
  console.log(app);
  // {"message":"You will receive an email shortly, please click the URL in it to get an apikey"}

};

main();

APIs

IRKit Device HTTP API

  • GET /messages
  • POST /messages
  • POST /keys
  • POST /wifi

IRKit Internet HTTP API

  • POST /1/keys
  • POST /1/messages
  • GET /1/messages
  • POST /1/clients
  • POST /1/devices
  • POST /1/door
  • POST /1/apps

Badges

npm version Travis CI

License

src/irkit-device-key-serializer.ts

MIT mash

others

MIT

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)

Readme

Keywords

none

Package Sidebar

Install

npm i @bouzuya/irkit

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

15.7 kB

Total Files

15

Last publish

Collaborators

  • bouzuya