Is this possible? Store data from Asus Router ajax .asp page for Temperature data.
-
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.
-
toggledbitsreplied to cw-kid on Jul 27, 2023, 12:40 AM last edited by toggledbits Jul 26, 2023, 8:42 PM
@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. -
@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.
-
toggledbitswrote on Jul 28, 2023, 3:23 PM last edited by toggledbits Jul 28, 2023, 11:29 AM
Not showing enough work here. What sets
RouterMemoryRaw
? Need detailsEdit: also, did you hard refresh after restarting MSR?
-
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
What sets RouterMemoryRaw? Need details
A rule that I just set to run every hour.
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
also, did you hard refresh after restarting MSR?
Yes I did.
Its been several days and these global expression still say (has not been evaluated)
Thanks
-
Works fine for me. Restart MSR if you have not, and hard refresh. They will be evaluated at restart. If they still show not evaluated, you need to dig deeper.
-
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
Restart MSR if you have not, and hard refresh. They will be evaluated at restart
Just tried that and still not evaluated. I did look in the log but couldn't see anything obvious that stuck out.
-
I just deleted all 3 Global Expressions and recreated them, then restarted MSR and they still don't evaluate.
-
Rebooting the host Linux box doesn't help either. I am baffled as to why they do not evaluate.
-
What about where the values are used? Ignore the global expression displayed state/value for a moment, and look at any rules/conditions that use these globals. What do they show?
-
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
What about where the values are used?
I didn't get that far yet in setting up the rule, as it seemed to not be working etc.
I was going to create other actions to send the values to a mutl-string device in Vera.
This is all that is in the rule currently
-
OK, but the target variable shown there is different from the one used in the expressions...
RouterMemoryResponse
vsRouterMemoryRaw
-
cw-kidreplied to toggledbits on Jul 30, 2023, 5:47 PM last edited by cw-kid Jul 30, 2023, 1:48 PM
That's because I just renamed the global expression to see if that made any difference.
-
-
Sorry, but let's stick with one issue at a time, please.
I want to see if that Expressions page view is actually broken and not showing complete/valid data. Make a dummy rule that contains a variable expression condition using the free memory value, and show what that displays for "current value" in both the rule editor and in the rule status view.
-
38/77