Best approach in Node-RED to save data from MQTT broker to MongoDB -
right i'm working on architecture application manage smart sockets. when smart socket configured (connected user account) , turn on automatically publish data in mqtt (let's every 5s) @ topic "user_name/socket_id", node-red save mongodb.
collection storing sockets data looks this:
{ "socket_id": "socket_id", "data": { "0": { "date": "start_date", "data": { "0" : 10.0, "1" : 10.0, "2" : 10.0, "3" : 10.0 } }, "1": { "date": "start_date", "data": { "0" : 15.0, "1" : 15.0, "2" : 15.0 } } } }
the idea first "data" stores "date" , "data" every uninterrupted sequence of data. if "start_date" 14:00:00, data index 8 14:00:40 (8 * 5s = 40s).
in node.red this:
{ "topic": "user_name/socket_id", "payback": "10.0" }
so find proper collection.
and problem , question: best approach in node.red check if data arrive continuous? because if it's not have create new field current date , can make updates next values.
i thinking last field in "data", date, add last index * 5s, , check if equal current data don't solution, there have more esthetic way.
what think this? how can this? or maybe should change in structure of database, mqtt topic ...?
if need more information, ask!
Comments
Post a Comment