Injecting multiple JSON objects in a database

Hello!

I have a data logger in a device that captures dat in an SD at a 100Hz data rate from 6 sensors. Every 0.01s I collect the data and create a JSON object that looks like this:

lectura = {
"ID" : 1,
"Fuerza" : [15.23,17.72],
"Velocidad" : [5,4.8],
"timestamp" : "19-08-2020T16:00:13Z",
"milis" : 12563452
}

Once the device finds WiFi, it sends the info to my app, which I am managing with node-red. Thing is, its such a big amount of data that I would like to send it in packets of 50 or 100 objects at once. But once I recieve the data in Node-Red, I don´t know how to split every object from one another and inject it into the data base.

The flow is the following:

[{"id":"7b63b1a9.f2278","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"604ee5e2.10df3c","type":"debug","z":"7b63b1a9.f2278","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1640,"y":400,"wires":[]},{"id":"3c7e18e4.a04d48","type":"inject","z":"7b63b1a9.f2278","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"{\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452} {\"ID\":1,\"Fuerza\":[15.23,17.72],\"Velocidad\":[5,4.8],\"timestamp\":\"19-08-2020T16:00:13Z\",\"milis\":12563452}","payloadType":"jsonata","x":330,"y":300,"wires":[["d036c01a.fe472"]]},{"id":"d036c01a.fe472","type":"function","z":"7b63b1a9.f2278","name":"","func":"var id = msg.payload.ID;\nvar Fi = msg.payload.Fuerza[0];\nvar Fd = msg.payload.Fuerza[1];\nvar Vi = msg.payload.Velocidad[0];\nvar Vd = msg.payload.Velocidad[1];\nvar time = msg.payload.timestamp;\nvar mili = msg.payload.milis;\n\nmsg.topic = \"INSERT INTO Sensores(ID_and_s,V_izq,V_der,F_izq,F_der,tiempo_mili)\" + \"VALUES (\"+id+\",\"+Vi+\",\"+Vd+\",\"+Fi+\",\"+Fd+\",\"+mili+\")\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":300,"wires":[["13d41800.259e08"]]},{"id":"13d41800.259e08","type":"mysql","z":"7b63b1a9.f2278","mydb":"2becde9d.a8a7b2","name":"","x":720,"y":300,"wires":[["4d23b71e.34de58"]]},{"id":"4d23b71e.34de58","type":"debug","z":"7b63b1a9.f2278","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":380,"wires":[]},{"id":"2becde9d.a8a7b2","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"I-Walker","tz":""}]

Is there anyway? Or is just better to send them one by one.. The sending rate doesn´t need to be 100Hz as Ive already stored the timestamp.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.