Python plugin: set a timer to get a callback after N ms
Posted: Wednesday 24 March 2021 22:15
Hi,
I'm developing Creasol DomBus plugin, in python, and I have a question expecially for @Dnpwwo and who is involved with Domoticz python framework.
Let me explain...
Dombus plugin manages some modules (inputs, outputs, sensors) connected by RS485 serial bus.
Now the plugin send ACK as soon as it receives a command from the bus, and this is ok.
Suppose to have a pushbutton connected to a input device, that must toggle 2 lights connected to 2 relay outputs
1.PUSHBUTTON is pushed => INPUT module send command to Dombus plugin
2.Dombus plugin informs Domoticz that the input device has changed, and immediately transmits back an ACK to the INPUT module
3.Domoticz or a script manages that input, and after a certain time (usually 50-80ms with a Raspberry) sends a onCommand callback to Dombus plugin to activate OUTPUT1 => Dombus transmits a frame to activate OUTPUT1 module by RS485
4.and immediately after, another onCommand callback to notify that OUTPU2 has been activated => Dombus transmits anoter frame to activate OUTPUT2
more schematically we have:
RX command from pushbutton input
TX ACK to pushbutton input module
Domoticz informs DomBus that OUTPUT1 has changed =>TX CMD to OUTPUT1
Domoticz informs DomBus that also OUTPUT2 has changed => TX CMD to both OUTPUT1 and OUTPUT2
The result now is that Dombus plugin transmits a frame within ACK to the input module, and 2 frames to the output module.
This is not a real problem, I'm using 115200bps and frames are only 1-2 ms long, but as it's possible to transmits more commands/ack in the same frame, limiting the overhead, it will be better if I can send a single frame with both ACK and CMDs together.
To get a single transmission frame with both ACK and CMD, it will be perfect to delay transmission, for example, 100ms: is there a way to program a timer to get a callback (HeartBeat, for example) after a specified number of ms ?? If so, I can put the ACK/CMD into a TX queue, program a delay, and if in the meanwhile other commands are received from Domoticz, they will be added to the TX queue, and after that delay they will be transmitted together in a single frame.
I've tried to explain the reason of my request. If it's not clear, I can explain in a different way.
Thanks a lot.
Paolo
I'm developing Creasol DomBus plugin, in python, and I have a question expecially for @Dnpwwo and who is involved with Domoticz python framework.
Let me explain...
Dombus plugin manages some modules (inputs, outputs, sensors) connected by RS485 serial bus.
Now the plugin send ACK as soon as it receives a command from the bus, and this is ok.
Suppose to have a pushbutton connected to a input device, that must toggle 2 lights connected to 2 relay outputs
1.PUSHBUTTON is pushed => INPUT module send command to Dombus plugin
2.Dombus plugin informs Domoticz that the input device has changed, and immediately transmits back an ACK to the INPUT module
3.Domoticz or a script manages that input, and after a certain time (usually 50-80ms with a Raspberry) sends a onCommand callback to Dombus plugin to activate OUTPUT1 => Dombus transmits a frame to activate OUTPUT1 module by RS485
4.and immediately after, another onCommand callback to notify that OUTPU2 has been activated => Dombus transmits anoter frame to activate OUTPUT2
more schematically we have:
RX command from pushbutton input
TX ACK to pushbutton input module
Domoticz informs DomBus that OUTPUT1 has changed =>TX CMD to OUTPUT1
Domoticz informs DomBus that also OUTPUT2 has changed => TX CMD to both OUTPUT1 and OUTPUT2
The result now is that Dombus plugin transmits a frame within ACK to the input module, and 2 frames to the output module.
This is not a real problem, I'm using 115200bps and frames are only 1-2 ms long, but as it's possible to transmits more commands/ack in the same frame, limiting the overhead, it will be better if I can send a single frame with both ACK and CMDs together.
To get a single transmission frame with both ACK and CMD, it will be perfect to delay transmission, for example, 100ms: is there a way to program a timer to get a callback (HeartBeat, for example) after a specified number of ms ?? If so, I can put the ACK/CMD into a TX queue, program a delay, and if in the meanwhile other commands are received from Domoticz, they will be added to the TX queue, and after that delay they will be transmitted together in a single frame.
I've tried to explain the reason of my request. If it's not clear, I can explain in a different way.
Thanks a lot.
Paolo