Implementing controller for Serial Gateway
I started to develop a simple controller in Java, implementing node ID assignment and the most basic stuff to let mysensors work. The sensor data is then mirrored to MQTT, similar to the way Openhab 1.6 tutorial shows.
With MySensors 1.6 and 2.0, I had about the same problem: flow control between controller and gateway.
Now I have a system having 3 threads:
- listening for ACK packets, resending messages after a timeout
I have 16 relays controlling my lights in my home. If I send a command to each of them too fast, some messages gets lost. (I'm connecting over USB-serial, reproduced on Windows 10 and Raspberry Pi).
It actually turned out, if I wait about 350 milliseconds after sending a command, the system gets pretty stable. But... slow as well.
Can you please advice on how to properly implement flow control on a serial gateway? I know this should have a simple solution and I must be doing something wrong : )
About buffering from Java side, I'm flushing my output stream be deterministic when waiting for that 350 ms.