Hi,
There can be issues if you try to configure it by this logic via WebUI, since you will have 2 timers that are not aware of each other.
You can write a shell script, but this task is up to you. We do not have examples, but you can check this forum for similar threads and refer to other resources available online too.
To read from modbus slave, you can use the following command (you can change it to your needs):
- ubus call modbus_master tcp.test
For information:
- ubus -v list modbus_master
You will need to parse the response. For example:
- ubus call modbus_master tcp.test '{"id":1,"timeout":15,"function":3,"first_reg":1025,"reg_count":"1","data_type":"16bit_int_hi_first","no_brackets":1,"ip":"127.0.0.1","port":502,"delay":0}' | sed -n 's/.*"result": "\(.*\)".*/\1/p'
Function 3 for read, function 6 for write.
Regarding the available data types, you can configure a modbus request in modbus master in the WebUI and check the data type in the modbus_master config file:
- cat /etc/config/modbus_master
The config will show you your configured requests and their data types. So you can use those in your modbus tcp.test command.
So, check the values, and based on that turn on/off relay. You will need to add a timer too. For example (relay_time is your 4hour time in seconds):
- timer_started=$(date +%s)
- timer_end_time=$((timer_started + RELAY_TIME))
- if [ "$(date +%s)" -ge "$timer_end_time" ]; then
You can change the state of the relay or any other IO via ubus, or by setting register 203 (for relay) via Modbus using the commands I have mentioned before.
Ubus commands for relay:
- ubus call ioman.relay.relay0 update '{"state":"open"}'
- ubus call ioman.relay.relay0 update '{"state":"close"}'
- ubus call ioman.relay.relay0 status
- ubus -v list ioman
Kind Regards,
Andzej