I am using a webCoRE piston to send a GET request to the USGS's API. It is returning the water temperature for a local river. For whatever reason the value webCoRE is logging is different than the actual value. It's treating it as a whole number and ignoring everything on the right side of the decimal. I can do the same GET request through a script I wrote and it spits out the correct value. Here's the piston:
Might try stepping back and listing out the entire series values string to see if you’re just off a position or 2.
Here's the GET request:
I'm using value.timeSeries.values.value.value
in both my PS script and in webCoRE. The script spits out the correct value. The webCoRE logs show it returning [[[5.4]]] (not sure what's up with the brackets) and then when converting from that value to Fahrenheit it decides to use 5.0 instead.
2/14/2022, 9:51:42 PM +406ms
+5ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 0ms, canQueue: true, calledMyself: false
+15ms ║RunTime initialize > 14 LockT > 1ms > r9T > 2ms > pistonT > 1ms (first state access 11 6 8)
+18ms ║Runtime (7048 bytes) initialized in 2ms (v0.3.114.20220203_HE)
+22ms ║╔Execution stage started
+34ms ║║[[[5.4]]]
+36ms ║║Executed virtual command log (2ms)
+44ms ║║Executed virtual command setVariable (2ms)
+50ms ║║Calculating (decimal)5.0 * (decimal)1.8 >> (decimal)9.0
+53ms ║║Calculating (decimal)9.0 + (decimal)32.0 >> (decimal)41.0
+58ms ║║Executed virtual command setVariable (2ms)
For whatever reason it decided to start working overnight. I didn't make any changes. It looks like it's now returning the value without the brackets so I guess maybe they were causing this issue? I'll keep your suggestion in mind if I have any other issues. Thanks!
Another thought, may be able to use $response.json also...
Ugh... I had my pistons mixed up. Long night. This one was still returning the brackets, but your string function seemed to correct that once I realized that index0f
was actually indexOf
.
Anyhow, I now have a working piston with the correct values AND I learned something new. Thanks!
One of the reasons I wait until after the second cup of coffee before I change something. Glad to be of assistance.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.