Trouble writing to an InfluxDB

Hi all

Im fairly new to the likes of programming and tinkering with raspberryPi. My first project that I am trying to implement is a counter which uses 4 inductive sensors to count from four separate machines. To begin with, I am having trouble with the output of the counter node synchronising with my database, and I have tried several different approaches. I would like to capture all the data on the output of the counter node, and save it as its various fields and tags. Im sure it is something silly that I am yet to learn. TIA

[{"id":"186fb0d9.3deeaf","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"ed41bdba.865a5","type":"inject","z":"186fb0d9.3deeaf","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":158,"y":263,"wires":[["377f2c1.b2bd3d4"]]},{"id":"4ad10e1a.2204b","type":"inject","z":"186fb0d9.3deeaf","name":"increment","topic":"Woodmizer 1","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":158,"y":223,"wires":[["dbe16548.367da8"]]},{"id":"35397b26.1dfd34","type":"inject","z":"186fb0d9.3deeaf","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":148,"y":303,"wires":[["b8cdbcac.72dd7"]]},{"id":"dbe16548.367da8","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.increment = 3;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":223,"wires":[["cef3f450.5502c8"]]},{"id":"b8cdbcac.72dd7","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.reset = 10;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":303,"wires":[["cef3f450.5502c8"]]},{"id":"377f2c1.b2bd3d4","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":263,"wires":[["cef3f450.5502c8"]]},{"id":"e5958ebc.79a48","type":"debug","z":"186fb0d9.3deeaf","name":"count","active":false,"console":"false","complete":"payload","x":1154.7142333984375,"y":168.42855834960938,"wires":},{"id":"cef3f450.5502c8","type":"counter","z":"186fb0d9.3deeaf","name":"","init":"100","step":"1","lower":"","upper":"","mode":"increment","outputs":1,"x":518,"y":243,"wires":[["a3e78899.9f3848","b4b5c114.935f9","8329fd29.74544"]]},{"id":"72302cb3.3a5784","type":"inject","z":"186fb0d9.3deeaf","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":248,"y":183,"wires":[["cef3f450.5502c8"]]},{"id":"9d765c43.ce3f5","type":"debug","z":"186fb0d9.3deeaf","name":"message","active":true,"console":"false","complete":"true","x":1156.5713844299316,"y":303.00000381469727,"wires":},{"id":"a3e78899.9f3848","type":"change","z":"186fb0d9.3deeaf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":874.1428571428571,"y":220.57142857142856,"wires":[["e5958ebc.79a48"]]},{"id":"b4b5c114.935f9","type":"change","z":"186fb0d9.3deeaf","name":"","rules":[{"t":"set","p":"count","pt":"msg","to":"count","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":871.2857142857142,"y":291.99999999999994,"wires":[["9d765c43.ce3f5"]]},{"id":"8329fd29.74544","type":"influxdb out","z":"186fb0d9.3deeaf","influxdb":"52f04081.7ea1","name":"testdb","measurement":"tester","precision":"","retentionPolicy":"","x":839,"y":137,"wires":},{"id":"52f04081.7ea1","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"TEST","name":"","usetls":false,"tls":""}]

SELECT * FROM tester
name: tester
time value


1558434331161983700 1558434331150
1558434331313012495 1558434331295
1558434331496185719 1558434331485
1558434331668754081 1558434331626
1558434331867333945 1558434331851
1558434331933431087 1558434331920
1558434332048892791 1558434332036
1558434332297181488 1558434332276
1558434332370425881 1558434332356

