Files
ewelink-api/docs/zeroconf.md
Martin M 098011b285 Release v2.0.0 (#44)
* Added arpTableSolver (#18)

* Added arpTableSolver

* fix package import

* linting class

* changed arp library

* refactor arp class

* using arpping fork

* refactor arpTableSolver class

* Added Zero Conf functionality (LAN mode) (#46)

* added crypto-js

* zeroconf helper functions

* zeroconf update payload

* new method to save devices cache file

* class renamed

* refactor Zeroconf class

* return cached device if exists

* moved method to get local ip address

* fix mac addresses without leading zeroes

* refactor Zeroconf class

* using new zeroconf functionality

* zeroconf working with single and multichannel devices

* save device mixin enhancement

* working on zeroconf test cases

* catch errors on filesystem methods

* zeroconf: added extra test cases

* better error handling

* zeroconf: 100% code coverage

* removed deprecated login method

* updates on credentials file

* version bump

* Docs for v2.0 (#52)

* added v1 docs

* added zeroconf docs

* updated readme

* docs updated

* removed zeroconf article warning

* updated vscode config

Co-authored-by: Luis Llamas <luisllamas@hotmail.com>
2020-01-11 01:39:29 -03:00

1.7 KiB

Zeroconf (LAN mode)

Zeroconf only works if you're connected to the same network of the device you wanna control.

Notes

  • at this time, only turn on/off action is available.
  • after initial setup, internet connection is not required to turn on/off your devices.

Introduction

Before start, you will need to create 2 files with information about your devices (the library includes methods to generate both files).

  1. a cache file with information about your devices.
  2. an "arp table" cache file with info from your network connected devices.
  3. toggle specific device power state

1. Generate devices cache file

const ewelink = require('ewelink-api');

const connection = new ewelink({
  email: '<your ewelink email>',
  password: '<your ewelink password>',
  region: '<your ewelink region>',
});

await connection.saveDevicesCache();

A file named devices-cache.json will be created.

2. Generate arp table cache file

const Zeroconf = require('ewelink-api/classes/Zeroconf');

await Zeroconf.saveArpTable({
  ip: '<your network addres, ex: 192.168.5.1>'
});

A file named arp-table.json will be created.

3. toggle device power state

const ewelink = require('ewelink-api');
const Zeroconf = require('ewelink-api/classes/Zeroconf');

/* load cache files */
const devicesCache = await Zeroconf.loadCachedDevices();
const arpTable = await Zeroconf.loadArpTable();

/* create the connection using cache files */
const connection = new ewelink({ devicesCache, arpTable });

/* turn device on */
await connection.setDevicePowerState('<your device id>', 'on');

/* turn device off */
await connection.setDevicePowerState('<your device id>', 'off');