mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 13:23:05 +01:00
* 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>
1.5 KiB
1.5 KiB
openWebSocket
Opens a socket connection to eWeLink and listen for realtime events.
Usage
The openWebSocket method requires a callback function as an argument.
Once an event is received, the callback function will be executed with the server message as argument.
// instantiate class
const connection = new ewelink({
email: '<your ewelink email>',
password: '<your ewelink password>',
region: '<your ewelink region>',
});
// login into eWeLink
await connection.login();
// call openWebSocket method with a callback as argument
const socket = await connection.openWebSocket(async data => {
// data is the message from eWeLink
console.log(data)
});
Response example
If everything went well, the first message will have the following format:
{
error: 0,
apikey: '12345678-9012-3456-7890-123456789012',
config: {
hb: 1,
hbInterval: 12345
},
sequence: '1234567890123'
}
When a device change his status, a similar message will be returned:
{
action: 'update',
deviceid: '1234567890',
apikey: '12345678-9012-3456-7890-123456789012',
userAgent: 'device',
sequence: '1234567890123'
ts: 0,
params: {
switch: 'on'
},
from: 'device',
seq: '11'
}
Notes
- Because of the nature of a socket connection, the script will keep running until the connection gets closed.
openWebSocketwill return the socket instance- if you need to manually kill the connection, just run
socket.close()(where socket is the variable used).