System health voltage string conversion ROS7.13

Hello Guru’s,

I’ve been wanting to simply log the system voltage on my RB953 but am having some difficulty.
I can get a “value” easily enough of 10.5 in a global variable called voltage. The difficulty comes due to the voltage reading being inaccurate, about 2 volts low and trying to adjust that.

:set $voltage [/system health get number=0 value ]

This command pumps out a string value not a number (integer). If I try to simply +2 the result, the ROS treats it as an IP address and mangles it. So somehow I need to convert it from a string to a number. In the documentation it makes some brief references to conversions using :tonum commands.

:global voltage1 [:tonum $voltage ]

So I followed what I think should have worked but it doesn’t, the voltage1 variable is blank.

I’ve seen in my google searching people getting the system health voltage returned as a 3 digit integer but I’m unable to replicate that, I suspect it was old ROS versions that did it.

I’m more than happy for any advice on either how to convert the string to a number or getting the system health voltage returned as a 3 digit number to begin with and I should be able to handle the rest from there.

For reference the script thus far is as follows. The system is running ROS 7.13

/system script
add dont-require-permissions=no name=Health owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global voltage\r\
    \n:global voltage1\r\
    \n:set \$voltage value=0\r\
    \n:set \$voltage1 value=0\r\
    \n:set \$voltage [/system health get number=0 value ]\r\
    \n:global voltage1 [:tonum \$voltage ]"

RouterOS only handles integers. This means that in some places like health, ROS will return a string with the decimal number, and in other places, like the POE section, ROS returns the output voltage as a number in deci-volt, i.e. times ten, to convert the number to an integer.

The later has been causing me issues, as I need the number as a string but in volts, and I do not care about the value type, hence I needed to convert it to a string and reinsert the decimal separator.

In your case, I suspect it will work if you remove the decimal separator, convert it to a number, add 2*10 instead of 2, convert it to a string and reinsert the decimal separator.

Good luck :slight_smile:

We already start with bullshit at the beginning (number=0), everything else is certainly wrong.

[admin@Pandoras Box] > /system health print                 
Columns: NAME, VALUE, TYPE
#  NAME         VALUE  TYPE
0  voltage      10.4   V   
1  temperature  42     C   
[admin@Pandoras Box] > /system health get value-name=voltage
input does not match any value of value-name
[admin@Pandoras Box] > /system health get value-name= voltage
input does not match any value of value-name
[admin@Pandoras Box] > /system health get value-name="voltage"
input does not match any value of value-name

Rex, I’m curious to see how you get it to work.

Cheers xrlls, I’ll give it a go.

[system health get value-name=value [find type=V]]
Try this.

There is no need to reinvent the weel:
just use the “search” function in the forum…
http://forum.mikrotik.com/t/cant-get-cpu-temperature-in-script/169075/6