[ { "id": "94bfafc7.085d8", "type": "tab", "label": "Meteocat Simple", "disabled": false, "info": "" }, { "id": "8265150d.955108", "type": "http request", "z": "94bfafc7.085d8", "name": "meteodata D3", "method": "GET", "ret": "obj", "paytoqs": false, "url": "https://analisi.transparenciacatalunya.cat/resource/nzvn-apee.json?codi_estacio=D3&$order=data_lectura DESC&$limit=6&$where=codi_variable in('30','32', '33', '34','35','36')", "tls": "", "proxy": "", "authType": "", "x": 350, "y": 100, "wires": [ [ "b3da2232.3ab4e", "731f614f.037ce" ] ] }, { "id": "b3da2232.3ab4e", "type": "function", "z": "94bfafc7.085d8", "name": "Prepare Sentilo msg", "func": "// Prepare sentilo message\n//{\n// \"sensors\": [\n// {\n// \"sensor\": \"D3_P\",\n// \"observations\": [\n// {\n// \"value\": \"1021.3\",\n// \"timestamp\": \"10/11/2020T16:00:00\"\n// }\n// ]\n// }, {\n// \"sensor\": \"D3_HR\",\n// \"observations\": [\n// {\n// \"value\": \"62\",\n// \"timestamp\": \"10/11/2020T16:00:00\"\n// }\n// ]\n// }, ...\n// ]\n//}\n\n\nvar sentiloMessage = {\n \"sensors\": []\n};\n\n// variable to sensor mapping\nvar fields = {30: 'VV10', 32: 'T', 33:'HR',34:'P',35:'PPT',36:'RS'};\n\nif(msg.payload.length===0){\n console.log(\"No new data to publish\");\n return null;\n}\n\nfor (i = 0; i < msg.payload.length; i++) {\n var sensor = msg.payload[i].codi_estacio+\"_\"+fields[msg.payload[i].codi_variable];\n var tsSentilo = convert(msg.payload[i].data_lectura);\n \n sentiloMessage.sensors.push({\n \"sensor\": sensor,\n \"observations\":[{\n \"value\": msg.payload[i].valor_lectura,\n \"timestamp\": tsSentilo\n }]\n });\n\n console.log(\"sensor:\"+sensor+\" date:\"+tsSentilo+\" valor:\"+msg.payload[i].valor_lectura);\n}\n\nmsg.payload=sentiloMessage;\nreturn msg;\n\n// convert from \"2020-11-10T11:00:00.000\" to \"10/11/2020T11:00:00\" for Sentilo format\nfunction convert(timestamp)\n{\n var ts;\n ts = new Date(timestamp);\n return ('00' + ts.getUTCDate()).slice(-2)+'/'+('00' + (ts.getUTCMonth()+1)).slice(-2)+'/'+ ts.getUTCFullYear()+\"T\"+\n ('00' + ts.getUTCHours()).slice(-2) + ':' + ('00' + ts.getUTCMinutes()).slice(-2) + ':' +('00' + ts.getUTCSeconds()).slice(-2);\n}\n\n\n", "outputs": 1, "noerr": 0, "x": 590, "y": 100, "wires": [ [ "d5096c49.f8784", "cec19a9d.3a02d8" ] ] }, { "id": "1527b7a4.17e418", "type": "inject", "z": "94bfafc7.085d8", "name": "Get last data", "topic": "", "payload": "", "payloadType": "date", "repeat": "1800", "crontab": "", "once": false, "onceDelay": 0.1, "x": 170, "y": 100, "wires": [ [ "8265150d.955108" ] ] }, { "id": "731f614f.037ce", "type": "debug", "z": "94bfafc7.085d8", "name": "", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 360, "y": 160, "wires": [] }, { "id": "d5096c49.f8784", "type": "debug", "z": "94bfafc7.085d8", "name": "", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 580, "y": 160, "wires": [] }, { "id": "8c3438a.9efcdc8", "type": "comment", "z": "94bfafc7.085d8", "name": "https://analisi.transparenciacatalunya.cat/resource/nzvn-apee.json?codi_estacio=D3&$order=data_lectura DESC&$limit=6&$where=codi_variable in('30','32', '33', '34','35','36')", "info": "Returns:\n\n[\n {\n \"id\": \"D3301011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"30\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"1.2\",\n \"codi_base\": \"SH\"\n },\n {\n \"id\": \"D3321011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"32\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"17.5\",\n \"codi_base\": \"SH\"\n },\n {\n \"id\": \"D3331011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"33\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"61\",\n \"codi_base\": \"SH\"\n },\n {\n \"id\": \"D3341011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"34\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"995.1\",\n \"codi_base\": \"SH\"\n },\n {\n \"id\": \"D3351011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"35\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"0\",\n \"codi_base\": \"SH\"\n },\n {\n \"id\": \"D3361011201500\",\n \"codi_estacio\": \"D3\",\n \"codi_variable\": \"36\",\n \"data_lectura\": \"2020-11-10T15:00:00.000\",\n \"valor_lectura\": \"60\",\n \"codi_base\": \"SH\"\n }\n]", "x": 620, "y": 40, "wires": [] }, { "id": "cec19a9d.3a02d8", "type": "publish", "z": "94bfafc7.085d8", "name": "", "server": "b26c44b9.3968d8", "providerId": "ensprova@meteocat", "dataType": "data", "identifier": "", "obsValue": "", "urlRaw": "/data/ensprova@meteocat", "x": 820, "y": 100, "wires": [] }, { "id": "b26c44b9.3968d8", "type": "server", "z": "", "alias": "PreconnectaAPI-Meteo", "host": "http://pre-api-sentilo.diba.cat" } ]