Hi guys! I've got a file.txt in my SPIFFS where I store 5 row of json object in this format
{"AcX": 1625, "AcY": -225, "AcZ": 1235, "time": 3000}
{"AcX": 1625, "AcY": -25, "AcZ": 1556, "time": 6000}
{"AcX": 1625, "AcY": -132, "AcZ": 1789, "time": 9000}
{"AcX": 1625, "AcY": -67, "AcZ": 345, "time": 12000}
{"AcX": 1625, "AcY": -67, "AcZ": 345, "time": 12000}
After I filled my file.txt with my 5 rows I call a function that read the file, store every row in the array and then I send it via mqtt to my topic.
void mqtt_publish(){
//Open and read the file
File file = LittleFS.open("/file.txt", "r");
if(!file){
Serial.println("file open failed");
} //Serial.println("------ Reading ------");
//Create an empty array
JsonArray arr = doc.to<JsonArray>();
for (int i=0; i<=5; i++){
String s = file.readStringUntil('\n');
JsonObject obj = doc.createNestedObject();
doc[i].add(serialized(s));
}
char sendread[MQTT_BUFFER];
serializeJsonPretty(doc, sendread);
int ret = client.publish("esp8266/JSON", sendread);
file.close();
}
Anyway the output in the serial monitor is this
12:47:54.208 -> Message arrived in topic: esp8266/JSON
12:47:54.208 -> Message:[
12:47:54.208 -> {},
12:47:54.208 -> {},
12:47:54.208 -> {},
12:47:54.208 -> {},
12:47:54.208 -> {},
12:47:54.208 -> {}
12:47:54.208 -> ]
The array with the 5 elements it's created but not filled. What am I missing? Thanks a lot!