Use real data for the diagram
This commit is contained in:
parent
ca8da3c608
commit
2efa4a576c
34
src/main.cpp
34
src/main.cpp
@ -97,7 +97,7 @@ typedef struct s_point {
|
|||||||
long timestamp;
|
long timestamp;
|
||||||
float temp;
|
float temp;
|
||||||
#ifdef BME680
|
#ifdef BME680
|
||||||
uint32_t gas_resistance;
|
uint32_t gas;
|
||||||
float humidity;
|
float humidity;
|
||||||
#endif
|
#endif
|
||||||
float pressure;
|
float pressure;
|
||||||
@ -325,16 +325,19 @@ String sensorAsJSON(void) {
|
|||||||
String buffer;
|
String buffer;
|
||||||
StaticJsonDocument<500> doc;
|
StaticJsonDocument<500> doc;
|
||||||
|
|
||||||
doc["temp"] = String(bmx.readTemperature());
|
if (mMeasureIndex > 0) {
|
||||||
|
int lastIdx = mMeasureIndex - 1;
|
||||||
|
doc["temp"] = String(mMeasureSeries[lastIdx].temp);
|
||||||
#ifdef BME680
|
#ifdef BME680
|
||||||
doc["gas"] = String((bmx.gas_resistance / 1000.0));
|
doc["gas"] = String(mMeasureSeries[lastIdx].gas);
|
||||||
doc["humidity"] = String(bmx.humidity);
|
doc["humidity"] = String(mMeasureSeries[lastIdx].humidity);
|
||||||
#endif
|
#endif
|
||||||
float atmospheric = bmx.readPressure() / 100.0F;
|
float atmospheric = mMeasureSeries[lastIdx].pressure;
|
||||||
float altitude = 44330.0 * (1.0 - pow(atmospheric / SEALEVELPRESSURE_HPA, 0.1903));
|
float altitude = 44330.0 * (1.0 - pow(atmospheric / SEALEVELPRESSURE_HPA, 0.1903));
|
||||||
doc["altitude"] = String(altitude);
|
doc["altitude"] = String(altitude);
|
||||||
doc["pressure"] = String(atmospheric);
|
doc["pressure"] = String(atmospheric);
|
||||||
doc["particle"] = String(mParticle_pM25);
|
doc["particle"] = String(mMeasureSeries[lastIdx].pm25);
|
||||||
|
}
|
||||||
doc["cycle"] = String(mMeasureIndex);
|
doc["cycle"] = String(mMeasureIndex);
|
||||||
serializeJson(doc, buffer);
|
serializeJson(doc, buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
@ -406,6 +409,7 @@ String diagramJson(void) {
|
|||||||
bufferLabels += "\", \"" + String((now - mMeasureSeries[i].timestamp) / 1000) + "s";
|
bufferLabels += "\", \"" + String((now - mMeasureSeries[i].timestamp) / 1000) + "s";
|
||||||
bufferDataTemp += "\", \"" + String(mMeasureSeries[i].temp);
|
bufferDataTemp += "\", \"" + String(mMeasureSeries[i].temp);
|
||||||
bufferDataPressure += "\", \"" + String(mMeasureSeries[i].pressure);
|
bufferDataPressure += "\", \"" + String(mMeasureSeries[i].pressure);
|
||||||
|
/* float altitude = 44330.0 * (1.0 - pow(atmospheric / SEALEVELPRESSURE_HPA, 0.1903)); */
|
||||||
}
|
}
|
||||||
if (mMeasureIndex > 0) {
|
if (mMeasureIndex > 0) {
|
||||||
bufferLabels += "\" ]";
|
bufferLabels += "\" ]";
|
||||||
@ -424,6 +428,7 @@ String diagramJson(void) {
|
|||||||
buffer += "{\n \"label\" : \"Pressure\",\n \"data\" : " + bufferDataPressure + ",\n \"borderColor\" : \"rgba(0,0,255,1)\" \n}";
|
buffer += "{\n \"label\" : \"Pressure\",\n \"data\" : " + bufferDataPressure + ",\n \"borderColor\" : \"rgba(0,0,255,1)\" \n}";
|
||||||
/* TODO, next ones ... */
|
/* TODO, next ones ... */
|
||||||
|
|
||||||
|
|
||||||
buffer += "]\n }";
|
buffer += "]\n }";
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -471,9 +476,14 @@ void loopHandler()
|
|||||||
// FIXME: add the measured data into the big list
|
// FIXME: add the measured data into the big list
|
||||||
if (mMeasureSeries != NULL) {
|
if (mMeasureSeries != NULL) {
|
||||||
mMeasureSeries[mMeasureIndex].timestamp = millis();
|
mMeasureSeries[mMeasureIndex].timestamp = millis();
|
||||||
mMeasureSeries[mMeasureIndex].pm25 = millis() / 100; /* Dummy */
|
mMeasureSeries[mMeasureIndex].temp = bmx.readTemperature();
|
||||||
mMeasureSeries[mMeasureIndex].temp = random(10,30) * 1.0f; /* Dummy */
|
#ifdef BME680
|
||||||
mMeasureSeries[mMeasureIndex].pressure = random(900,1050) * 1.0f; /* Dummy */
|
mMeasureSeries[mMeasureIndex].gas = (bmx.gas_resistance / 1000.0);
|
||||||
|
mMeasureSeries[mMeasureIndex].humidity = bmx.humidity;
|
||||||
|
#endif
|
||||||
|
float atmospheric = bmx.readPressure() / 100.0F;
|
||||||
|
mMeasureSeries[mMeasureIndex].pressure = atmospheric;
|
||||||
|
mMeasureSeries[mMeasureIndex].pm25 = mParticle_pM25;
|
||||||
mMeasureIndex++;
|
mMeasureIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user