I have it working, it seems like it works okay. is there anything wrong with the way im using String here? is this doomed to crash my sketch.
void handlegettmjson5() {
char a[15];
char b[15];
char c[15];
char d[15];
char e[15];
char f[15];
char g[15];
char h[15];
char i[15];
char j[15];
char k[15];
char l[15];
char m[15];
char n[15];
char o[15];
char p[15];
char q[15];
if (_EEPROM.enabled) {
sprintf(c, "%s", "Enabled");
} else {
sprintf(c, "%s", "Disabled");
}
if (_EEPROM.timerEnabled[0]) {
sprintf(d, "%s", "Enabled");
} else {
sprintf(d, "%s", "Disabled");
}
if (_EEPROM.timerEnabled[1]) {
sprintf(e, "%s", "Enabled");
} else {
sprintf(e, "%s", "Disabled");
}
if (_EEPROM.timerEnabled[2]) {
sprintf(f, "%s", "Enabled");
} else {
sprintf(f, "%s", "Disabled");
}
if (_EEPROM.timerEnabled[3]) {
sprintf(g, "%s", "Enabled");
} else {
sprintf(g, "%s", "Disabled");
}
if (_EEPROM.timerEnabled[4]) {
sprintf(h, "%s", "Enabled");
} else {
sprintf(h, "%s", "Disabled");
}
if (_EEPROM.cleanMode) {
sprintf(i, "%s", "Enabled");
} else {
sprintf(i, "%s", "Disabled");
}
if (!_EEPROM.timerRunning[0]) {
sprintf(j, "%s", "Running");
} else {
sprintf(j, "%s", "Not Running");
}
if (!_EEPROM.timerRunning[1]) {
sprintf(k, "%s", "Running");
} else {
sprintf(k, "%s", "Not Running");
}
if (!_EEPROM.timerRunning[2]) {
sprintf(l, "%s", "Running");
} else {
sprintf(l, "%s", "Not Running");
}
if (!_EEPROM.timerRunning[3]) {
sprintf(m, "%s", "Running");
} else {
sprintf(m, "%s", "Not Running");
}
if (!_EEPROM.timerRunning[4]) {
sprintf(n, "%s", "Running");
} else {
sprintf(n, "%s", "Not Running");
}
if (_EEPROM.cleanMode) {
sprintf(o, "%s", "Enabled");
} else {
sprintf(o, "%s", "Disabled");
}
if (!_EEPROM.timerRunning[5]) {
sprintf(p, "%s", "Running");
} else {
sprintf(p, "%s", "Not Running");
}
server.send(200, "text/plane", "{\"tm1t1rt\":[" +
String(_EEPROM.timerRuntimes[0]) + "]" + "," + "\"tm1t2rt\":[" +
String(_EEPROM.timerRuntimes[1]) + "]" + "," + "\"tm1t3rt\":[" +
String(_EEPROM.timerRuntimes[2]) + "]" + "," + "\"tm1t4rt\":[" +
String(_EEPROM.timerRuntimes[3]) + "]" + "," + "\"tm1t5rt\":[" +
String(_EEPROM.timerRuntimes[4]) + "]" + "," + "\"tm1cleanrt\":[" +
String(_EEPROM.timerRuntimes[5]) + "]" + "," + "\"tm1status\":[\"" +
String(c) + "\"]" + "," + "\"tm1t1s\":[\"" +
String(d) + "\"]" + "," + "\"tm1t2s\":[\"" +
String(e) + "\"]" + "," + "\"tm1t3s\":[\"" +
String(f) + "\"]" + "," + "\"tm1t4s\":[\"" +
String(g) + "\"]" + "," + "\"tm1t5s\":[\"" +
String(h) + "\"]" + "," + "\"tm1cleans\":[\"" +
String(i) + "\"]" + "," + "\"tm1t1status\":[\"" +
String(j) + "\"]" + "," + "\"tm1t2status\":[\"" +
String(k) + "\"]" + "," + "\"tm1t3status\":[\"" +
String(l) + "\"]" + "," + "\"tm1t4status\":[\"" +
String(m) + "\"]" + "," + "\"tm1t5status\":[\"" +
String(n) + "\"]" + "," + "\"lightstatus\":[" +
String(lightsOn) + "]" + "," + "\"tm1cleanss\":[\"" +
String(o) + "\"]" + "," + "\"tm1cleanstatus\":[\"" +
String(p) + "\"]" + "," + "\"labelt1\":[\"" +
String(_EEPROM.label[0]) + "\"]" + "," + "\"labelt2\":[\"" +
String(_EEPROM.label[1]) + "\"]" + "," + "\"labelt3\":[\"" +
String(_EEPROM.label[2]) + "\"]" + "," + "\"labelt4\":[\"" +
String(_EEPROM.label[3]) + "\"]" + "," + "\"labelt5\":[\"" +
String(_EEPROM.label[4]) + "\"]" + "," + "\"labelt6\":[\"" +
String(_EEPROM.label[5]) + "\"]" + "," + "\"t1otdv\":[" +
String(_EEPROM.timerTimes[0][0]) + "]" + "," + "\"t1offtdv\":[" +
String(_EEPROM.timerTimes[0][1]) + "]" + "," + "\"t1otnv\":[" +
String(_EEPROM.timerTimes[0][2]) + "]" + "," + "\"t1offtnv\":[" +
String(_EEPROM.timerTimes[0][3]) + "]" + "," + "\"t2otdv\":[" +
String(_EEPROM.timerTimes[1][0]) + "]" + "," + "\"t2offtdv\":[" +
String(_EEPROM.timerTimes[1][1]) + "]" + "," + "\"t2otnv\":[" +
String(_EEPROM.timerTimes[1][2]) + "]" + "," + "\"t2offtnv\":[" +
String(_EEPROM.timerTimes[1][3]) + "]" + "," + "\"t3otdv\":[" +
String(_EEPROM.timerTimes[2][0]) + "]" + "," + "\"t3offtdv\":[" +
String(_EEPROM.timerTimes[2][1]) + "]" + "," + "\"t3otnv\":[" +
String(_EEPROM.timerTimes[2][2]) + "]" + "," + "\"t3offtnv\":[" +
String(_EEPROM.timerTimes[2][3]) + "]" + "," + "\"t4otdv\":[" +
String(_EEPROM.timerTimes[3][0]) + "]" + "," + "\"t4offtdv\":[" +
String(_EEPROM.timerTimes[3][1]) + "]" + "," + "\"t4otnv\":[" +
String(_EEPROM.timerTimes[3][2]) + "]" + "," + "\"t4offtnv\":[" +
String(_EEPROM.timerTimes[3][3]) + "]" + "," + "\"t5otdv\":[" +
String(_EEPROM.timerTimes[4][0]) + "]" + "," + "\"t5offtdv\":[" +
String(_EEPROM.timerTimes[4][1]) + "]" + "," + "\"t5otnv\":[" +
String(_EEPROM.timerTimes[4][2]) + "]" + "," + "\"t5offtnv\":[" +
String(_EEPROM.timerTimes[4][3]) + "]" + "," + "\"cleanondurationv\":[" +
String(_EEPROM.cleanOnTime) + "]" + "," + "\"cleanoffdurationv\":[" +
String(_EEPROM.cleanOffTime) + "]" + "," + "\"disinfectdurationv\":[" +
String(_EEPROM.cleanDisinfectTime) + "]" + "," + "\"datetime\":[\"" +
String(str) + "\"]"
+ "}" );
here is the output of the json object,
{"tm1t1rt":[0],"tm1t2rt":[0],"tm1t3rt":[0],"tm1t4rt":[0],"tm1t5rt":[0],"tm1cleanrt":[1],"tm1status":["Disabled"],"tm1t1s":["Enabled"],"tm1t2s":["Enabled"],"tm1t3s":["Enabled"],"tm1t4s":["Enabled"],"tm1t5s":["Enabled"],"tm1cleans":["Enabled"],"tm1t1status":["Not Running"],"tm1t2status":["Not Running"],"tm1t3status":["Not Running"],"tm1t4status":["Not Running"],"tm1t5status":["Not Running"],"lightstatus":[0],"tm1cleanss":["Enabled"],"tm1cleanstatus":["Running"],"labelt1":["default"],"labelt2":["default"],"labelt3":["default"],"labelt4":["default"],"labelt5":["default"],"labelt6":["default"],"t1otdv":[2000],"t1offtdv":[120000],"t1otnv":[2000],"t1offtnv":[120000],"t2otdv":[2000],"t2offtdv":[120000],"t2otnv":[2000],"t2offtnv":[120000],"t3otdv":[2000],"t3offtdv":[120000],"t3otnv":[2000],"t3offtnv":[120000],"t4otdv":[2000],"t4offtdv":[120000],"t4otnv":[2000],"t4offtnv":[120000],"t5otdv":[2000],"t5offtdv":[120000],"t5otnv":[2000],"t5offtnv":[120000],"cleanondurationv":[8000],"cleanoffdurationv":[1000],"disinfectdurationv":[120000],"datetime":["2021/8/5 4:33:15"]}
here is what i originally had,
void handlegettmjson() {
//yield();
StaticJsonDocument<1000> doc;
JsonArray tm1t1rt = doc.createNestedArray("tm1t1rt");
JsonArray tm1t2rt = doc.createNestedArray("tm1t2rt");
JsonArray tm1t3rt = doc.createNestedArray("tm1t3rt");
JsonArray tm1t4rt = doc.createNestedArray("tm1t4rt");
JsonArray tm1t5rt = doc.createNestedArray("tm1t5rt");
JsonArray tm1cleanrt = doc.createNestedArray("tm1cleanrt");
JsonArray tm1SS = doc.createNestedArray("tm1status");
JsonArray tm1t1s = doc.createNestedArray("tm1t1s");
JsonArray tm1t2s = doc.createNestedArray("tm1t2s");
JsonArray tm1t3s = doc.createNestedArray("tm1t3s");
JsonArray tm1t4s = doc.createNestedArray("tm1t4s");
JsonArray tm1t5s = doc.createNestedArray("tm1t5s");
JsonArray tm1cleans = doc.createNestedArray("tm1cleans");
JsonArray tm1t1status = doc.createNestedArray("tm1t1status");
JsonArray tm1t2status = doc.createNestedArray("tm1t2status");
JsonArray tm1t3status = doc.createNestedArray("tm1t3status");
JsonArray tm1t4status = doc.createNestedArray("tm1t4status");
JsonArray tm1t5status = doc.createNestedArray("tm1t5status");
JsonArray lightstatus = doc.createNestedArray("lightstatus");
JsonArray cleanstatus = doc.createNestedArray("tm1cleanss");
JsonArray tm1cleanstatus = doc.createNestedArray("tm1cleanstatus");
lightstatus.add(lightsOn);
if (_EEPROM.cleanMode) {
cleanstatus.add("Enabled");
} else {
cleanstatus.add("Disabled");
}
tm1t1rt.add(_EEPROM.timerRuntimes[0]);
tm1t2rt.add(_EEPROM.timerRuntimes[1]);
tm1t3rt.add(_EEPROM.timerRuntimes[2]);
tm1t4rt.add(_EEPROM.timerRuntimes[3]);
tm1t5rt.add(_EEPROM.timerRuntimes[4]);
tm1cleanrt.add(_EEPROM.timerRuntimes[5]);
if (_EEPROM.enabled) {
tm1SS.add("Enabled");
} else {
tm1SS.add("Disabled");
}
if (_EEPROM.timerEnabled[0]) {
tm1t1s.add("Enabled");
} else {
tm1t1s.add("Disabled");
}
if (_EEPROM.timerEnabled[1]) {
tm1t2s.add("Enabled");
} else {
tm1t2s.add("Disabled");
}
if (_EEPROM.timerEnabled[2]) {
tm1t3s.add("Enabled");
} else {
tm1t3s.add("Disabled");
}
if (_EEPROM.timerEnabled[3]) {
tm1t4s.add("Enabled");
} else {
tm1t4s.add("Disabled");
}
if (_EEPROM.timerEnabled[4]) {
tm1t5s.add("Enabled");
} else {
tm1t5s.add("Disabled");
}
if (_EEPROM.timerEnabled[5]) {
tm1cleans.add("Enabled");
} else {
tm1cleans.add("Disabled");
}
if (!_EEPROM.timerRunning[0]) {
tm1t1status.add("Running");
// char a[] = {"Running"};
} else {
// char a[] = {"Not Running"};
tm1t1status.add("Not Running");
}
if (!_EEPROM.timerRunning[1]) {
tm1t2status.add("Running");
} else {
tm1t2status.add("Not Running");
}
if (!_EEPROM.timerRunning[2]) {
tm1t3status.add("Running");
} else {
tm1t3status.add("Not Running");
}
if (!_EEPROM.timerRunning[3]) {
tm1t4status.add("Running");
} else {
tm1t4status.add("Not Running");
}
if (!_EEPROM.timerRunning[4]) {
tm1t5status.add("Running");
} else {
tm1t5status.add("Not Running");
}
if (!_EEPROM.timerRunning[5]) {
tm1cleanstatus.add("Running");
} else {
tm1cleanstatus.add("Not Running");
}
char JSON[1000];
serializeJson(doc, JSON);
server.send(200, "text/plane", JSON);
}
void handlegettmjson2() {
// yield();
DynamicJsonDocument doc(600);
JsonArray t1otdv = doc.createNestedArray("t1otdv");
JsonArray t1offtdv = doc.createNestedArray("t1offtdv");
JsonArray t2otdv = doc.createNestedArray("t2otdv");
JsonArray t2offtdv = doc.createNestedArray("t2offtdv");
JsonArray t3otdv = doc.createNestedArray("t3otdv");
JsonArray t3offtdv = doc.createNestedArray("t3offtdv");
JsonArray t4otdv = doc.createNestedArray("t4otdv");
JsonArray t4offtdv = doc.createNestedArray("t4offtdv");
JsonArray t1otnv = doc.createNestedArray("t1otnv");
JsonArray t1offtnv = doc.createNestedArray("t1offtnv");
JsonArray t2otnv = doc.createNestedArray("t2otnv");
JsonArray t2offtnv = doc.createNestedArray("t2offtnv");
JsonArray t3otnv = doc.createNestedArray("t3otnv");
JsonArray t3offtnv = doc.createNestedArray("t3offtnv");
JsonArray t4otnv = doc.createNestedArray("t4otnv");
JsonArray t4offtnv = doc.createNestedArray("t4offtnv");
t1otdv.add(_EEPROM.timerTimes[0][0]);
t1offtdv.add(_EEPROM.timerTimes[0][1]);
t2otdv.add(_EEPROM.timerTimes[1][0]);
t2offtdv.add(_EEPROM.timerTimes[1][1]);
t3otdv.add(_EEPROM.timerTimes[2][0]);
t3offtdv.add(_EEPROM.timerTimes[2][1]);
t4otdv.add(_EEPROM.timerTimes[3][0]);
t4offtdv.add(_EEPROM.timerTimes[3][1]);
t1otnv.add(_EEPROM.timerTimes[0][2]);
t1offtnv.add(_EEPROM.timerTimes[0][3]);
t2otnv.add(_EEPROM.timerTimes[1][2]);
t2offtnv.add(_EEPROM.timerTimes[1][3]);
t3otnv.add(_EEPROM.timerTimes[2][2]);
t3offtnv.add(_EEPROM.timerTimes[2][3]);
t4otnv.add(_EEPROM.timerTimes[3][2]);
t4offtnv.add(_EEPROM.timerTimes[3][3]);
char JSON[600];
serializeJson(doc, JSON);
server.send(200, "text/plane", JSON);
}
void handlegettmjson3() {
// yield();
DynamicJsonDocument doc(500);
JsonArray labelt1 = doc.createNestedArray("labelt1");
JsonArray labelt2 = doc.createNestedArray("labelt2");
JsonArray labelt3 = doc.createNestedArray("labelt3");
JsonArray labelt4 = doc.createNestedArray("labelt4");
JsonArray labelt5 = doc.createNestedArray("labelt5");
JsonArray labelt6 = doc.createNestedArray("labelt6");
labelt1.add(_EEPROM.label[0]);
labelt2.add(_EEPROM.label[1]);
labelt3.add(_EEPROM.label[2]);
labelt4.add(_EEPROM.label[3]);
labelt5.add(_EEPROM.label[4]);
labelt6.add(_EEPROM.label[5]);
char JSON[500];
serializeJson(doc, JSON);
server.send(200, "text/plane", JSON);
}
void handlegettmjson4() {
// yield();
DynamicJsonDocument doc(400);
JsonArray cleanondurationv = doc.createNestedArray("cleanondurationv");
JsonArray cleanoffdurationv = doc.createNestedArray("cleanoffdurationv");
JsonArray disinfectdurationv = doc.createNestedArray("disinfectdurationv");
JsonArray var3 = doc.createNestedArray("datetime");
JsonArray t5otnv = doc.createNestedArray("t5otnv");
JsonArray t5offtnv = doc.createNestedArray("t5offtnv");
JsonArray t5otdv = doc.createNestedArray("t5otdv");
JsonArray t5offtdv = doc.createNestedArray("t5offtdv");
var3.add(str);
cleanondurationv.add(_EEPROM.cleanOnTime);
cleanoffdurationv.add(_EEPROM.cleanOffTime);
disinfectdurationv.add(_EEPROM.cleanDisinfectTime);
t5otnv.add(_EEPROM.timerTimes[4][2]);
t5offtnv.add(_EEPROM.timerTimes[4][3]);
t5otdv.add(_EEPROM.timerTimes[4][0]);
t5offtdv.add(_EEPROM.timerTimes[4][1]);
char JSON[400];
serializeJson(doc, JSON);
server.send(200, "text/plane", JSON);
}