Renew bridge connection with rule after midnight

Platform information:
Hardware: Rasberry Pi 3B
openHAB version: OH 2.5

I have a configured “modbus:tcp:remoteTCP” bridge and Thing that deliver data from a modbus device. While the whole day it’s working pretty fine and openhab is getting the values. Unfortunately the Modbus device is doing at midnight something like a “reboot/refresh” so that openhab is freezing the communication. The value will no longer received. To get the communication back again, I have to save my .things file another time, then it’s working until next midnight.

My question: Is there a method to Renew/restart Bridge connection with a “time” based rule? With this i could start connection from new after midnight.

This is the definition of my Bridge:

  Bridge modbus:tcp:remoteTCP [ host="192.168.178.100", port=502, id=1 ]  {
    Bridge poller input [ start=5030, length=2, refresh=10000, type="input" ]  {
 	         Thing data input5030 [ readStart="5030", readValueType="uint32_swap" ]
    }
 }

Thank you.

Is it enough to use the linux

touch /path/to/your/thing-file

command ? If that is the case you could use a linux cron job or an openhab cron entry to touch the file.
To restart a binding others in the forum use linux cron job to restart a binding via karaf console.

If you’re using Rules DSL, set up an API token and then use a rule like this to disable and re-enable the thing. I’ve shown the cron as 1:30am every day.

when
    Time cron "0 30 1 ? * * *"
then
    //Header for REST authentication
    //https://community.openhab.org/t/javascript-syntax-to-insert-api-token-into-sendhttpgetrequest/116798
    val headers = newHashMap("Authorization" -> "Bearer INSERT-API-TOKEN-HERE", "WWW-Authenticate"-> "Basic")

    //disable the thing
    sendHttpPutRequest("http://INSERT-IP-ADDRESS:8080/rest/things/INSERT-THING-ID/enable", "application/json", 'false', headers, 1000)

    //enable the thing
    sendHttpPutRequest("http://INSERT-IP-ADDRESS:8080/rest/things/INSERT-THING-ID/enable", "application/json", 'true', headers, 1000)
end

You might need to add a brief pause between the two commands.

If the Modbus thing shows up as offline and just doesn’t reconnect, you could instead trigger on its status.

UPDATE: This work up until OH 3.1, but in OH3.2 you need to change application/json to text/plain.

2 Likes

The bridge is still shown as online ( see picture) , but value is no longer receiving.

Thank you for your comments. I’ll try your ideas.

How can i get the “Bearer MyToken” ?

What actual errors do you get in your openhab.log?
Disable/enable Thing doesn’t do much different to a routine poll, given your default TCP connect strategy.
Some ideas here