Or, more generally, I want the router to do something if the line (input) voltage to the UPS drops below a threshold and/or the UPS has changed to battery power.
I have this code which seems to work, but I am hoping there is a way to do this without running the script every second.
:if (([/system/ups/monitor 0 once as-value]->"on-line") = "false") do={
:local voltage (([/system ups monitor 0 once as-value]->"line-voltage")/100)
:log info $voltage
}
Remove the “once” and it becomes a “:while (true)” loop, so it will run forever. There is an interval= that control how often the do={} code is run, i.e. 1s or 1m or 1h etc…
You can also make only run for a fixed period like duration=1m. This is useful like in a /system/scheduler script if say the schedule was “every 1m”, it just run the “monitor” loop, and end at same time as schedule. But you can just say once at =startup, and should keep running forever if you do not provide an duration= value.
Jokes aside, I don’t have any UPS directly connected to a RouterBOARD otherwise I would have helped you better,
but if you are not familiar with scripting the 1 second scheduler is more than enough and practically does not consume CPU.
I should have been clearer, in all likelihood using the "monitor once" in a scheduler is a better plan.
I was more explaining how it works when NOT using "once"... generally speaking .
Not wrong. I don't use UPS either.
I do know some stuff like LTE – which also uses "monitor" – may not actually get all value every time. For example, on some modems it's ~50% where the CQI or RSRQ will be included in "monitor once". The "loop" version of monitor for more like voltage over 10 seconds, i.e. "duration=10s interval=1s". But if you're just looking for just "on-line", then the no need to make it complex & and assuming UPS always report "on-line"... using once should be fine and then just scheduling it how ever often you want to check.
Let /system/scheduler manage the interval it checks with "once" is best plan.
I searched the entire ROS manual for “monitor once” as well as for “duration=” and could not find an explanation for the “once” or “duration=” parameters.
I am looking for both “on-line” as well as “line-voltage” – does that change the recommendation to use the scheduler and not use a duration parameter?
At the location that prompted me to start this “voltage” investigation, I have frequent (but irregular – i.e., at random times) losses of internet connectivity. Sometimes it turns out the cable modem needs to be rebooted, and other times, service is restored without intervention in seconds or minutes.
When I used this ‘run-script-every-second’ solution I discovered that the line-voltage was dropping to as low as 106 from time to time.
The equipment are all connected to a UPS, but not a fancy one (i.e., not an on-line sine wave device).
I double checked the line voltage by monitoring a power usage I have set up for the entire location (Emporia Vue) and confirmed the low voltage.
I called the electric utility company, they came out yesterday, and now the voltage to the entire house is steady at 122 (with an occasional dip to 119).
I don’t know yet if this will solve the problem, but it definetly helped solve another problem (that I did not know I had).