Hi,
On my MR3020 I have a template which outputs using FTP a series of variables every 5 minutes in a JSON format file with the date and time embedded in the file name. A background program picks these up and feeds them to a web site. This has been working fine for 2 weeks.
Then suddenly the background program that parses the JSON file created by the template every 5 minutes fails because it can't convert what should be a numeric value.
Inspecting the file in question reveals the issue. The template token has not been substituted. Just one item in the middle of others than have been converted fine. See following...
"thb0press":1020.0,
"thb0seapress":1021.1,
"rain0rate":0.0,
"rain0ratezero":"20200327140938",
"rain0sum5":[rain0total-sum5],
"rain0total":0.0,
"uv0index":0.0,
"sol0rad":77.0
The template generated files both 5 minutes before and after show the correct value of 0 (for rain0total-sum5).
Yes, there isn't a default value in token but there shouldn't need to be one because the sum will always be zero or greater.
As far as I can tell this has happened only once in 2 weeks. I manually edited the one problematic file, and then it and every other subsequent file was processed without error (implying no other file had this issue), and everything has run fine again for the last two days.
The template has run fine 14 days x 24 hours x 12 times/hour fine = 4032 times fine and then this.
Any ideas...
Strange Template Issue **solved**
Moderator: Mattk
Re: Strange Template Issue
Nope, when there is no rain data logged in the respective time frame, then the variable is not defined and will not be evaluated. Therefore, you have to define what to return. In your case a default of "0" will make sense.stevem wrote: Thu Apr 02, 2020 6:51 am Yes, there isn't a default value in token but there shouldn't need to be one because the sum will always be zero or greater.
Re: Strange Template Issue **solved**
Thanks for the reply.
I'll try that but my gut instinct doesn't feel right (I have a 30+ yr programming background).
If your theory is correct (a default is required) why has it returned zero many times both before and after? If tolerated age was exceeded then this failure should persist until it actually rains. The last rain was several days before this event and there has been none since yet there hasn't been a re-occurrence.
And if indeed a default is required perhaps your code should always reject the tag because its a real trap if it mostly works, but then some thousand of iterations later is likely to fail especially when at the top of your documentation it says the "replacement" is optional.
Thinking more about what is going on... Unfortunately I can't tell when the meteobridge was last rebooted prior to this event. But... is it possible that this behavior would be observed if the device had re-booted and before 5 minutes had elapsed this 5 minute sum was requested (the site has experienced multiple power failures but I have no record of when unfortunately)? So the fail condition is rather than there being no data, that there hadn't been sufficient elapsed time to create the running total.
Rgds Steve
I'll try that but my gut instinct doesn't feel right (I have a 30+ yr programming background).
If your theory is correct (a default is required) why has it returned zero many times both before and after? If tolerated age was exceeded then this failure should persist until it actually rains. The last rain was several days before this event and there has been none since yet there hasn't been a re-occurrence.
And if indeed a default is required perhaps your code should always reject the tag because its a real trap if it mostly works, but then some thousand of iterations later is likely to fail especially when at the top of your documentation it says the "replacement" is optional.
Thinking more about what is going on... Unfortunately I can't tell when the meteobridge was last rebooted prior to this event. But... is it possible that this behavior would be observed if the device had re-booted and before 5 minutes had elapsed this 5 minute sum was requested (the site has experienced multiple power failures but I have no record of when unfortunately)? So the fail condition is rather than there being no data, that there hadn't been sufficient elapsed time to create the running total.
Rgds Steve