Files
ewelink-api/docs/zeroconf.md
Martin M c11b3a8ab7 Release v3.0.0 (#85)
* updated dependencies

* code linting

* added new app id & app secret

* cleanup requests payloads

* remove unused function

* update test cases

* enabled firmware tests

* refactor getDevice to use right api endpoint

* error messages improvements

* error messages improvements

* error messages improvements

* error messages improvements

* error messages improvements

* payload cleanup

* refactor setDevicePowerState to use right api endpoint

* update test exepectation

* removed deprecated class

* updated tests to reflect new error codes

* error messages improvements

* refactoring project structure: devices methods

refactoring project sturcture

* refactoring project structure: firmware methods

* refactoring project structure: temperature/humidity

* refactoring project structure: credentials methods

* refactoring project structure: power usage methods

* refactoring project structure: power state methods

* refactoring project structure: websocket methods

* removed deprecated login method from docs

* refactoring project structure: power usage methods

* refactoring project structure: zeroconf classes

* refactoring project structure: websocket classes

* refactoring project structure: zeroconf classes

* refactor and cleanup

* refactoring project structure: firmware methods

* moved parsers to own directory

* update tests with methods renames

* export missing temperature/humidity methods

* removed unused package

* refactor and cleanup

* fix test expectation

* refactoring project structure: moved data files

* refactoring project structure: moved data files

* refactoring project structure: moved helpers files

* refactoring project structure: moved helpers files

* refactoring project structure: moved payload files

* refactor and cleanup

* refactor getDevicePowerState

* setDevicePowerState returns channel

* convert error 400 to 404 for clarity

* updated test cases

* remove console.log

* cache path for zeroconf cache files

* installed nock

* using nock to simulate server requests during testing

* moved credentials file to config folder

* update request url when using nock

* refactor nock helper file

* move cooldown delay to setupTests file

* updating testing instructions

* restored delete code block

* fix wrong error code

* accept phone number to login to ewelink

* added test cases for initialize main class

* improvements on class initialization parameters

* allow login using phone number

* rename test file

* updated test case

* fixed regression bug

* Release v3.0.0 - use node-fetch (#87)

* replaced deprecated request library with node-fetch

* refactor: moved makeRequest to own mixin file

* refactor to use node-fetch

* fixes

* update config

* created helper method

* constant rename

* ignore files from final package

* version bump
2020-05-23 03:07:52 -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/src/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/src/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');