ESP8266 yield yield yield (!!!)
This commit is contained in:
parent
917450676b
commit
352b3ed89f
@ -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];
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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!");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user