Browse Source

print values

lightsleep
Hendrik Langer 7 years ago
parent
commit
d921a9b5fb
  1. 21
      src/main.cpp

21
src/main.cpp

@ -90,23 +90,33 @@ void ICACHE_FLASH_ATTR sendValues() {
float p10, p2_5; float p10, p2_5;
int sds_error = sds.read(&p2_5, &p10); int sds_error = sds.read(&p2_5, &p10);
if(!sds_error) { if(!sds_error) {
Serial.println("SDS011 updated."); // Serial.println("SDS011 updated.");
} else { } else {
Serial.println("SDS011 no new values."); // Serial.println("SDS011 no new values.");
} }
// sds.sleep(); // sds.sleep();
unsigned long cpm = 0; unsigned long cpm = 0;
float radiationValue = -1;
if (millis() - geiger_previousMillis > logging_period_ms) { if (millis() - geiger_previousMillis > logging_period_ms) {
cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis); cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis);
geiger_previousMillis = millis(); geiger_previousMillis = millis();
geiger_counts = 0; geiger_counts = 0;
Serial.println(cpm); radiationValue = cpm * CONV_FACTOR;
// Serial.println(cpm);
} else { } else {
Serial.println("Geiger Counter: no new value"); // Serial.println("Geiger Counter: no new value");
} }
Serial.printf("Temperature : %6.2f°C (DHT22)\n", temperature);
Serial.printf("Humidity : %6.2f% (DHT22)\n", humidity);
Serial.printf("Temperature : %6.2f°C (BMP180)\n", temp2);
Serial.printf("Pressure : %6.2fhPa (BMP180)\n", pressure);
if (!sds_error) Serial.printf("Particles 10 : %6.2fµg/m³ (SDS011)\n", p10);
if (!sds_error) Serial.printf("Particles 2.5: %6.2fµg/m³ (SDS011)\n", p2_5);
if (cpm > 0) Serial.printf("Radiation : %6.2fµSv/h (J305)\n", radiationValue);
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
JsonArray& array = jsonBuffer.createArray(); JsonArray& array = jsonBuffer.createArray();
@ -134,7 +144,6 @@ void ICACHE_FLASH_ATTR sendValues() {
} }
if (cpm > 0) { if (cpm > 0) {
float radiationValue = cpm * CONV_FACTOR;
JsonObject& cpmObject = array.createNestedObject(); JsonObject& cpmObject = array.createNestedObject();
cpmObject["sensor"] = SENSOR6_ID; cpmObject["sensor"] = SENSOR6_ID;
cpmObject["value"] = radiationValue; cpmObject["value"] = radiationValue;
@ -152,7 +161,6 @@ void ICACHE_FLASH_ATTR sendValues() {
char buffer[500]; char buffer[500];
array.printTo(buffer, sizeof(buffer)); array.printTo(buffer, sizeof(buffer));
HTTPClient httpclient; HTTPClient httpclient;
char url[100]; char url[100];
sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID); sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID);
@ -165,6 +173,7 @@ void ICACHE_FLASH_ATTR sendValues() {
if (httpCode > 0) { if (httpCode > 0) {
if (httpCode == HTTP_CODE_CREATED) { if (httpCode == HTTP_CODE_CREATED) {
httpclient.writeToStream(&Serial); httpclient.writeToStream(&Serial);
Serial.println();
} else { } else {
Serial.printf("[HTTP] POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str()); Serial.printf("[HTTP] POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str());
} }

Loading…
Cancel
Save