tobof / openhab-addons

The next-generation open Home Automation Bus (openHAB)
Eclipse Public License 2.0
39 stars 30 forks source link

SerialPortGateway reconnects to serial port to frequently #116

Open wmarkow opened 6 years ago

wmarkow commented 6 years ago

Expected Behavior

Serial port gateway should not reconnect to serial port so frequently. It is bad for performance and - every reconnect to serial port - resets the connected ArduinoUno Gateway Device as well.

Current Behavior

I'm using a MySensors Serial Port gateway which is running a mysensors/NodeManager. It looks like NodeManager sends to serial port some bogus characters which doesn't follow the MySensors Serial API:

NodeManager v1.7
LIB V=2.3.0-alpha R=- E=- T=G A=A S=- B=-
RADIO...0;255;3;0;14;Gateway startup complete.
0;255;0;0;17;2.3.0-alpha
OK
0;255;3;0;11;NodeManager
0;255;3;0;12;1.0
READY 

MY I=0 M=255 
INT P=3 M=255
INT P=2 M=255

MySensors OpenHAB Binding has a mechanism that reconnects to serial port if more than 5 bogus messages are received on serial port. In the short log above you can see 11 messages, from which only 3 seems to be correct. Morover ArduinoUno restarts on every attempt to connect to serial port - actually this is a correct behavior but a side effect of this is that NodeManager sends again those bogus messages to MySensors Binding and the whole cycle repeats. I'm attaching the openHAB-reset-serial-gateway.log fro reference.

Possible Solution

I would say that the mechanism of detecting bogus frames could be changed on the MySensors Binding side. The binding could just flush (and possibly log them with the debug level) the garbage messages. It may be not possible to avoid sending such a messages from the attached hardware gateway: i.e. some library (like a hardware sensor) may be written in the way that it constantly prints something bogus to serial port. MySensors Binding should be resistant to such a messages.

Does openHAB contain some internal mechanism to check if Gateway is up and running? If so, maybe we could use it?

Steps to Reproduce (for Bugs)

Run openHAB-2.4.0-SNAPSHOT, install mysensors binding (that binding which is compatible with openHAB-2.4.0 take a look at #114), attach the Arduino Uno with installed NodeManager. Configure MySensor Serial Gateway correctly in openHAB.

Your Environment

wmarkow commented 6 years ago

I think I have just accidentally closed this issue. I'm reopening it again.

wmarkow commented 6 years ago

I didn't know that those debug messages (I called them bogus before) from NodeManager can be switched off by setting FEATURE_DEBUG to OFF. When I did this, the MySensors Binding works stable and do not reconnect to serial port.

Now I'm not sure if this issue is a bug. Maybe it is more like improvement?