[{"id":"186fb0d9.3deeaf","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"ed41bdba.865a5","type":"inject","z":"186fb0d9.3deeaf","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":158,"y":263,"wires":[["377f2c1.b2bd3d4"]]},{"id":"4ad10e1a.2204b","type":"inject","z":"186fb0d9.3deeaf","name":"increment","topic":"Woodmizer 1","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":158,"y":223,"wires":[["dbe16548.367da8"]]},{"id":"35397b26.1dfd34","type":"inject","z":"186fb0d9.3deeaf","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":148,"y":303,"wires":[["b8cdbcac.72dd7"]]},{"id":"dbe16548.367da8","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.increment = 3;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":223,"wires":[["cef3f450.5502c8"]]},{"id":"b8cdbcac.72dd7","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.reset = 10;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":303,"wires":[["cef3f450.5502c8"]]},{"id":"377f2c1.b2bd3d4","type":"function","z":"186fb0d9.3deeaf","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":263,"wires":[["cef3f450.5502c8"]]},{"id":"e5958ebc.79a48","type":"debug","z":"186fb0d9.3deeaf","name":"count","active":false,"console":"false","complete":"payload","x":1154.7142333984375,"y":168.42855834960938,"wires":},{"id":"cef3f450.5502c8","type":"counter","z":"186fb0d9.3deeaf","name":"","init":"100","step":"1","lower":"","upper":"","mode":"increment","outputs":1,"x":518,"y":243,"wires":[["a3e78899.9f3848","b4b5c114.935f9","8329fd29.74544"]]},{"id":"72302cb3.3a5784","type":"inject","z":"186fb0d9.3deeaf","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":248,"y":183,"wires":[["cef3f450.5502c8"]]},{"id":"9d765c43.ce3f5","type":"debug","z":"186fb0d9.3deeaf","name":"message","active":true,"console":"false","complete":"true","x":1156.5713844299316,"y":303.00000381469727,"wires":},{"id":"a3e78899.9f3848","type":"change","z":"186fb0d9.3deeaf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":874.1428571428571,"y":220.57142857142856,"wires":[["e5958ebc.79a48"]]},{"id":"b4b5c114.935f9","type":"change","z":"186fb0d9.3deeaf","name":"","rules":[{"t":"set","p":"count","pt":"msg","to":"count","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":871.2857142857142,"y":291.99999999999994,"wires":[["9d765c43.ce3f5"]]},{"id":"8329fd29.74544","type":"influxdb out","z":"186fb0d9.3deeaf","influxdb":"52f04081.7ea1","name":"testdb","measurement":"tester","precision":"","retentionPolicy":"","x":839,"y":137,"wires":},{"id":"52f04081.7ea1","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"TEST","name":"","usetls":false,"tls":""}]

There might be something missing from your flow code, it gives an error. I suspect you copy/paste the incorrectly formatted code from your first post.

lets try this one...

