skydiver / ewelink-api

eWeLink API for JavaScript
https://www.npmjs.com/package/ewelink-api
MIT License
265 stars 109 forks source link

RF bridge support question #74

Open rtomasik opened 4 years ago

rtomasik commented 4 years ago

Is there any chance to send data to rf bridge? openWebSocket listen data form rf bridge but how we can send data to rf bridge?

data recived: { action: 'update', deviceid: 'xxx', apikey: 'xxxx', userAgent: 'app', sequence: '1582506488423', ts: 0, params: { cmd: 'transmit', rfChl: 0 }, tempRec: 'xxxxx' }

skydiver commented 4 years ago

Hey @rtomasik

I don't have a rf bridge device.

Hope someone else can answer that question.

foulek57 commented 4 years ago

Hi all,

Here my code :

var express = require('express'); 
var hostname = 'localhost'; 
var portServer = 6005;
var app = express(); 
const ewelink = require('ewelink-api');
var request = require('request');

 const socket = await connection.openWebSocket
      (
        async data => 
        {
 app.get('/sync', function(req, res) 
          {
            ( async () => 
                {
                  var device_id = DEVICEID;
                  var apikey = APIKEY;
                  var channel = RFCHL;

                    const timeStamp = new Date() / 1000;
                    const sequence = Math.floor(timeStamp * 1000);
                    var payload = {};
                    payload.action = 'update';
                    payload.userAgent = 'app';
                    payload.apikey = '' + apikey;
                    payload.deviceid = '' + device_id;
                    payload.sequence = '' + sequence;
                  payload.params = {};
                  payload.params.cmd = 'transmit';
                  payload.params.rfChl = channel;
                    var string = JSON.stringify(payload);
                    socket.send(string);
                }
 )();
          });   
)();

var server = app.listen(portServer, hostname, function()
    {
      var date = new Date();
      console.log("Serveur correctement lancé sur http://"+ hostname +":"+ portServer + " Le " + date); 
    });

I send trought the socket the payload. I also run a server to send http request

@skydiver any way to add this to your script ?

rtomasik commented 4 years ago

@foulek57 thank you, i will test it.

@skydiver How to use LAN mode? Everywhere there are examples with logging in through ewelink account.

sickao3 commented 4 years ago

@rtomasik I have a pull request where I solved the RF Bridge connection

https://github.com/sickao3/ewelink-api