Generate the JSON without any library
This commit is contained in:
parent
3224224251
commit
ae6c53d39b
61
src/main.cpp
61
src/main.cpp
@ -387,45 +387,40 @@ String sensorHeader(void) {
|
|||||||
String diagramJson(void) {
|
String diagramJson(void) {
|
||||||
int i;
|
int i;
|
||||||
String buffer;
|
String buffer;
|
||||||
String bufferLabels;
|
String bufferLabels = "\"\"";
|
||||||
String bufferDataContent;
|
String bufferDataTemp = "\"\"";
|
||||||
String bufferData;
|
String bufferDataPressure = "\"\"";
|
||||||
String bufferDatasets;
|
String bufferDatasets;
|
||||||
|
String bufferData;
|
||||||
long now = millis();
|
long now = millis();
|
||||||
StaticJsonDocument<500> doc;
|
if (mMeasureIndex > 0) {
|
||||||
StaticJsonDocument<500> docLabels;
|
bufferLabels = "[ \"" + String((now - mMeasureSeries[0].timestamp) / 1000) + "s";
|
||||||
StaticJsonDocument<500> docDataset;
|
bufferDataTemp = "[ \"" + String(mMeasureSeries[0].temp);
|
||||||
StaticJsonDocument<500> docDatasets;
|
bufferDataPressure = "[ \"" + String(mMeasureSeries[0].pressure);
|
||||||
StaticJsonDocument<500> docDataTemp;
|
|
||||||
StaticJsonDocument<500> docDataPressure;
|
|
||||||
for(i=0; i < mMeasureIndex; i++) {
|
|
||||||
docLabels.add(String(String((now - mMeasureSeries[i].timestamp) / 1000) + String("s")));
|
|
||||||
docDataTemp.add(String(mMeasureSeries[i].temp));
|
|
||||||
docDataPressure.add(String(mMeasureSeries[i].pressure));
|
|
||||||
}
|
}
|
||||||
serializeJson(docLabels, bufferLabels);
|
for(i=1; i < mMeasureIndex; i++) {
|
||||||
|
bufferLabels += "\", \"" + String((now - mMeasureSeries[i].timestamp) / 1000) + "s";
|
||||||
|
bufferDataTemp += "\", \"" + String(mMeasureSeries[i].temp);
|
||||||
|
bufferDataPressure += "\", \"" + String(mMeasureSeries[i].pressure);
|
||||||
|
}
|
||||||
|
if (mMeasureIndex > 0) {
|
||||||
|
bufferLabels += "\" ]";
|
||||||
|
bufferDataTemp += "\" ]";
|
||||||
|
bufferDataPressure += "\" ]";
|
||||||
|
}
|
||||||
|
/* Generate label */
|
||||||
|
buffer = "{ \"labels\" : " + bufferLabels + ",\n";
|
||||||
|
buffer += "\"datasets\" : [";
|
||||||
|
|
||||||
/* generate first block for Temperature */
|
/* generate first block for Temperature */
|
||||||
docDataset.clear();
|
buffer += "{\n \"label\" : \"Temp\",\n \"data\" : " + bufferDataTemp + ",\n \"borderColor\" : \"rgba(255,0,0,1)\" \n}";
|
||||||
docDataset["label"] = "Temp";
|
|
||||||
serializeJson(docDataTemp, bufferDataContent);
|
|
||||||
docDataset["data"] = bufferDataContent;
|
|
||||||
docDataset["borderColor"] = "rgba(255,0,0,1)";
|
|
||||||
serializeJson(docDataset, bufferData);
|
|
||||||
docDatasets.add(bufferData);
|
|
||||||
/* generate second block for Pressure */
|
/* generate second block for Pressure */
|
||||||
docDataset.clear();
|
buffer += ", ";
|
||||||
docDataset["label"] = "Pressure";
|
buffer += "{\n \"label\" : \"Pressure\",\n \"data\" : " + bufferDataPressure + ",\n \"borderColor\" : \"rgba(0,0,255,1)\" \n}";
|
||||||
serializeJson(docDataPressure, bufferDataContent);
|
/* TODO, next ones ... */
|
||||||
docDataset["data"] = bufferDataContent;
|
|
||||||
docDataset["borderColor"] = "rgba(0,0,255,1)";
|
|
||||||
serializeJson(docDataset, bufferData);
|
|
||||||
docDatasets.add(bufferData);
|
|
||||||
|
|
||||||
|
buffer += "]\n }";
|
||||||
serializeJson(docDatasets, bufferDatasets);
|
|
||||||
doc["labels"] = bufferLabels;
|
|
||||||
doc["datasets"] = bufferDatasets;
|
|
||||||
serializeJson(doc, buffer);
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user