Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onReceive(responseCode as Lang.Number, data as Lang.Dictionary or Lang.String or Null) as Void {
- System.println("onReceive: response code: " + responseCode + ", data: " + data);
- if (responseCode == 200) {
- if (data["payload"] != null && data["payload"] instanceof Lang.Array) {
- for (var i = 0; i < data["payload"].size(); i++) {
- var payloadItem = data["payload"][i];
- if (payloadItem instanceof Lang.Dictionary && "temperature".equals(payloadItem["par"])) {
- var val = payloadItem["val"];
- if (val instanceof Lang.String) {
- // Convert string to float. If conversion fails, null will be returned
- var valAsFloat = val.toFloat();
- Background.exit(valAsFloat);
- }
- if (val instanceof Lang.Float) {
- Background.exit(val);
- }
- }
- }
- }
- }
- Background.exit(null);
- }
- public function onTemporalEvent() as Void {
- Communications.makeWebRequest(
- "https://api.existenz.ch/apiv1/hydro/latest",
- {
- "locations" => "2030",
- "version" => "1.042",
- "parameters" => "temperature,flow" // note that %2C in ASCII is ","
- },
- {
- :method => Communications.HTTP_REQUEST_METHOD_GET,
- :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
- },
- method(:onReceive)
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement