I am trying to collect sensor data from ESP32 to RPi.
I am getting a packet of data containing strings in intervals of 10secs(this can be changed). I am getting sensor data, along with geolocation and device ID which comes in a single packet. I want to append the timestamp and convert the whole packets into JSON format and send it via MQTT to AWS. Can someone help me with how to do this?
Yes we can help you but it’s unclear (at least to me) if the data getting into Node-RED is all arriving at the same time in one msg or does the data arrive at various times.
If it is in one msg and you just want to add a timestamp, you might be able do it in a function node or a template node or maybe even with a change node.
Show us the data you are getting and an example of what it should look like to send off.
This is my incoming data
"geodata=15.34-34.67;device_ID=3;Temperature=10 degC;Humidity=2 RH;WindSpeed=5 m/s"
and I would like to send it in this format
{"geodata": " ",
"device_ID: ,
"value": {
"timestamp": , // this is an array
"Temperature": , // this is an array
"Humidity": , // this is an array
"Windspeed": // this is an array
}
}
Here the data inside the timestamp, temperature, humidity, and windspeed will be an array because I will be sending the data to the cloud occasionally. For example, If I am getting data from ESP32 every 10secs, then I will append the data for 2mins, and send the complete set of data at once every 2mins. I hope this is clear.
I had already tried this, but my requirement is to send the appended temperature, humidity, and windspeed data. If I get 10 data packets from esp32 and I want to send an array of data. I need to have geodata and device_ID as one entry but temp, humidity, and windspeed can have multiple entries like an array.
Right now, I am testing one scenario only. So, geodata and device_ID will be the same for now. But there might be a scenario I might have 2 or 3. Not more than that. Geodata is a unique identifier according to device_ID.
This might work but only for constant geodata.
It constructs a compound object from successive messages, but it always returns the message as it is so far, which you may not want.