Ok, call me a n00b but I am not getting MQTT to work to send data to Influxdb.
What I want to achieve:
Send gas meter (P1) data to influx so I can create cool graphics in Grafana.
The protocol from the gasmeter is not yet supported by Http-Link so I wanted to try something via MQTT.
I created the hardware device:
And according to the log there is a connection:
2016-08-02 11:56:16.123 MQTT: Connecting to xxx.xxx.xxx.xxx:1883
2016-08-02 11:56:16.225 MQTT: connected to: xxx.xxx.xxx.xxx:1883
2016-08-02 11:56:16.325 MQTT: Subscribed
In Node-Red I imported the following:
Code: Select all
[{"id":"7b366043.74005","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":15,"cleansession":true,"willQos":"0","birthQos":"0"},{"id":"1be38963.6067a7","type":"mqtt in","z":"ecee940b.146508","name":"Domotic Out","topic":"domoticz/out","broker":"7b366043.74005","x":120,"y":158,"wires":[["962a6069.2b9c5"]]},{"id":"962a6069.2b9c5","type":"function","z":"ecee940b.146508","name":"ToInfluxDB","func":"var date = new Date(msg.payload);\ndata=JSON.parse(msg.payload);\n\nmsg.payload = {}; //null msg obj and create new properties\n\nvar influx_obj = \"[{\";\n\n\ninflux_obj += '\"name\": \"' + data.dtype.split(\" + \").join(\"\") + '\",';\nvar columns='\"columns\": [';\n\ncolumns+='\"idx\", \"nvalue\"';\n\nvar points='\"points\": [[';\n\npoints+= data.idx + ', ' + data.nvalue;\n\nfor (ii=0; ii<10; ii++)\n{\n var vidx = (ii+1).toString();\n var vname = \"svalue\" + vidx;\n if (typeof data[vname] != 'undefined') {\n columns+=', \"' + vname + '\"';\n var vdata=data[vname];\n if (!isNaN(vdata)) {\n points+=', ' + parseFloat(vdata);\n }\n else {\n points+=', \"' + vdata + '\"';\n }\n }\n}\n\n\ncolumns+=']';\npoints+=']]';\n\ninflux_obj+=columns+\",\" + points;\n\ninflux_obj+=\"}]\";\n\nmsg.payload=influx_obj;\n\nreturn msg;","outputs":1,"noerr":0,"x":225,"y":224,"wires":[["df17cf36.7a29f","19155261.c3e15e"]]},{"id":"df17cf36.7a29f","type":"debug","z":"ecee940b.146508","name":"","active":false,"console":false,"complete":false,"x":528.0833129882812,"y":223.08331298828125,"wires":[]},{"id":"19155261.c3e15e","type":"http request","z":"ecee940b.146508","name":"TEST","method":"POST","ret":"txt","url":"http://xxx.xxx.xxx.xxx:8086/db/domoticz/series?u=root&p=root","x":333.08331298828125,"y":317.08331298828125,"wires":[["4bab87f8.cc2218"]]},{"id":"4bab87f8.cc2218","type":"debug","z":"ecee940b.146508","name":"","active":false,"console":false,"complete":false,"x":529,"y":317,"wires":[]}]
Node-Red can deploy this without issues and has connection to Domoticz
But still, no info in Influx...
What am I doing wrong??