mapero / node-red-contrib-smartplug

MIT License
3 stars 4 forks source link

Failure of one plug causes loss of polling/control of all plugs #16

Open elguiri opened 7 years ago

elguiri commented 7 years ago

I have two Edimax plugs and have configured a node (A and B) for each one on a flow. Both nodes are polling normally and updating.

If plug B is powered down, then the node B displays "disconnected", but node A is also affected - it's state is no longer updated properly and it is not possible to control it either.

It looks like the disconnected state may be shared between instances of the node, which affects the healthy node.

mapero commented 7 years ago

I will have a look into it.

elguiri commented 7 years ago

Thanks very much. Please let me know if you require further information on my setup or help with testing (I've just ordered a third plug)!

mapero commented 7 years ago

Hi,

since I only have one smartplug (and no plans to buy more), I can not test it at the moment. I tried to simulate it, and it worked: image

Can you update to todays release and check the firmware of your plugs?

If this does not resolve your problem, please start node red with node-red -v and check if there are some more errors in your console log.

Thx, regards, Jochen

elguiri commented 7 years ago

Hi Jochen

I updated to 1.0.1 (using npm update node-red-contrib-smartplug), however the behaviour is the same.

The log was not helpful, just indicated the following as expected:

24 Jul 20:56:04 - [info] [smartplug-device:ediPlugB] Status changed: connected-->disconnected 24 Jul 20:56:48 - [error] [smartplug-device:ediPlugB] Error: connect EHOSTUNREACH 192.168.0.109:10000

My two devices are called ediPlugA and ediPlugB. When ediPlugB is powered down, the output from the ediPlugA node is no longer valid - meaning that it is no longer possible to extract a value from msg.payload.status.state. The ediPlugA sends a message erratically. When healthy, the ediPlugA message is

object topic: "home/ediPlugA/plug/state" payload: object status: object state: false scheduleState: false nowPower: 0 nowCurrent: 0 day: 0 week: 0 month: 0 lastToggleTime: "2017-07-24T19:55:41.000Z"

However, when it becomes unhealthy due to ediPlugB powering down, the message changes (also updating every 3 seconds rather than the 5 seconds I had set):

object topic: "home/ediPlugA/plug/state" payload: object undefined: object state: false scheduleState: false nowPower: 0 nowCurrent: 0 day: 0 week: 0 month: 0 lastToggleTime: "2017-07-24T20:10:51.000Z"

Note the difference is that "status" becomes "undefined". It seems strange for the object name to change like that.

I hope that helps.

mapero commented 7 years ago

I think I found the bug. I'll try to provide an update tomorrow. I'll keep you updated.

elguiri commented 7 years ago

Thanks, much appreciated.

JonMurphy commented 7 years ago

I wonder if this is related to #9

mapero commented 7 years ago

I think it is related. But I can not reproduce the error. I only have one plug and do not plan to buy another one. I will try to optimize some stuff and hope it will fix it.

elguiri commented 7 years ago

Hi Jochen

I'm happy to do some debugging of code if you can give me some pointers about what dev environment is best to use... I've never done any node programming - good old fashioned embedded C/C++ and .net desktop experience recently. I am running Node-RED in a Debian VM on my NAS drive (no GUI).

I've now got a third plug so can test the n+1 case!

Thanks

mapero commented 7 years ago

I use node-inspector to debug in node.js. You can debug over ssh tunnel.

But I do not have an idea where to start :(

elguiri commented 7 years ago

@mapero I have the debug connection (no need to use ssh tunnel as my VM is on my local LAN)...

debug

The image shows a breakpoint being hit when I power down one of the plugs so I think that is a good start.

Is it possible the issue is arising in edimax-smartplug rather than node-red-contrib-smartplug? I can now start debugging so your thoughts would be appreciated.

If I want to make edits in the code, do I edit the smartplug.js file in place at _.node-red/nodemodules/node-red-contrib-smartplug and do I need to restart node-red to make the edit effective?

Thanks

elguiri commented 7 years ago

@mapero Just noticed v2.0.0 so will have a play with that, thanks!

mapero commented 7 years ago

Is it possible the issue is arising in edimax-smartplug rather than node-red-contrib-smartplug? I can now start debugging so your thoughts would be appreciated.

Could be an issue with edimax-smartplug, but I doubt it. It does not have instances, only stateless functions.

If I want to make edits in the code, do I edit the smartplug.js file in place at .node-red/node_modules/node-red-contrib-smartplug and do I need to restart node-red to make the edit effective?

Yeah, thats the right file to edit and you have to restart node-red after a change.

elguiri commented 7 years ago

@mapero A quick debug on the old code pointed to the indexes collection disappearing (hence the undefined status), and it looks like you have corrected that in the 2.0.0 release. I am upgrading to that using:

npm install node-red-contrib-smartplug@latest

since currently the wanted version is different from the latest so npm update doesn't update to 2.0.0

mapero commented 7 years ago

In this release I move the cost from inside the status to an own field. That can break some flows and is a change of an outside api. That is why I increased the major version. npm update ensures that you do not accidental break something. You have to use install to update therefore.

Did you test 2.2.0. Would be great if you have some feedback.

Thanks for your support.

Regards Jochen

elguiri commented 7 years ago

Hi @mapero

This is my test flow: capture

This shows the situation with plug A powered off and plug B still powered on.

Unfortunately, in this state, the true and false commands to plug B go unrecognized for a significant period of time (seems like they get queued up for a minute or so), so there is still an issue somewhere with a connection between the state of the plugs.

Thanks