diff --git a/lib/patrix/log.cpp b/lib/patrix/log.cpp index 92afb36..df05383 100644 --- a/lib/patrix/log.cpp +++ b/lib/patrix/log.cpp @@ -6,10 +6,10 @@ bool debugEnabled = DEBUG_LOG; void log(const char *level, const char *format, va_list vl) { - char datetime[26]; + char datetime[26] = ""; getDateTime(datetime, sizeof datetime); - char header[20]; + char header[20] = ""; snprintf(header, sizeof header, " | %-5s | ", level); char message[500]; diff --git a/lib/patrix/mqtt.cpp b/lib/patrix/mqtt.cpp index 9eb41f7..66b4a1b 100644 --- a/lib/patrix/mqtt.cpp +++ b/lib/patrix/mqtt.cpp @@ -41,6 +41,8 @@ void mqttDisconnect() { void mqttLoop() { const bool connected = mqtt.loop(); + yield(); + if (mqttConnected != connected) { if (!connected) { error("MQTT DISCONNECTED"); @@ -84,16 +86,19 @@ void mqttPublishLog(const char *datetime, const char *header, const char *messag mqtt.print(header); mqtt.print(message); mqtt.endPublish(); + yield(); } } bool mqttPublishData(const char *name, const JsonDocument &doc) { - if (mqtt.connected() != 0) { + if (mqtt.connected()) { char topic[128]; snprintf(topic, sizeof topic, TOPIC_DATA_FORMAT, HOSTNAME, name); char payload[512]; const size_t size = serializeJson(doc, payload); - return mqtt.publish(topic, payload, size); + boolean result = mqtt.publish(topic, payload, size); + yield(); + return result; } return false; } diff --git a/lib/patrix/sensors/Dallas.h b/lib/patrix/sensors/Dallas.h index b45797d..91d95d4 100644 --- a/lib/patrix/sensors/Dallas.h +++ b/lib/patrix/sensors/Dallas.h @@ -43,7 +43,7 @@ public: void loop() { if (converting) { if (sensors.isConversionComplete()) { - if (first || isDebugEnabled()) { + if (first) { first = false; uint8_t count = sensors.getDeviceCount(); if (count == 0) { diff --git a/lib/patrix/sensors/DallasSensor.h b/lib/patrix/sensors/DallasSensor.h index d28dc9e..700b5ee 100644 --- a/lib/patrix/sensors/DallasSensor.h +++ b/lib/patrix/sensors/DallasSensor.h @@ -35,8 +35,8 @@ public: DallasSensor(Dallas &sensors, const uint64_t address, const char *name, const double valueThreshold, const time_t timeoutSec, const time_t minIntervalSec) : sensors(sensors), - name(name), address(address), + name(name), valueThreshold(valueThreshold), timeoutSec(timeoutSec), minIntervalSec(minIntervalSec) { diff --git a/lib/patrix/wifi.cpp b/lib/patrix/wifi.cpp index 4a3a76b..27b2f50 100644 --- a/lib/patrix/wifi.cpp +++ b/lib/patrix/wifi.cpp @@ -54,6 +54,7 @@ void wifiConnect() { otaInitialized = false; } mqttDisconnect(); + yield(); WiFi.disconnect(); WiFi.enableAP(false); @@ -119,21 +120,27 @@ void otaSetup() { }); } +void bootDelayLoop() { + // TODO merge this into Arduino:loop + consoleLoop(); + wifiLoop(); + yield(); + wdt_reset(); +} + void bootDelay() { #if !BOOT_DELAY return; #endif info("BOOT DELAY: Waiting for WiFi..."); while ((uint32_t) WiFi.localIP() == 0) { - consoleLoop(); - wifiLoop(); + bootDelayLoop(); } info("BOOT DELAY: WiFi connected!"); info("BOOT DELAY: Waiting 10 seconds..."); unsigned long bootDelayBegin = millis(); while (millis() - bootDelayBegin < BOOT_DELAY_MS) { - consoleLoop(); - wifiLoop(); + bootDelayLoop(); } info("BOOT DELAY: Complete!"); info("BOOT DELAY: Resuming normal boot!"); diff --git a/src/Fermenter.cpp b/src/Fermenter.cpp index 64b2c39..1530bbe 100644 --- a/src/Fermenter.cpp +++ b/src/Fermenter.cpp @@ -11,7 +11,7 @@ Dallas dallas(SENSOR_GPIO); -DallasSensor sensor(dallas, 0xAA0121125E4A7528, "sensor", 0.5, 5, 60); +DallasSensor sensor(dallas, 0x3D0417C1D740FF28, "sensor", 0.5, 5, 60); ArduPID pid; @@ -61,7 +61,7 @@ void patrixLoop() { unsigned long now = millis(); if (now - lastDebug >= 1000) { lastDebug = now; - debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | pwm: %3d%%", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPWM); + debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | pwm: %f", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPWM); if (emergencyCutOff) { error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget); }