caseyjhol / node-red-contrib-tplink

A collection of Node-RED nodes for TP-Link Smart Home devices
https://www.npmjs.com/package/node-red-contrib-tplink-iot
MIT License
16 stars 15 forks source link

Node buffers messages when device is not connected #45

Open Jaddache opened 3 years ago

Jaddache commented 3 years ago

Firstly, thank you for developing this node.

I am using the kasa node to control a KL130B smart bulb. The KL130B bulb is being used as an indicator of the status of an off grid electrical power system. System status and available power being represented by the colour and brightness of the bulb.

Control messages for the bulb are created approximately every 10 seconds and passed to the node. When the bulb is disconnected from power for a period of time and then reconnected, it appears as though the control messages for the intervening period are buffered by the node and then all passed to the bulb when reconnected. The effect is that the bulb does a fast run though of the light output pattern until the buffer is cleared and then it responds as intended. During the period, the node returns a stream of messages which can go on for a long period if the bulb has been disconnected for some time.

I appreciate that this might be desirable behavior in some circumstances however in my situation I would like the node to either:

  1. not buffer any control messages that cannot be actioned (it might be appropriate to still buffer command messages if this is also happening) ; or
  2. only buffer the most recent control message so that the bulb is correctly initiated when it is next powered up.

The kasa node is being used within node red V1.1.3, running on a raspberry pi 3B+ with Linux 4.19.75-v7+.

Is it possible to include a flag that drops control messages that are unable to be actioned before a subsequent control message is received.

hufftheweevil commented 3 years ago

The node only buffers input messages before the device is first setup in the node. After first connection, all buffered messages are processed. However, if the device subsequently disconnects, then any input messages are still processed immediately. That is, they are sent to the underlying API -- which, if I'm not mistaken, will buffer the messages. However, a timeout should occur at some point, and so the message should be dropped.

By chance, do you have the Connection poll interval or Event poll interval set to 0?

Jaddache commented 2 years ago

My apologies for not checking back here to see that you had responded. Yes I do have the connection poll AND event poll intervals set to zero.