Code Monkey home page Code Monkey logo

Comments (46)

murtaza9000 avatar murtaza9000 commented on May 28, 2024 1

yes I also saw the issues. what I am able to do is to getdevices. You can do it by updating the following parameter under node-modules/ewelink-api/mixins/devices/getDevicesMixin.js ,

`const getDevicesMixin = {
async getDevices() {
return this.makeRequest({
uri: '/user/device',
qs: { lang: 'en', getTags: 1,

apiKey : '<insert apikey can be find by login',
getTag : '1',
version : '6',
ts : '' + Math.floor(new Date().getTime() / 1000),

// nounce : '' + nonce(),
appid : 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq', //this is fixed
imei : 'xxxxxxxxxxxx',
os : 'android',
model : '',
romVersion : '',
appVersion : ''

},
});

},
};

module.exports=getDevicesMixin;
`

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hello @primalnow

All tests has passed.

Did a few manual tests and get expected results on:

  • getDevices
  • setDevicePowerState

Where did you see these changes? Any link to investigate?

Thanks.-

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

Changes were discussed here: peterbuga/HASS-sonoff-ewelink#162

My server is 'as'

If I don't do the "(async () => ", I get "SyntaxError: await is only valid in async function"

Websocket is working fine. But other commands give a '400'

`
const ewelink = require('ewelink-api');
(async () => {
const connection = new ewelink({
email: '[email protected]',
password: 'xxx',
region: 'as'
});

console.log('connection', connection);

const login = await connection.login();

const accessToken = login.at;
const apiKey = login.user.apikey

console.log('login details -> ' , login);

const socket = await connection.openWebSocket(async data => {
    console.log('data <-' , data)
});

const devices = await connection.getDevices();
console.log('all devices' , devices);

const device = await connection.getDevice('xxx');
console.log('a device' , device);

const status = await connection.toggleDevice('xxx');
console.log('bay on' , status);

})();`

Output:

