Is this possible? Store data from Asus Router ajax .asp page for Temperature data.
-
@cw-kid the
\n
at the end is a newline character. Linux is quite literal. You can push that string through the expressionint()
function and it will convert it to a number and ignore the newline. -
@cw-kid the
\n
at the end is a newline character. Linux is quite literal. You can push that string through the expressionint()
function and it will convert it to a number and ignore the newline.@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
You can push that string through the expression int() function
No idea what that means, but I will search. I also need to do some thing with that data like round it, as it says"66986" which should read as 66.99 degrees
-
int(RouterCPUTemp) / 1000
-
You can wrap that in a
round()
if you only want one decimal (for example)...round( int( RouterCPUTemp ) / 1000, 1 )
-
You can wrap that in a
round()
if you only want one decimal (for example)...round( int( RouterCPUTemp ) / 1000, 1 )
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
round( int( RouterCPUTemp ) / 1000, 1 )
Even better, you have made my day! Thank you.
I have been worrying about my router getting too hot, now I will know if it does.
-
You can wrap that in a
round()
if you only want one decimal (for example)...round( int( RouterCPUTemp ) / 1000, 1 )
-
Think I just found a bug? try naming a local expression as "2.4GTempRaw" without the quotes in a rule and see what happens. I am stuck and cannot delete the expression or exist the rule. Had to refresh the browser to recover. Should of known not to put a dot in the name LOL.
I might have just corrupted the rule now I cannot add an expression named "24GTempRaw"
Or maybe its the numbers it doesn't like.
OK that's better.
-
This is much more powerful than I imagined. Seems you can send any old linux command like "free" to see the memory usage. I haven't figured out how to extract and parse just a part of the returned data yet though, say just the "Used" memory value.
(string) " total used free shared buffers cached\nMem: 426020 303308 122712 3404 0 39212\n-/+ buffers/cache: 264096 161924\nSwap: 0 0 0\n"
"303308" is the used memory value, no idea how to extract just that part of the data to another local expression though as its not formatted like JSON data would be.
-
This is much more powerful than I imagined. Seems you can send any old linux command like "free" to see the memory usage. I haven't figured out how to extract and parse just a part of the returned data yet though, say just the "Used" memory value.
(string) " total used free shared buffers cached\nMem: 426020 303308 122712 3404 0 39212\n-/+ buffers/cache: 264096 161924\nSwap: 0 0 0\n"
"303308" is the used memory value, no idea how to extract just that part of the data to another local expression though as its not formatted like JSON data would be.
@cw-kid you're going to have to learn "regular expressions", which are patterns that can be matched in strings. It's another rabbit hole to go down, but here's a specific solution you might build on. Using your response string:
The
match()
function (refer to the docs) will match a pattern to a string. In this case, the pattern contains "regular expression groups", which are the parentheses and their contents. These groups contain\d+
patterns (you have to specify them as\\d+
as shown because of string escaping in the language)... the\d
pattern matches a single digit 0-9, and the modifier+
after it tells it to match one or more occurrences — so each\\d+
matches a number made of one or more consecutive digits. So this whole pattern basically finds the wordMem:
in the string, then from there finds the six numbers that follow. The3
in the last argument tellsmatch()
to return only the third matched item, which is the number 122712, the amount of free space (it's third in place in the string of numbers based on the header line above it).You can Google around to find regular expression tutorials.
-
Thanks I will take a look at the pattern matching.
I realised I need a Global Expression, for my second rule to trigger from. As I cannot use a local expression that is in one rule as a trigger in a different rule etc.
My second rule will be the one that triggers if the CPU Temp value is greater than 80 and it will notify me by repeated TTS announcements etc.So I created two new Global Expressions.
The first rule I setup that gets the CPU Temp via the ssh command, now also sends that raw response value to the Global variable as well, that is named "RouterCPUTempRaw" that works fine OK.
However my second Global variable called "RouterCPUTemp" that changes it to "int" doesn't seem to evaluate.
When should it evaluate ?
If I restart MSR then it evaluates then and updates correctly.
Maybe? its because to test it and force the value to be 81 I sent in this URL to MSR.
http://192.168.1.40:8111/api/v1/variable/RouterCPUTempRaw/set?value=81495
Thanks
EDIT: I guess as a work around I could delete the "RouterCPUTemp" global variable and just have my second rule trigger if the value in "RouterCPUTempRaw" global variable is greater than 80000
EDIT2: I just did that and that seems to work OK instead.
-
Local expressions are only evaluated when the parent rule is evaluated. The changing of the
rawResponse
local variable does not cause an evaluation of the other variables. These would need to be global. -
Local expressions are only evaluated when the parent rule is evaluated. The changing of the
rawResponse
local variable does not cause an evaluation of the other variables. These would need to be global.@toggledbits OK thanks I will change them to global variables and a see.
My comment before the last one, both of those expressions were global, yet one of them didn't seem to be evaluating and I wasn't sure why..
-
OK I changed all three expressions to be global ones instead.
I waited a while, but a similar thing as yet they have not been evaluated.
I then press Play on them but still nothing.
I then ran the action in the rule that pulls down the Free Memory data, but they still say (has not been evaluated)
Edit: I am on build, latest-23196-40ef07f4, just checked I am up to date it seems.
Restarting MSR also doesn't help. I don't understand why these global variables don't seem to be evaluating.