[ { "id": "c518cb18.95c398", "type": "function", "z": "4deb3d15.4857ac", "name": "Build the request towards OpenWeather ", "func": "\nvar lat = msg.request.location.lat;\nvar lon = msg.request.location.lon;\nvar api_key = msg.open_weather_api_key;\n\nmsg.url = \"api.openweathermap.org/data/2.5/weather?lat=\" + lat.toString();\nmsg.url += \"&lon=\"\nmsg.url += lon.toString();\nmsg.url += \"&units=metric&appid=\"\nmsg.url += api_key;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 360, "y": 500, "wires": [ [ "95d2be39.d77fc8" ] ] }, { "id": "95d2be39.d77fc8", "type": "http request", "z": "4deb3d15.4857ac", "name": "POST", "method": "POST", "ret": "txt", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 661, "y": 500, "wires": [ [ "1e398734.b279b9" ] ] }, { "id": "1e398734.b279b9", "type": "json", "z": "4deb3d15.4857ac", "name": "", "property": "payload", "action": "", "pretty": false, "x": 781, "y": 500, "wires": [ [ "244bf4bf.87093c" ] ] }, { "id": "244bf4bf.87093c", "type": "function", "z": "4deb3d15.4857ac", "name": "Add OWeather values + delta pressure", "func": "\nvar external_temperature = msg.payload.main.temp;\nvar external_humidity = msg.payload.main.humidity;\nvar external_pressure = msg.payload.main.pressure;\nvar city_name = msg.payload.name;\n\nmsg.payload = msg.request;\n// Add the external_temperature field\nmsg.payload.value.external_temperature = external_temperature;\nmsg.payload.value.external_humidity = external_humidity;\nmsg.payload.value.external_pressure = external_pressure;\nmsg.payload.value.delta_pressure = msg.payload.value.pressure - external_pressure;\nmsg.payload.value.city_name = city_name;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 350, "y": 580, "wires": [ [ "65d26f22.869ed8", "b2ec9855.0cdca8" ] ] }, { "id": "9c7bce45.c962e8", "type": "http in", "z": "4deb3d15.4857ac", "name": "Add Average Extended", "url": "/addaverageEx", "method": "post", "upload": false, "swaggerDoc": "", "x": 120, "y": 295, "wires": [ [ "f2d481c4.6b005" ] ] }, { "id": "65d26f22.869ed8", "type": "http response", "z": "4deb3d15.4857ac", "name": "", "statusCode": "", "headers": {}, "x": 670, "y": 580, "wires": [] }, { "id": "81a23f2d.851c", "type": "function", "z": "4deb3d15.4857ac", "name": "Calculate and add the average_5_last_temperatures field", "func": "\n\n// Compute the average of the 4 last temperatures + the current one\n// Current temperature\nvar sum = msg.request.value.temperature;\n// the 4 last ones\nfor(var x = 0; x < 4; x++) {\n sum += msg.payload.hits.hits[x]._source.value.temperature;\n}\nvar average = sum/5\n\n//msg.payload = msg.request;\n\n// Add the average_5_last_temperatures\nmsg.request.value.average_5_last_temperatures = average;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 410, "y": 420, "wires": [ [ "c518cb18.95c398" ] ] }, { "id": "dcfe1aa1.d3d26", "type": "comment", "z": "4deb3d15.4857ac", "name": "Save the initial message and build the elastic search request to get the 5 last temperatures", "info": "", "x": 510, "y": 340, "wires": [] }, { "id": "22ce9e47.fd032a", "type": "comment", "z": "4deb3d15.4857ac", "name": "Container management demo ", "info": "My pressurized chemical containers travel from Paris to Lille\n\nI want to know their location and their functioning telemetry : temperature, pressure, fan activity (rpm), hygrometry, CO2 level, door status\n\nBut above all \n- I want to follow the average of the 5 last internal temperatures\n- I want to know external data at the container location: temperature, hygrometry, pressure\n- I want to know the inside vs outside delta pressure\n- I want to see in what town the containers are\n", "x": 140, "y": 40, "wires": [] }, { "id": "f7f75aa6.fbd0d", "type": "comment", "z": "4deb3d15.4857ac", "name": "Get + Add local external data from Open Weather", "info": "", "x": 380, "y": 460, "wires": [] }, { "id": "f2d481c4.6b005", "type": "switch", "z": "4deb3d15.4857ac", "name": "Switch on group \"/demo\"", "property": "payload.metadata.group.path", "propertyType": "msg", "rules": [ { "t": "neq", "v": "/demo", "vt": "str" }, { "t": "eq", "v": "/demo", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 370, "y": 295, "wires": [ [ "aceadbec.349e78" ], [ "28c0c04e.6c169" ] ] }, { "id": "aceadbec.349e78", "type": "http response", "z": "4deb3d15.4857ac", "name": "", "statusCode": "", "headers": {}, "x": 566, "y": 260, "wires": [] }, { "id": "e57a0023.e97168", "type": "comment", "z": "4deb3d15.4857ac", "name": "How : use the LO Asset Android application + Live Objects account", "info": "Install the Android simulator from the play store : https://play.google.com/store/apps/details?id=com.orange.lo.assetdemo\n\nIn Live Objects : \n- create a free account\n- create a \"device\" API key for your Android simulator\n- create an \"application\" API Key for your node red flow\n- create a pipeline towards your entry point : /node-red/api/xxxxxxx/addaverageEx\nBeware of the Authorization field. It must be this way : \n'node-red-api:your_key' base64 encoded (use https://www.base64encode.org/)", "x": 520, "y": 40, "wires": [] }, { "id": "3d69fd3d.ebeb1a", "type": "inject", "z": "4deb3d15.4857ac", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 123, "y": 151, "wires": [ [ "eef7b6ef.b8f6b" ] ] }, { "id": "eef7b6ef.b8f6b", "type": "change", "z": "4deb3d15.4857ac", "name": "", "rules": [ { "t": "set", "p": "api_key", "pt": "flow", "to": "Your Live Objects API key", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 283, "y": 151, "wires": [ [] ] }, { "id": "df8b4d1.611c6b", "type": "comment", "z": "4deb3d15.4857ac", "name": "Input your Live Objects API \"application\" key which will be used into the flow ", "info": "", "x": 313, "y": 116, "wires": [] }, { "id": "f57d17d.4dfb168", "type": "comment", "z": "4deb3d15.4857ac", "name": "Input your Open Weather API key which will be used into the flow ", "info": "", "x": 273, "y": 186, "wires": [] }, { "id": "81025636.74c678", "type": "change", "z": "4deb3d15.4857ac", "name": "", "rules": [ { "t": "set", "p": "open_weather_api_key", "pt": "flow", "to": "Your OpenWeather API key", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 333, "y": 221, "wires": [ [] ] }, { "id": "b11145c1.a53118", "type": "inject", "z": "4deb3d15.4857ac", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 123, "y": 221, "wires": [ [ "81025636.74c678" ] ] }, { "id": "28c0c04e.6c169", "type": "change", "z": "4deb3d15.4857ac", "name": "Set api_key, open_weather_api_key", "rules": [ { "t": "set", "p": "api_key", "pt": "msg", "to": "api_key", "tot": "flow" }, { "t": "set", "p": "open_weather_api_key", "pt": "msg", "to": "open_weather_api_key", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 666, "y": 297, "wires": [ [ "4a9243d9.c64e54" ] ] }, { "id": "4a9243d9.c64e54", "type": "function", "z": "4deb3d15.4857ac", "name": "Store initial msg + build the average last 5 request", "func": "var streamId = msg.payload.streamId;\nstreamId = \"androidnullPRIMARY\";\nmsg.request = msg.payload;\n\nmsg.headers = {};\nmsg.headers['X-API-KEY'] = msg.api_key;\nmsg.headers['Content-Type'] = 'application/json';\n\n/*\nmsg.payload = \"{\\\"size\\\" : 5,\t\\\"query\\\" : {\\\"bool\\\":{\\\"filter\\\": [{\\\"term\\\" : { \\\"streamId\\\": \\\"\";\nmsg.payload += streamId;\nmsg.payload += \"\\\" }}]}},\";\nmsg.payload += \"\\\"sort\\\": { \\\"timestamp\\\": { \\\"order\\\": \\\"desc\\\" }}\";\nmsg.payload += \"}\";\n*/\nmsg.payload =\n{\n \"size\": 5,\n \"query\":\n { \n \"bool\" :{\n \"filter\": [\n {\n \"term\": {\n \"streamId\": streamId\n }\n }\n ]\n }\n },\n \"sort\": {\"timestamp\": {\"order\": \"desc\" }}\n};\n\nmsg.url = \"https://liveobjects.orange-business.com/api/v0/data/search\";\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 390, "y": 380, "wires": [ [ "c2b36ff7.24c07" ] ] }, { "id": "c2b36ff7.24c07", "type": "http request", "z": "4deb3d15.4857ac", "name": "POST", "method": "POST", "ret": "txt", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 663, "y": 380, "wires": [ [ "8d4c0f61.6e305" ] ] }, { "id": "8d4c0f61.6e305", "type": "json", "z": "4deb3d15.4857ac", "name": "", "property": "payload", "action": "", "pretty": false, "x": 784, "y": 380, "wires": [ [ "81a23f2d.851c" ] ] }, { "id": "997f87bf.b9265", "type": "comment", "z": "4deb3d15.4857ac", "name": "Calculate and add the fields coming from OpenWeather", "info": "", "x": 400, "y": 540, "wires": [] }, { "id": "b2ec9855.0cdca8", "type": "json", "z": "4deb3d15.4857ac", "name": "", "property": "payload", "action": "obj", "pretty": false, "x": 770, "y": 260, "wires": [ [ "2ec6a34a.49101c" ] ] }, { "id": "2ec6a34a.49101c", "type": "debug", "z": "4deb3d15.4857ac", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 910, "y": 260, "wires": [] }, { "id": "8d291d7d.95dc28", "type": "comment", "z": "4deb3d15.4857ac", "name": "Configuration", "info": "", "x": 90, "y": 80, "wires": [] } ]