-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Sorry to bug you again, but I'm really perplexed. I updated the code that I really want to serialize and tried to run it. But each time it runs, the processor exceptions out and restarts at the point of serializing the document. I know its not a memory issue because the code is so short. Can you give me any advice on this matter. Just so yo u can look at the code to check for errors, here it is.
I hate to waste you time, but I really would appreciate a little.
Thanks in advance.
#include <Arduino.h>
#include "ArduinoJson.h"
#include "PinConfig.h"
struct Board {
std::vector<PinConfig *> analog {};
std::vector<PinConfig *> digital {};
};
Board systemBoards[4] {};
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Starting application");
JsonDocument doc;
JsonObject saveToFile = doc["saveToFile"].to<JsonObject>();
saveToFile["controllerId"] = 1;
saveToFile["trackPowerMonitorId"] = "Reset1";
saveToFile["stateSendMonitorId"] = "Send2";
JsonArray boards = saveToFile["boards"].to<JsonArray>();
for (unsigned int address = 0; address < 1; address++) {
JsonObject board = doc["board"].to<JsonObject>();
boards.add(board);
board["address"] = address;
board["analog"] = doc.to<JsonArray>();
board["digital"] = doc.to<JsonArray>();
for (auto pinConfig : systemBoards[address].analog) {
auto board_pinConfig = board["analog"].add<JsonObject>();
board_pinConfig["firstPin"] = pinConfig->firstPin;
auto it = pinStringTable.find(pinConfig->pinType);
if (it != pinStringTable.end()) {
board_pinConfig["type"] = it->second;
}
board_pinConfig["id"] = pinConfig->id;
if (strlen(pinConfig->actuatorId) > 0) {
board_pinConfig["actuatorId"] = pinConfig->actuatorId;
}
if (pinConfig->onWidth) {
board_pinConfig["onWidth"] = pinConfig->onWidth;
}
}
for (auto pinConfig : systemBoards[address].digital) {
auto board_pinConfig = board["digital"].add<JsonObject>();
board_pinConfig["firstPin"] = pinConfig->firstPin;
auto it = pinStringTable.find(pinConfig->pinType);
if (it != pinStringTable.end()) {
board_pinConfig["type"] = it->second;
}
board_pinConfig["id"] = pinConfig->id;
}
}
String result;
serializeJson(saveToFile, result);
Serial.println(result);
}
void loop() {
// write your code here
}