mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
optimization for esp8266
This commit is contained in:
@@ -70,37 +70,52 @@ protected:
|
||||
Log.sinfoln("MQTT", F("Started"));
|
||||
|
||||
// wificlient settings
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
this->wifiClient->setSync(true);
|
||||
#endif
|
||||
|
||||
// client settings
|
||||
this->client->setClient(*this->wifiClient);
|
||||
this->client->setSocketTimeout(3);
|
||||
this->client->setKeepAlive(15);
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
this->client->setSocketTimeout(1);
|
||||
this->client->setBufferSize(768);
|
||||
#else
|
||||
this->client->setSocketTimeout(3);
|
||||
this->client->setBufferSize(1536);
|
||||
#endif
|
||||
|
||||
this->client->setCallback([this] (char* topic, uint8_t* payload, unsigned int length) {
|
||||
this->onMessage(topic, payload, length);
|
||||
});
|
||||
|
||||
// writer settings
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
this->writer->setYieldCallback([this] {
|
||||
this->delay(10);
|
||||
});
|
||||
#endif
|
||||
|
||||
this->writer->setEventPublishCallback([this] (const char* topic, size_t written, size_t length, bool result) {
|
||||
Log.straceln("MQTT", F("%s publish %u of %u bytes to topic: %s"), result ? F("Successfully") : F("Failed"), written, length, topic);
|
||||
|
||||
this->client->loop();
|
||||
this->delay(250);
|
||||
});
|
||||
this->writer->setEventFlushCallback([this] (size_t, size_t) {
|
||||
if (!this->wifiClient->getSync() && this->wifiClient->connected()) {
|
||||
this->wifiClient->flush();
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
::yield();
|
||||
#endif
|
||||
|
||||
this->client->loop();
|
||||
this->delay(250);
|
||||
});
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
this->writer->setEventFlushCallback([this] (size_t, size_t) {
|
||||
this->client->flush();
|
||||
this->wifiClient->flush();
|
||||
::yield();
|
||||
});
|
||||
#endif
|
||||
|
||||
// ha helper settings
|
||||
this->haHelper->setDevicePrefix(settings.mqtt.prefix);
|
||||
this->haHelper->setDeviceVersion(PROJECT_VERSION);
|
||||
@@ -117,9 +132,8 @@ protected:
|
||||
this->connected = false;
|
||||
this->onDisconnect();
|
||||
}
|
||||
|
||||
|
||||
if (this->wifiClient == nullptr || (!this->client->connected() && millis() - this->lastReconnectTime >= MQTT_RECONNECT_INTERVAL)) {
|
||||
Log.sinfoln("MQTT", F("Not connected, state: %d"), this->client->state());
|
||||
Log.sinfoln("MQTT", F("Connecting to %s:%u..."), settings.mqtt.server, settings.mqtt.port);
|
||||
|
||||
this->client->setServer(settings.mqtt.server, settings.mqtt.port);
|
||||
@@ -144,6 +158,9 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
::yield();
|
||||
#endif
|
||||
this->client->loop();
|
||||
|
||||
// delay for publish data
|
||||
@@ -151,6 +168,10 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
::yield();
|
||||
#endif
|
||||
|
||||
// publish variables and status
|
||||
if (this->newConnection || millis() - this->prevPubVarsTime > settings.mqtt.interval) {
|
||||
this->writer->publish(
|
||||
|
||||
@@ -273,6 +273,8 @@ protected:
|
||||
arpGratuitous();
|
||||
lastArpGratuitous = millis();
|
||||
}
|
||||
|
||||
::yield();
|
||||
#endif
|
||||
|
||||
wm.process();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#define PROJECT_NAME "OpenTherm Gateway"
|
||||
#define PROJECT_VERSION "1.4.0-rc.2"
|
||||
#define PROJECT_VERSION "1.4.0-rc.3"
|
||||
#define PROJECT_REPO "https://github.com/Laxilef/OTGateway"
|
||||
#define AP_SSID "OpenTherm Gateway"
|
||||
#define AP_PASSWORD "otgateway123456"
|
||||
|
||||
Reference in New Issue
Block a user