[{"id":"7736f534.b6954c","type":"inject","z":"afdd2e1b.0988a","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":141,"y":321,"wires":[["98062150.e24bb"]]},{"id":"cbce2cb0.870ed","type":"inject","z":"afdd2e1b.0988a","name":"increment","topic":"Woodmizer 1","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":141,"y":281,"wires":[["2b64bef5.bda082"]]},{"id":"9ade384c.b2a0c8","type":"inject","z":"afdd2e1b.0988a","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":131,"y":361,"wires":[["1b5faf56.af82c1"]]},{"id":"2b64bef5.bda082","type":"function","z":"afdd2e1b.0988a","name":"msg object","func":"msg.increment = 3;\nreturn msg;","outputs":1,"noerr":0,"x":311,"y":281,"wires":[["dc5cc42e.560608"]]},{"id":"1b5faf56.af82c1","type":"function","z":"afdd2e1b.0988a","name":"msg object","func":"msg.reset = 10;\nreturn msg;","outputs":1,"noerr":0,"x":311,"y":361,"wires":[["dc5cc42e.560608"]]},{"id":"98062150.e24bb","type":"function","z":"afdd2e1b.0988a","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":311,"y":321,"wires":[["dc5cc42e.560608"]]},{"id":"5343b1a0.e1b8a","type":"debug","z":"afdd2e1b.0988a","name":"count","active":true,"console":"false","complete":"payload","x":1137.7142333984375,"y":226.42855834960938,"wires":[]},{"id":"dc5cc42e.560608","type":"counter","z":"afdd2e1b.0988a","name":"","init":"100","step":"1","lower":"","upper":"","mode":"increment","outputs":1,"x":501,"y":301,"wires":[["1c42e586.b83c4a","b91d139c.ce256","c93555ca.f8bb68","5343b1a0.e1b8a","e3e07737.2c6e28"]]},{"id":"a434a856.b30018","type":"inject","z":"afdd2e1b.0988a","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":231,"y":241,"wires":[["dc5cc42e.560608"]]},{"id":"e3e07737.2c6e28","type":"debug","z":"afdd2e1b.0988a","name":"message","active":true,"console":"false","complete":"true","x":1139.5713844299316,"y":361.00000381469727,"wires":[]},{"id":"1c42e586.b83c4a","type":"change","z":"afdd2e1b.0988a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":857.1428571428571,"y":278.57142857142856,"wires":[[]]},{"id":"b91d139c.ce256","type":"change","z":"afdd2e1b.0988a","name":"","rules":[{"t":"set","p":"count","pt":"msg","to":"count","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":854.2857142857142,"y":349.99999999999994,"wires":[[]]},{"id":"c93555ca.f8bb68","type":"influxdb out","z":"afdd2e1b.0988a","influxdb":"52f04081.7ea1","name":"testdb","measurement":"tester","precision":"","retentionPolicy":"","x":822,"y":195,"wires":[]},{"id":"52f04081.7ea1","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"TEST","name":"","usetls":false,"tls":""}]

I am a bit confused what you are trying to accomplish with your flow. What would you like to 'count' ?

If you read the info panel for the influx node:

If msg.payload is a string, number, or boolean, it will be written as a single value to the specified measurement (called value ).

If msg.payload is an object containing multiple properties, the fields will be written to the measurement.

If msg.payload is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.

Your function & count nodes don't output msg.payload, but msg.count, msg.increment etc.

Thank you very much, that does make a whole lot more sense now. What would be the conventional method of adding the data from msg.count and msg.increment to the msg.payload string, with all necessary influxdb notation?

What is the purpose of the 'count' ? you can count the records too ?

I am trying to write data into the influx node and it only receives the payload as a time stamp, all other fields from the output of the counter node are ignored. How do I resolve this issue? Regards

So basically you don't need the counter, only a timestamp and a sensor name (i assume) ?

I need to receive the incremental value as well as the count total and topic at the influx node so that I can can write the following data sets..

-Timestamp (even though this will be issued by influx automatically)
-topic (machine 1,2,3 or 4)
-count
-Increment

I feel as if it has something to do with the structure of my message. When I debug it, it shows as a msg:object and not msg:payload? The payload is picked up within the string as an injected timestamp, and that’s where the data capture ends...

Try this flow:

[{"id":"f5df081e.7602a8","type":"inject","z":"802bec.02eb2c18","name":"","topic":"sensor1","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":288,"y":352,"wires":[["b62ad79d.bf9fa8"]]},{"id":"dea382c5.833c3","type":"inject","z":"802bec.02eb2c18","name":"","topic":"sensor2","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":288,"y":396,"wires":[["c56122b6.6c2e1"]]},{"id":"5a3e1d4f.3c5de4","type":"inject","z":"802bec.02eb2c18","name":"","topic":"sensor3","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":288,"y":440,"wires":[["4c6b7822.1ae7f"]]},{"id":"a01d5886.bbd218","type":"inject","z":"802bec.02eb2c18","name":"","topic":"sensor4","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":288,"y":484,"wires":[["241dc1b3.109116"]]},{"id":"2fca3b37.220194","type":"debug","z":"802bec.02eb2c18","name":"to influx","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":896,"y":418,"wires":[]},{"id":"303374a9.1d2e1c","type":"function","z":"802bec.02eb2c18","name":"","func":"\n\nmsg = {payload:{timestamp:msg.payload,sensor:msg.topic,count:msg.count,increment:msg.increment}}\nreturn msg;","outputs":1,"noerr":0,"x":732,"y":418,"wires":[["2fca3b37.220194"]]},{"id":"b62ad79d.bf9fa8","type":"counter","z":"802bec.02eb2c18","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":500,"y":352,"wires":[["303374a9.1d2e1c"]]},{"id":"241dc1b3.109116","type":"counter","z":"802bec.02eb2c18","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":500,"y":484,"wires":[["303374a9.1d2e1c"]]},{"id":"4c6b7822.1ae7f","type":"counter","z":"802bec.02eb2c18","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":500,"y":440,"wires":[["303374a9.1d2e1c"]]},{"id":"c56122b6.6c2e1","type":"counter","z":"802bec.02eb2c18","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":500,"y":396,"wires":[["303374a9.1d2e1c"]]}]

It is unfortunate that the counter-node does not with with topics, could have saved 3 nodes, but it works.
You should be able to connect the function node to influx with a measurement field.