Polling?

Not sure if this is a scripting question.

I want to be able to poll the UPS’s status.

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
}

Possible?

It looks like there is no solution.

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.

Interesting. This is a powerful, and potentially dangerous approach – (don’t ask me how I found out).

I used the following code (setting the condition tested to be “on-line” being true was just used for testing; depoloyed it would be false):

:local UPSonline ([/system/ups/monitor 0 once as-value]->"on-line")

:while ([/system/ups/monitor 0 once as-value]->"on-line") do={
    :log info $UPSonline
    :local voltage (([/system ups monitor 0 as-value]->"line-voltage")/100)
}

The only way I was able to get out of it was rebooting the router.

Does a continuously run “while” loop use a lot fo system resources?

I don’t see any documentation including “duration=” in the while loop.

Is there a more graceful way to get the while loop to stop?

Is this the recommended way to do this?

Thank you.

It’s quicker to set it in the scheduler every second rather than doing intricate things, especially for those who are not familiar with scripting…

Does setting a scheduler for every second create a large CPU overhead?

Need to run Assassin’s Creed on your router?

Does setting a infinite loop for every nanosecond create a more large CPU overhead?

No.

Does setting a infinite loop for every nanosecond create a more large CPU overhead?

No idea.

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.

Oh, how disappointing! I was hoping you were going to provide a tutorial for how to run Assasin's Creed on a hEX!

Seriously: Thank you.

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 :wink:.

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.

Thank you again for the explanation.

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?

Update:

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).