howanghk / homebridge-ewelink

Homebridge plugin to control Sonoff relays with OEM firmware
MIT License
81 stars 46 forks source link

Fixed "params incomplete" error #49

Closed maxmacstn closed 4 years ago

maxmacstn commented 4 years ago

Fixed params incomplete error while perform GET request to /api/user/device by adding appropriate parameters as like eWeLink app did.

maxmacstn commented 4 years ago

48

LeJeko commented 4 years ago

I did not have this issue but thank you for your work. Just a question: Why do you add a requirement for querystring.stringify () ? JSON.Stringify () does not do the job?

Otherwise, it should be added in package.json dependencies.

LeJeko commented 4 years ago

Hello @howanghk,

First of all, congratulations for your work. Perfect integration with a very clear code.

There is a lot of homebridge-ewelink fork and we start getting lost. Are you ok to maintain and evolve this fork?

Because I will also have a PR to propose for a new feature: Group channels of multi-switch devices to simulate another accessory. (A roller blind in my case).

I just wanted to wait for this PR to be validated in order to integrate the very useful fix of @maxmacstn.

Thank you

maxmacstn commented 4 years ago

The reason that I'm using querystring is because I want to create http GET request with the querystring as what I captured eWeLink app

Ex. https://as-api.coolkit.cc:8080/api/user/device?lang=en&apiKey=2817695a-3b73-4cd4-940a-1961726213a8&getTags=1&version=6&ts=1570205726&nonce=25bmf835&appid=oeVkj2lYFGnJu5XUtWisfW4&imei=167E1085-DA42-451A-9992-A558757CAC71&os=iOS&model=iPhone%207_iPhone9%2C3&romVersion=12.4&appVersion=3.11.

The app did not send the POST request with JSON body but it send GET with the query parameters at the end of the url, so I use this package for convenience of creating the request.

This plugin still not perfect, I found out that It seems to be slow when you have multiple devices and it needs to create request for checking the status of each device, instead of using the cache from previous request. And when there is no internet connection, all of the homebridge accessories will not response because of this plugin.

Also I'm very new to JS so if I do something wrong, feel free to create comments.

LeJeko commented 4 years ago

Thank you for the explanations, it makes sense! And I tried your fork, querystring is part of node.js, so no reason to declare a dependency. Sorry for my misunderstanding.

I looked at your code more deeply and I notice that the answer is different with or without arguments. That's why you declare body = body.devicelist. I also suggest a little cleanup of the code in the next comment.

Currently, I have only one Sonoff Dual (I will soon receive a mini) and I have no slowdown, but your comment is relevant. I quickly looked for solutions and I think the following could be implemented: https://dev.to/vigzmv/a-simple-caching-strategy-for-node-rest-apis-part-1-72a

rajattrehan21 commented 4 years ago

Basically i am a noob. But i still got it working in no time. The code works and i think it should be updated in the main application. The most amount of time i spent, was for locating the index.js file. Made a backup of the old file. copied the new code to the file. and it started working.

The index.js file is located at /usr/local/lib/node_modules/homebridge-ewelink-max

*May be in a different location for some people.

howanghk commented 4 years ago

Thanks for the great work, @maxmacstn ! I am going to merge this and release a new version now.