ESP8266 yield yield yield (!!!)
This commit is contained in:
parent
917450676b
commit
352b3ed89f
@ -6,10 +6,10 @@
|
|||||||
bool debugEnabled = DEBUG_LOG;
|
bool debugEnabled = DEBUG_LOG;
|
||||||
|
|
||||||
void log(const char *level, const char *format, va_list vl) {
|
void log(const char *level, const char *format, va_list vl) {
|
||||||
char datetime[26];
|
char datetime[26] = "";
|
||||||
getDateTime(datetime, sizeof datetime);
|
getDateTime(datetime, sizeof datetime);
|
||||||
|
|
||||||
char header[20];
|
char header[20] = "";
|
||||||
snprintf(header, sizeof header, " | %-5s | ", level);
|
snprintf(header, sizeof header, " | %-5s | ", level);
|
||||||
|
|
||||||
char message[500];
|
char message[500];
|
||||||
|
|||||||
@ -41,6 +41,8 @@ void mqttDisconnect() {
|
|||||||
|
|
||||||
void mqttLoop() {
|
void mqttLoop() {
|
||||||
const bool connected = mqtt.loop();
|
const bool connected = mqtt.loop();
|
||||||
|
yield();
|
||||||
|
|
||||||
if (mqttConnected != connected) {
|
if (mqttConnected != connected) {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
error("MQTT DISCONNECTED");
|
error("MQTT DISCONNECTED");
|
||||||
@ -84,16 +86,19 @@ void mqttPublishLog(const char *datetime, const char *header, const char *messag
|
|||||||
mqtt.print(header);
|
mqtt.print(header);
|
||||||
mqtt.print(message);
|
mqtt.print(message);
|
||||||
mqtt.endPublish();
|
mqtt.endPublish();
|
||||||
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mqttPublishData(const char *name, const JsonDocument &doc) {
|
bool mqttPublishData(const char *name, const JsonDocument &doc) {
|
||||||
if (mqtt.connected() != 0) {
|
if (mqtt.connected()) {
|
||||||
char topic[128];
|
char topic[128];
|
||||||
snprintf(topic, sizeof topic, TOPIC_DATA_FORMAT, HOSTNAME, name);
|
snprintf(topic, sizeof topic, TOPIC_DATA_FORMAT, HOSTNAME, name);
|
||||||
char payload[512];
|
char payload[512];
|
||||||
const size_t size = serializeJson(doc, payload);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public:
|
|||||||
void loop() {
|
void loop() {
|
||||||
if (converting) {
|
if (converting) {
|
||||||
if (sensors.isConversionComplete()) {
|
if (sensors.isConversionComplete()) {
|
||||||
if (first || isDebugEnabled()) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
uint8_t count = sensors.getDeviceCount();
|
uint8_t count = sensors.getDeviceCount();
|
||||||
if (count == 0) {
|
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) :
|
DallasSensor(Dallas &sensors, const uint64_t address, const char *name, const double valueThreshold, const time_t timeoutSec, const time_t minIntervalSec) :
|
||||||
sensors(sensors),
|
sensors(sensors),
|
||||||
name(name),
|
|
||||||
address(address),
|
address(address),
|
||||||
|
name(name),
|
||||||
valueThreshold(valueThreshold),
|
valueThreshold(valueThreshold),
|
||||||
timeoutSec(timeoutSec),
|
timeoutSec(timeoutSec),
|
||||||
minIntervalSec(minIntervalSec) {
|
minIntervalSec(minIntervalSec) {
|
||||||
|
|||||||
@ -54,6 +54,7 @@ void wifiConnect() {
|
|||||||
otaInitialized = false;
|
otaInitialized = false;
|
||||||
}
|
}
|
||||||
mqttDisconnect();
|
mqttDisconnect();
|
||||||
|
yield();
|
||||||
|
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
WiFi.enableAP(false);
|
WiFi.enableAP(false);
|
||||||
@ -119,21 +120,27 @@ void otaSetup() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bootDelayLoop() {
|
||||||
|
// TODO merge this into Arduino:loop
|
||||||
|
consoleLoop();
|
||||||
|
wifiLoop();
|
||||||
|
yield();
|
||||||
|
wdt_reset();
|
||||||
|
}
|
||||||
|
|
||||||
void bootDelay() {
|
void bootDelay() {
|
||||||
#if !BOOT_DELAY
|
#if !BOOT_DELAY
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
info("BOOT DELAY: Waiting for WiFi...");
|
info("BOOT DELAY: Waiting for WiFi...");
|
||||||
while ((uint32_t) WiFi.localIP() == 0) {
|
while ((uint32_t) WiFi.localIP() == 0) {
|
||||||
consoleLoop();
|
bootDelayLoop();
|
||||||
wifiLoop();
|
|
||||||
}
|
}
|
||||||
info("BOOT DELAY: WiFi connected!");
|
info("BOOT DELAY: WiFi connected!");
|
||||||
info("BOOT DELAY: Waiting 10 seconds...");
|
info("BOOT DELAY: Waiting 10 seconds...");
|
||||||
unsigned long bootDelayBegin = millis();
|
unsigned long bootDelayBegin = millis();
|
||||||
while (millis() - bootDelayBegin < BOOT_DELAY_MS) {
|
while (millis() - bootDelayBegin < BOOT_DELAY_MS) {
|
||||||
consoleLoop();
|
bootDelayLoop();
|
||||||
wifiLoop();
|
|
||||||
}
|
}
|
||||||
info("BOOT DELAY: Complete!");
|
info("BOOT DELAY: Complete!");
|
||||||
info("BOOT DELAY: Resuming normal boot!");
|
info("BOOT DELAY: Resuming normal boot!");
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
Dallas dallas(SENSOR_GPIO);
|
Dallas dallas(SENSOR_GPIO);
|
||||||
|
|
||||||
DallasSensor sensor(dallas, 0xAA0121125E4A7528, "sensor", 0.5, 5, 60);
|
DallasSensor sensor(dallas, 0x3D0417C1D740FF28, "sensor", 0.5, 5, 60);
|
||||||
|
|
||||||
ArduPID pid;
|
ArduPID pid;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ void patrixLoop() {
|
|||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
if (now - lastDebug >= 1000) {
|
if (now - lastDebug >= 1000) {
|
||||||
lastDebug = now;
|
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) {
|
if (emergencyCutOff) {
|
||||||
error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget);
|
error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user