Logic Machine Forum
Reactor update by script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Reactor update by script (/showthread.php?tid=2220)



Reactor update by script - Guilhem - 04.09.2019

Hello,

I'm trying to automatically link group objects to the reactor using a script that makes the modifications directly inside the database. For example, to link the object 1/1/x to the UIOy of the reactor as a digital output, I'm just doing this:

Code:
name = 'Digital Output 1'
x = 1
y = 1

db:query('UPDATE reactorra SET name = ?, address = ?, bus_write = 1, param_1 = "out_bin", param_3 = 0, param_4 = 0 WHERE id = ?', name, knxlib.encodega("1/1/" .. x), "io-" .. y)

This is seemingly working, but actually the link is not really made (changing the boolean value of the object doesn't the state of the output in the reactor) until I manually edit one of the reactor entries. As soon I validate a single manual edit, all the entries start to work correctly.

I know that just updating the database doesn't work out of the box for some manipulations that are supposed to be done via the web interface, but there is always a workaround to make it work. I found 2 examples on the forum:
- Updating the schedulers (https://forum.logicmachine.net/showthread.php?tid=265): here the changes are made via a db update and are then validated by calling a special function;
- Updating the Modbus parameters (https://forum.logicmachine.net/showthread.php?tid=2200): here all the changes are made using a specific function that seems to simulate a web request. 

As I don't understand exactly the internal mechanisms that are used in both cases, I can't figure out how to make it work for a reactor update but I guess that the solution is similar (and can be reproduced for any kind of update).

(And of course I'll be very happy if someone can explain quickly how it works so that next time I can succeed without asking :-) )

Thanks for your help!


RE: Reactor update by script - admin - 04.09.2019

You need to send a reload signal after db update.
Code:
pid = os.checkproc('reactorra')
if pid then
  os.kill(pid, signal.SIGUSR1)
end



RE: Reactor update by script - Guilhem - 04.09.2019

(04.09.2019, 12:31)admin Wrote: You need to send a reload signal after db update.
Code:
pid = os.checkproc('reactorra')
if pid then
  os.kill(pid, signal.SIGUSR1)
end

Hello admin,

Thanks a lot, it works perfectly!

The solution you propose here is quite different from the ones that were proposed for the schedulers and Modbus parameters update: there is no "unified" way to simulate web requests from a script?

Thanks again :-)