Browse Source

replace Serial.print

main
Hendrik Langer 5 years ago
parent
commit
efde2d3ef9
  1. 26
      src/main.cpp

26
src/main.cpp

@ -134,8 +134,7 @@ void gotoSleep(unsigned int sleep_time = TIME_TO_SLEEP) {
esp_sleep_enable_timer_wakeup(sleep_time * 1000000LL); esp_sleep_enable_timer_wakeup(sleep_time * 1000000LL);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
Serial.println("going to to sleep for " + String(sleep_time) + ESP_LOGI(TAG, "going to to sleep for %d seconds", sleep_time);
" Seconds");
Serial.flush(); Serial.flush();
esp_deep_sleep_start(); esp_deep_sleep_start();
delay(1); delay(1);
@ -156,7 +155,7 @@ void wifiConnect() {
Serial.println("millis(): " + String(millis())); Serial.println("millis(): " + String(millis()));
Serial.println("previous dhcp: " + String(getTimestamp() - network.last_dhcp) + "s ago"); ESP_LOGD(TAG, "previous dhcp: %lu s ago", getTimestamp() - network.last_dhcp);
if ( ip != INADDR_NONE && dns != INADDR_NONE && gateway != INADDR_NONE && subnet != INADDR_NONE if ( ip != INADDR_NONE && dns != INADDR_NONE && gateway != INADDR_NONE && subnet != INADDR_NONE
&& ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16)) && ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16))
@ -174,7 +173,7 @@ void wifiConnect() {
} else { } else {
ESP_LOGD("WiFi", "DHCP"); ESP_LOGD("WiFi", "DHCP");
for (int tries=0; wifiMulti.run() != WL_CONNECTED && tries < 20; tries++) { for (int tries=0; wifiMulti.run() != WL_CONNECTED && tries < 20; tries++) {
Serial.print("."); ESP_LOGD("WiFi", ".");
delay(500); delay(500);
} }
@ -283,7 +282,7 @@ void getSensorMeasurements() {
ESP_LOGI(TAG, "Humidity : %8.2f %", sensor_readings.humidity); ESP_LOGI(TAG, "Humidity : %8.2f %", sensor_readings.humidity);
ESP_LOGI(TAG, "VOC : %5lu kOhm", sensor_readings.voc); ESP_LOGI(TAG, "VOC : %5lu kOhm", sensor_readings.voc);
} else { } else {
Serial.println("Failed to perform reading :("); ESP_LOGE(TAG, "Failed to perform BME680 reading :(");
} }
} }
@ -318,18 +317,18 @@ void getSensorMeasurements() {
sensor_readings.lux = lightMeter.readLightLevel(); sensor_readings.lux = lightMeter.readLightLevel();
// auto-adjust sensitivity // auto-adjust sensitivity
if (sensor_readings.lux < 0) { if (sensor_readings.lux < 0) {
Serial.println("Error reading light level"); ESP_LOGE(TAG, "Error reading light level");
} else if (sensor_readings.lux > 40000.0) { } else if (sensor_readings.lux > 40000.0) {
if (lightMeter.setMTreg(32)) { if (lightMeter.setMTreg(32)) {
Serial.println(F("Setting MTReg to low value for high light environment")); ESP_LOGD(TAG, "Setting MTReg to low value for high light environment");
} }
} else if (sensor_readings.lux <= 10.0) { } else if (sensor_readings.lux <= 10.0) {
if (lightMeter.setMTreg(138)) { if (lightMeter.setMTreg(138)) {
Serial.println(F("Setting MTReg to high value for low light environment")); ESP_LOGD(TAG, "Setting MTReg to high value for low light environment");
} }
} else { // if (sensor_readings.lux > 10.0) } else { // if (sensor_readings.lux > 10.0)
if (lightMeter.setMTreg(69)) { if (lightMeter.setMTreg(69)) {
Serial.println(F("Setting MTReg to default value for normal light environment")); ESP_LOGD(TAG, "Setting MTReg to default value for normal light environment");
} }
} }
ESP_LOGI(TAG, "Lux : %8.2f lx", sensor_readings.lux); ESP_LOGI(TAG, "Lux : %8.2f lx", sensor_readings.lux);
@ -657,7 +656,7 @@ void setup()
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
++bootCount; ++bootCount;
Serial.println("Boot number: " + String(bootCount)); ESP_LOGI(TAG, "Boot number: %d", bootCount);
Serial.println("millis(): " + String(millis())); Serial.println("millis(): " + String(millis()));
ESP_LOGD(TAG, "setup hardware and sensors"); ESP_LOGD(TAG, "setup hardware and sensors");
@ -712,7 +711,7 @@ void setup()
2.95, 1.74, // UVB_C and UVB_D coefficients 2.95, 1.74, // UVB_C and UVB_D coefficients
0.001461, 0.002591); // UVA and UVB responses 0.001461, 0.002591); // UVA and UVB responses
} else { } else {
Serial.println("Failed to communicate with VEML6075 sensor, check wiring?"); ESP_LOGW(TAG, "Failed to communicate with VEML6075 sensor, check wiring?");
} }
Serial.println("millis(): " + String(millis())); Serial.println("millis(): " + String(millis()));
@ -720,7 +719,7 @@ void setup()
if (lightMeter.begin()) { if (lightMeter.begin()) {
sensors_active.light = true; sensors_active.light = true;
} else { } else {
Serial.println("Failed to communicate with BH1750 sensor, check wiring?"); ESP_LOGW(TAG, "Failed to communicate with BH1750 sensor, check wiring?");
} }
Serial.println("millis(): " + String(millis())); Serial.println("millis(): " + String(millis()));
@ -737,7 +736,7 @@ void setup()
sds.setActiveReportingMode(); // ensures sensor is in 'active' reporting mode sds.setActiveReportingMode(); // ensures sensor is in 'active' reporting mode
sds.setCustomWorkingPeriod(5); // sensor sends data every 3 minutes sds.setCustomWorkingPeriod(5); // sensor sends data every 3 minutes
} else { } else {
Serial.println("Failed to communicate with SDS011 sensor, check wiring?"); ESP_LOGW(TAG, "Failed to communicate with SDS011 sensor, check wiring?");
} }
} }
@ -817,7 +816,6 @@ void loop()
/* Do a full refresh every hour */ /* Do a full refresh every hour */
if (getTimestamp() - lastDisplayRefresh >= 60*60) { if (getTimestamp() - lastDisplayRefresh >= 60*60) {
Serial.printf("last display refresh :%ds ago", getTimestamp() - lastDisplayRefresh);
lastDisplayRefresh = getTimestamp(); lastDisplayRefresh = getTimestamp();
display.clearScreen(); display.clearScreen();
display.refresh(); display.refresh();

Loading…
Cancel
Save