Open realsquash opened 6 years ago
Have you checked the I2C hardware eg "i2cdetect -y 1" to check the circuit & address What settings have you used eg pullup, debounce, on msg
There isn't a hardware issue, the input will will indicate correctly on a state change. I had assumed that it would send a message every time it polled, but now I'm thinking it wasn't designed that way. It must just be polling the chip for a change in state, and then it will send out 1 message if the state has changed. I thought it would send a message every n milliseconds indicating what the state of the input is at that time.
Maybe it's better to give an example. I have an application where I've started a diesel generator remotely and it has a 12v run indicator that I'm using on an mcp23017 input. When it is started it sets a global variable and sends an MQTT message, which is then distributed to phones, control panel, etc over a wireless mobile phone network. It works perfectly fine, but after hours/days of running (300 gallon fuel tank) I am left wondering if that one little message somehow didn't make it out of the node, mqtt, etc. Did the gen die two hours ago and take out the control with it? There are other redundant ways to indicate that the gen is happy such as measuring the output voltage, but I have to work with what I've got...
As you determined, it only sends a message on a change Feel free to edit your copy of the node - remove line 104 of mcp23017chip.js if (theBit.lastState != state){ and line 116
You could set a global variable and set up a timer to periodically send the state of the variable
Where I need to know if something is running I set up a independent heartbeat So the remote instance sends a message every 20s The local instance keeps resetting a timer on receipt and alarms if timer gets to 60s
One of my applications has a remote water pump feeding a GSHP using MQTT between the 2 instances The water pump is disabled if the GSHP valve is not open The GSHP won't run unless the water pump is on If the heatbeat fails in either directions it defaults to a safe mode
Just thinking about this a little bit more - it would be nice to be able to trigger a read from the chip for an input. I can see cases were it wouldn't be useful to have a constant stream of messages, but a check on the status once in a while would be nice. I realize the node is always polling for a change, but if the change message it sends is missed you have no way to ever recover from it.
I know it's almost 3 years but as I commented on the recent thread on NR forum, this node fails on initial read. Sending msg only when state is changed is ok once all is up an running. However, when restarting NR we don't get any info about current state.
It could be accepting input msg (we could then add Inject node with checkbox Inject once after [0.1] seconds, then
) or have internal checkbox to send the initial msg once it's started. I would vote for input as it has more flexibility and can be triggered by various sources. Such incoming msg should force to read the state and send msg.
On an input I am not getting any polling whatsoever. When the input state changes in the hardware it does change the input node and send a mesage. If you restart node-red and the output was active it will show inactive and never poll it to change the status.