Advertisement
Guest User

Untitled

a guest
Oct 7th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. function onReceive(responseCode as Lang.Number, data as Lang.Dictionary or Lang.String or Null) as Void {
  2. System.println("onReceive: response code: " + responseCode + ", data: " + data);
  3. if (responseCode == 200) {
  4. if (data["payload"] != null && data["payload"] instanceof Lang.Array) {
  5. for (var i = 0; i < data["payload"].size(); i++) {
  6. var payloadItem = data["payload"][i];
  7. if (payloadItem instanceof Lang.Dictionary && "temperature".equals(payloadItem["par"])) {
  8. var val = payloadItem["val"];
  9. if (val instanceof Lang.String) {
  10. // Convert string to float. If conversion fails, null will be returned
  11. var valAsFloat = val.toFloat();
  12. Background.exit(valAsFloat);
  13. }
  14. if (val instanceof Lang.Float) {
  15. Background.exit(val);
  16. }
  17. }
  18. }
  19. }
  20. }
  21. Background.exit(null);
  22. }
  23.  
  24. public function onTemporalEvent() as Void {
  25. Communications.makeWebRequest(
  26. "https://api.existenz.ch/apiv1/hydro/latest",
  27. {
  28. "locations" => "2030",
  29. "version" => "1.042",
  30. "parameters" => "temperature,flow" // note that %2C in ASCII is ","
  31. },
  32. {
  33. :method => Communications.HTTP_REQUEST_METHOD_GET,
  34. :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
  35. },
  36. method(:onReceive)
  37. );
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement