Hey there,
after searching the internet for a while a tryin thing out I think it is time to look for some specific help for my problem.
Me and some colleagues working on a school project where we put industrial sensors on an old lathe. The sensors are connected to an io link master. The master is connected with an edge gateway and on the edge gateway is an raspberry pi. I installed mosquito, influxdb, node red and grafana on the raspi via docker. So far so good everything is working. We’re getting mqtt messages from the Edge Gateway into the raspi and can sub the topic in node red.
But we can’t put the data into our influx because the influx don’t like the form of the mqtt message i think. I tried it with an function node, with an change node but I will not work. Can someone give me a hint how I can make my mqtt message influx ready?
The reason is that your MQTT messages (each message is an object) has objects within. InfluxDB will not be able to store an object within an object.(e.g. Distance fields = [object,object] cannot be processed! ) by influxdb
You have to segregate your original message into individual messages so there are no more objects in the messages. Options are:
- try using SPLIT-node (this is not always achieving the outcomes wanted but worth a try)
- use a function node to segregate the MQTT message and only store the information you want in influxdb
I had the same approach (MQTT=> DB) in my early days and got it working to some extend, but as soon new sensors were added it had impacts on my code and especially on the DB structure.
I'm now using a simple DB structure (Source-Name, Sensor-Name, Sensor-Type, Sensor-Value, timestamp). I do a simple field-mapping from my MQTT message to the DB-Structure and write the to the database
Mapping the fields based on topic using a template node (because my DB is SQL based):
Hey,
thank you for your quick reply.
Would it be possible for you to show me the settings behind the nodes? This is my first time dealing with programming and all these things. Unfortunately, I don’t really know how to write such code on my own yet or how to correctly configure the template or switch nodes. I’m truly a complete beginner in this field.
I'm using a SQL database, therefore my template nodes will not help you.
As mentioned above I would start with a split node after you have received the MQTT message.. this should split-up the messages into individual messages without any further objects .. you should be able to write that into your influxdb. Please read details on split-node here
It will be challenging for a beginner to write into database as you have to manipulate your (mqtt) message into the format your database understands. Usually you cant directly write an object into a database, especially if that object has sub-objects (as in your case)