connection eWeLink { region: 'as', email: '[email protected]', password: 'xxx', at: undefined, apiKey: undefined } login details -> { at: 'xxx', rt: 'xxx', user: { _id: 'xxx', email: '[email protected]', password: 'xxx', appId: 'xxx', createdAt: '2019-05-09T17:23:22.679Z', apikey: 'xxx', __v: 0, lang: 'en', online: true, onlineTime: '2019-10-17T04:17:05.120Z', appInfos: [ [Object], [Object] ], ip: '182.179.187.115', location: '', offlineTime: '2019-10-17T04:16:50.552Z', userStatus: '2', bindInfos: { gaction: [Array] } }, region: 'as' } data <- { error: 0, apikey: 'xxxx', config: { hb: 1, hbInterval: 145 }, sequence: 'xxx' } all devices { error: 400, msg: 'params incomplete' } a device { code: 400, error: 'params is incomplete' } data <- { action: 'sysmsg', deviceid: '1000xxx apikey: 'xxx5', ts: 0, params: { online: false } } bay on { error: 'params is incomplete', msg: 'Device does not exist' } data <- { action: 'sysmsg', deviceid: '1000xxx', apikey: 'xxx02c0e8', ts: 0, params: { online: true } }

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hey @primalnow

I can't reproduce your error, everything works fine to me.

Which device are you using?
From the link you posted, i see there are errors with a Sonoff POW R2.

I've tested with this device and i was able to turn on/off, get power consumption.

Thanks.-

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

from ewelink-api.

narus2 avatar narus2 commented on May 28, 2024

Good afternoon.
I also see a mistake about using a token

const connection = new ewelink ({
     at: '<valid access token>',
   });

Using Email and password - works
valid access token - get with

const auth = connection.login ();
  console.log ('access token:', auth.at);

from ewelink-api.

sanketmehta7 avatar sanketmehta7 commented on May 28, 2024

Thanks @murtaza9000 that worked for me, to getDevices.
Below replacement will work. (better formatted)

async getDevices() {
    return this.makeRequest({
        uri: '/user/device',
        qs: {
            lang: 'en',
            getTags: 1,
            version: '6',
            ts: '' + Math.floor(new Date().getTime() / 1000),
            appid: 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq',
            imei: 'xxxxxxxxxxxx',
            os: 'android',
            model: '',
            romVersion: '',
            appVersion: ''
        }
    });
}

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hello @murtaza9000 and @sanketmehta7

Do you wanna make a PR so we can add these changes?

Thanks.-

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

Thanks for the update. But the error persists. At least for the CN/AS server.

from ewelink-api.

sanketmehta7 avatar sanketmehta7 commented on May 28, 2024

I can make PR...also issue with other apis still remains (having added same param to them), I couldn't get getDevice & toggleState (ws api) working...just able to get above devices list only. Any one tried mix of param with success can help with those remaining api params...Also any body know how to reverse proxy api calls from the app itself, to debug req/res data.

I tried Charles proxy but not able to decode ssl url data.

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hey @sanketmehta7

This is strange because i cannot reproduce any of those errors.

Tests are passing successfully.

Can you try to run npm run test and let me know which ones are failing?

Also, which region are you using?

from ewelink-api.

murtaza9000 avatar murtaza9000 commented on May 28, 2024

I can make PR...also issue with other apis still remains (having added same param to them), I couldn't get getDevice & toggleState (ws api) working...just able to get above devices list only. Any one tried mix of param with success can help with those remaining api params...Also any body know how to reverse proxy api calls from the app itself, to debug req/res data.

I tried Charles proxy but not able to decode ssl url data.

Actually true, I was only able to make it work with getdevices. Not with other. Yes @skydiver you may do PR at least for this. But any luck for other apis @sanketmehta7 . And are you have session out issue from the application "ewelink"?

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Guys, i've created a new branch issue-21-test

There is a new method, getDeviceAlt.

This can be tested on this way:

  1. clone repo and switch branch
  2. create test.js file on repo root
  3. run this code:
const ewelink = require('./main');

(async () => {

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

  await connection.login();

  const device = await connection.getDeviceAlt('your device id');
  console.log(device);

})();

setDevicePowerState request was also updated, let me know if works too

Thanks

from ewelink-api.

murtaza9000 avatar murtaza9000 commented on May 28, 2024

Hi @skydiver ,

So, getDeviceAlt is working fine but setDevicePowerState is giving me the error:

const status = await connection.setDevicePowerState('device id', 'on');
{ error: 'params is incomplete', msg: 'Device does not exist' }

Once I update setDevicePowerStateMixin.js

line 17 : to const device = await this.getDeviceAlt(deviceId);

It fixed.

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hey @murtaza9000

Thanks for the feedback.

I've updated setDevicePowerStateMixin.js to use the new method.

If everything works fine, we can replace the original getDevice and fix the issue.

from ewelink-api.

quan-th avatar quan-th commented on May 28, 2024

Hi @skydiver,
I'm new, I'm trying to use getDevicePowerUsage but it seems failed too. I think the reasons here:
https://github.com/skydiver/ewelink-api/blob/master/mixins/powerUsage/getDevicePowerUsageMixin.js#L14

https://github.com/skydiver/ewelink-api/blob/master/mixins/powerUsage/getDeviceRawPowerUsageMixin.js#L14

Can you check this?

By the way, do you have any other docs about ewelink-api? im reading
https://ewelink-api.now.sh/docs/available-methods

Thanks

from ewelink-api.

murtaza9000 avatar murtaza9000 commented on May 28, 2024

Hi @skydiver . Its fine working perfect.
Thanks for quick fixes

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hello everyone:

This PR tries to solve errors reported on this thread: https://github.com/skydiver/ewelink-api/pull/26/files

getDevice was replaced with the new method (getDeviceAlt was removed).

Will be great if we can get someone else who can test and confirm is working.

Thanks.-

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

@skydiver
= = = S O L V E D for Release 1.8.0 = = =

I'm using the current version without any of the patches...

I had the same problem trying to use ewelink-api with alternative access method using apikey, I noticed the response returned the region as the us, I'm in the EU.

with code:
const anotherNewConnection = new ewelink({ at: login.at, apiKey: login.user.apikey});
console.log("anotherNewConnection :: " + JSON.stringify(anotherNewConnection));
response = await anotherNewConnection.getDevices();
console.log("Devices :: " + JSON.stringify(response,null,4));

I get:

anotherNewConnection :: {"region":"us","at":"16c482b01afaf36e237c7329e76c7356e45d69f4","apiKey":"45b2b2ba-037e-4819-8ee5-09553a6f2119"}
Device :: {"error":401,"msg":"Authentication error"}

If I add the region to the new connection, ie:
const anotherNewConnection = new ewelink({ at: login.at, apiKey: login.user.apikey, region: login.region});

I get:
anotherNewConnection ::
{"region":"eu","at":"a128b75f15eabcf8315ca82c5a33b6ab6c88d975","apiKey":"45b2b2ba-037e-4819-8ee5-09553a6f2119"}
Devices :: [
{
"_id": "5dc29f913e1c64655f4f9890",
"name": "L1",
"type": "10",
. . .
. . .

And everything works OK !
Tried getDevice & getDevices !

--
Steve

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

Problem persists:
Used the code as given on https://ewelink-api.now.sh/docs/demos/node
My server is CN.
Have a few console.log in place to see the output. This is what I get

connection eWeLink {
region: 'cn',
email: 'xxxx',
password: 'xxx',
at: undefined,
apiKey: undefined
}

devices { error: 400, msg: 'params incomplete' }
device { code: 400, error: 'params is incomplete' }

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

Problem persists:
Used the code as given on https://ewelink-api.now.sh/docs/demos/node
My server is CN.
Have a few console.log in place to see the output. This is what I get

connection eWeLink {
region: 'cn',
email: 'xxxx',
password: 'xxx',
at: undefined,
apiKey: undefined
}

devices { error: 400, msg: 'params incomplete' }
device { code: 400, error: 'params is incomplete' }

If your using the login method you don't need the at or apiKey.

See comment below on use of region during login. I'd actually keep region for all connections, seems to influence which server is used and consequently access & speed.

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Hey @primalnow

Does the issue-21-test branch solves your problems?

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

Hey @primalnow

Does the issue-21-test branch solves your problems?

I didn't need to use the branch, just used the stock 1.8.0

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

Input:

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

(async () => {

const connection = new ewelink({
email: 'xxxxxxx',
password: 'xxxxxxx',
region: 'cn'
});

console.log('connection' , connection);

/* get all devices */
const devices = await connection.getDevices();
console.log('devices' , devices)

/* get specific devide info */
const device = await connection.getDevice('100078c852');
console.log('device' , device);

/* toggle device */
await connection.toggleDevice('10007797c8');

})();
`

Output:
`

MacBook-Pro:ewelink-node faisal$ node test.js
connection eWeLink {
region: 'cn',
email: 'xxxxxxxx',
password: 'xxxxxxxxx',
at: undefined,
apiKey: undefined
}
devices { error: 400, msg: 'params incomplete' }
device { code: 400, error: 'params is incomplete' }
MacBook-Pro:ewelink-node faisal$
`

`

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

Everyone:

The region parameter is required for everyone who is not using US servers, so, this is how you need to initialize the class:

const connection = new ewelink({
  email: '[email protected]',
  password: 'password',
  region: 'cn'
});
// possible regions: us, eu, cn, as
const connection = new ewelink({
  at: 'access token',
  region: 'us',
});

⚠️ this is important when you're using access token as authentication method ⚠️


More context: when using email and password with the wrong region (default is us), the login request fails, and performs a second login request with the right region.

So, not using region parameter is possible with email/password but not recommended since adds a few extra seconds to login because takes 2 api requests.

When using access token without region will fail with an error 400/401, so, in this scenario you MUST provide your region.

I believe the changes on issue-21-test branch are not needed, but will left open a few more days to get some input if using region parameter works for everyone.

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

MacBook-Pro:ewelink-node faisal$ npm list
/Volumes/http/ewelink-node
└─┬ [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]

Input:

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

(async () => {

const connection = new ewelink({
email: 'xxxxxxxx',
password: 'xxxxxxx',
region: 'cn'
});

console.log('connection' , connection);

/* get all devices */
const devices = await connection.getDevices();
console.log('devices' , devices);

/* get specific devide info */
const device = await connection.getDevice('');
console.log('device' , device);

/* toggle device */
await connection.toggleDevice('10006ac2c4');

})();

Output

MacBook-Pro:ewelink-node faisal$ node test.js
connection eWeLink {
region: 'cn',
email: 'xxxxxxx',
password: 'xxxxxx',
at: undefined,
apiKey: undefined
}
devices { error: 400, msg: 'params incomplete' }
device { code: 400, error: 'params is incomplete' }
MacBook-Pro:ewelink-node faisal$

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

Serverless - Copied from https://ewelink-api.now.sh/docs/demos/serverless

INPUT

const connection = new ewelink({
email: 'XXXXXXXX',
password: 'XXXXXXXX',
region: 'cn'
});

const login = await connection.login();

const accessToken = login.at;
const apiKey = login.user.apikey
const region = login.region;

const newConnection = new ewelink({
at: accessToken
region: region,
});
const devices = await newConnection.getDevices();
console.log(devices);

const thirdConnection = new ewelink({
at: accessToken
region: region,
});
const device = await thirdConnection.getDevice('10006ac2c4');
console.log(device);

const anotherNewConnection = new ewelink({
at: accessToken
region: region,
});
await anotherNewConnection.toggleDevice('10006ac2c4');

OUTPUT

MacBook-Pro:ewelink-node faisal$ node test-serverless.js
/Volumes/SD256/google_drive_20191001/http/ewelink-node/test-serverless.js:7
const login = await connection.login();
^^^^^

SyntaxError: await is only valid in async function
at Module._compile (internal/modules/cjs/loader.js:881:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
at Module.load (internal/modules/cjs/loader.js:798:32)
at Function.Module._load (internal/modules/cjs/loader.js:711:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
at internal/main/run_main_module.js:17:11
MacBook-Pro:ewelink-node faisal$

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

NODE SCRIPT - copied from https://ewelink-api.now.sh/docs/demos/node

INPUT

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

(async () => {

const connection = new ewelink({
email: 'XXXXXXX',
password: 'XXXXXXX',
region: 'cn'
});

const login = await connection.login();

console.log('connection' , connection);

/* get all devices */
const devices = await connection.getDevices();
console.log('devices' , devices);

/* get specific devide info */
const device = await connection.getDevice('');
console.log('device' , device);

/* toggle device */
await connection.toggleDevice('10006ac2c4');

})();

OUTPUT

MacBook-Pro:ewelink-node faisal$ node test.js
connection {
at: 'xxxxxxxxxx',
rt: 'xxxxxxxxxxx',
user: {
_id: 'xxxxxxxxx',
email: 'xxxxxxx',
password: 'xxxxxxxx',
appId: 'xxxxxxxx',
createdAt: '2019-05-09T17:23:22.679Z',
apikey: 'xxxxxxxxxxx',
__v: 0,
lang: 'en',
online: true,
onlineTime: '2019-11-11T12:13:51.533Z',
appInfos: [ [Object], [Object] ],
ip: '119.160.103.253',
location: '',
offlineTime: '2019-11-11T07:11:06.163Z',
userStatus: '2',
bindInfos: { gaction: [Array] }
},
region: 'as'
} eWeLink {
region: 'as',
email: 'fxxxxxx',
password: 'xxxxxxx',
at: 'xxxxxxxx',
apiKey: 'xxxxxxxxxxx'
}
devices { error: 400, msg: 'params incomplete' }
device { code: 400, error: 'params is incomplete' }
MacBook-Pro:ewelink-node faisal$

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

I'll have a proper look tomorrow, but a few observations inline bold and I've deleted a lot of code and replaced with . . .

NODE SCRIPT - copied from https://ewelink-api.now.sh/docs/demos/node
. . .
const connection = new ewelink({
. . .
region: 'cn'

Should you use "as" as the region as that is reported later on suggesting that's where you were registered.

});
. . .
const device = await connection.getDevice('');

connection.getDevice(''); MUST include a device id, eg 0123456789

console.log('device' , device);
. . .

OUTPUT

. . .
},
region: 'as'

server has reported you as being in region as

} eWeLink {
. . .

from ewelink-api.

peterbuga avatar peterbuga commented on May 28, 2024

fix for { code: 400, error: 'params is incomplete' } is in my code

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

fix for { code: 400, error: 'params is incomplete' } is in my code

Don't think you need any fixes, Release 1.8.0 & 1.8.1 work fine provided region is correctly set and no missing code.

from ewelink-api.

peterbuga avatar peterbuga commented on May 28, 2024

Don't think you need any fixes, Release 1.8.0 & 1.8.1 work fine provided region is correctly set and no missing code.

asian users keep getting bumped between cn and as regions, specifying a single region is not enough (also the fallback takes care of this making the "provided region is correctly" kinda useless or optional at best) this problem relies on another part of the code

from ewelink-api.

ferryariawan avatar ferryariawan commented on May 28, 2024

I'm using 1.8.1 and having the same issue (
Region: as
{ error: 400, msg: 'params incomplete' }

from ewelink-api.

ferryariawan avatar ferryariawan commented on May 28, 2024

In release 1.8.1, getDevicesMixin.js only have 2 params (lang and getTags)

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

In release 1.8.1, getDevicesMixin.js only have 2 params (lang and getTags)

@ferryariawan 1.8.1 just includes a new method called getRegion, which i believe wrong/missing region is the cause of a lot of errors found on this thread

from ewelink-api.

ferryariawan avatar ferryariawan commented on May 28, 2024

qs: {
lang: 'en',
getTags: 1,
version: '6',
ts: '' + Math.floor(new Date().getTime() / 1000),
appid: 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq',
imei: 'xxxxxxxxxxxx',
os: 'android',
model: '',
romVersion: '',
appVersion: ''
}

I get the getDevices to work after adding this to getDevicesMixin

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

@ferryariawan just released 1.8.2 who includes these changes

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

@peterbuga Thanks for jumping in :)

@skydiver Thanks for all your hard work. getDevices is working perfectly now.

However, nothing else is.

`
region { email: 'xxxxx', region: 'as' }

getDevicePowerState { error: 'params is incomplete', msg: 'Device does not exist' }

getDeviceCurrentTH { code: 400, error: 'params is incomplete' }

getDeviceChannelCount { error: 'params is incomplete', msg: 'Device does not exist' }

getDevice { code: 400, error: 'params is incomplete' }

toggleDevice { error: 'params is incomplete', msg: 'Device does not exist' }

`

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

@skydiver if you like I can share a few devices with you. Not sure if that would work. If you're willing to do it with me in real time, I can give you access to my ewelink account.

from ewelink-api.

ttz642 avatar ttz642 commented on May 28, 2024

After you have have done the Class Instantiation the connection has the region associated with the account, I think, can somebody having a problem with region try this?

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

console.log("region / server from Class Instantiation ",connection.region);

should now contain the region required by subsequent methods.

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

@ttz642 The latest update has fixed getDevices. It's the rest of the functions that are still not working.

from ewelink-api.

peterbuga avatar peterbuga commented on May 28, 2024

@ttz642 The latest update has fixed getDevices. It's the rest of the functions that are still not working.

when adding the new params to the /api/user/device due to constant inconsistencies in itead api the devices are returned differently at times, might be worth to check this

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

@peterbuga I tried with the exact device ID, returned by the getDevices command. I did not rely on the ID's in the app :-)

You know I'm thorough. :)

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

when adding the new params to the /api/user/device due to constant inconsistencies in itead api the devices are returned differently at times, might be worth to check this

hey @peterbuga i believe we already did this change on PR #26 on this file

Didn't merged yet because i'm not sure if it was really necessary or just by always using region was enough

from ewelink-api.

primalnow avatar primalnow commented on May 28, 2024

@skydiver tested with the getdevicemixin.js as given in #26, and everything works flawlessly. Kindly merge.

Thanks for all the hard work. Much appreciated.

from ewelink-api.

skydiver avatar skydiver commented on May 28, 2024

I've merged issue-21-test branch.

I'm gonna wait after some feedback before relesing 1.9.0 to npm.

Hope this fixes everyone problems 🤞 ... and remember to keep using region when initializing the class.

from ewelink-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.