From efde2d3ef96ee317d8c9c20dc65daeeafdb725c3 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 9 Aug 2019 18:24:28 +0200 Subject: [PATCH] replace Serial.print --- src/main.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 179b777..5e0abdc 100644 --- a/src/main.cpp +++ b/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_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); - Serial.println("going to to sleep for " + String(sleep_time) + - " Seconds"); + ESP_LOGI(TAG, "going to to sleep for %d seconds", sleep_time); Serial.flush(); esp_deep_sleep_start(); delay(1); @@ -156,7 +155,7 @@ void wifiConnect() { 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 && ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16)) @@ -174,7 +173,7 @@ void wifiConnect() { } else { ESP_LOGD("WiFi", "DHCP"); for (int tries=0; wifiMulti.run() != WL_CONNECTED && tries < 20; tries++) { - Serial.print("."); + ESP_LOGD("WiFi", "."); delay(500); } @@ -283,7 +282,7 @@ void getSensorMeasurements() { ESP_LOGI(TAG, "Humidity : %8.2f %", sensor_readings.humidity); ESP_LOGI(TAG, "VOC : %5lu kOhm", sensor_readings.voc); } 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(); // auto-adjust sensitivity 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) { 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) { 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) 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); @@ -657,7 +656,7 @@ void setup() esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); ++bootCount; - Serial.println("Boot number: " + String(bootCount)); + ESP_LOGI(TAG, "Boot number: %d", bootCount); Serial.println("millis(): " + String(millis())); ESP_LOGD(TAG, "setup hardware and sensors"); @@ -712,7 +711,7 @@ void setup() 2.95, 1.74, // UVB_C and UVB_D coefficients 0.001461, 0.002591); // UVA and UVB responses } 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())); @@ -720,7 +719,7 @@ void setup() if (lightMeter.begin()) { sensors_active.light = true; } 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())); @@ -737,7 +736,7 @@ void setup() sds.setActiveReportingMode(); // ensures sensor is in 'active' reporting mode sds.setCustomWorkingPeriod(5); // sensor sends data every 3 minutes } 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 */ if (getTimestamp() - lastDisplayRefresh >= 60*60) { - Serial.printf("last display refresh :%ds ago", getTimestamp() - lastDisplayRefresh); lastDisplayRefresh = getTimestamp(); display.clearScreen(); display.refresh();