mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
scheduler/mqtt running assync with psram, sync without psram
This commit is contained in:
@@ -41,8 +41,12 @@ void MqttSettingsService::startClient() {
|
|||||||
}
|
}
|
||||||
#ifndef TASMOTA_SDK
|
#ifndef TASMOTA_SDK
|
||||||
if (_state.enableTLS) {
|
if (_state.enableTLS) {
|
||||||
isSecure = true;
|
isSecure = true;
|
||||||
_mqttClient = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO);
|
if (emsesp::EMSESP::system_.PSram() > 0) {
|
||||||
|
_mqttClient = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::YES);
|
||||||
|
} else {
|
||||||
|
_mqttClient = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO);
|
||||||
|
}
|
||||||
if (_state.rootCA == "insecure") {
|
if (_state.rootCA == "insecure") {
|
||||||
static_cast<espMqttClientSecure *>(_mqttClient)->setInsecure();
|
static_cast<espMqttClientSecure *>(_mqttClient)->setInsecure();
|
||||||
} else {
|
} else {
|
||||||
@@ -59,8 +63,12 @@ void MqttSettingsService::startClient() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
isSecure = false;
|
isSecure = false;
|
||||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
if (emsesp::EMSESP::system_.PSram() > 0) {
|
||||||
|
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::YES);
|
||||||
|
} else {
|
||||||
|
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||||
|
}
|
||||||
static_cast<espMqttClient *>(_mqttClient)->onConnect([this](bool sessionPresent) { onMqttConnect(sessionPresent); });
|
static_cast<espMqttClient *>(_mqttClient)->onConnect([this](bool sessionPresent) { onMqttConnect(sessionPresent); });
|
||||||
static_cast<espMqttClient *>(_mqttClient)->onDisconnect([this](espMqttClientTypes::DisconnectReason reason) { onMqttDisconnect(reason); });
|
static_cast<espMqttClient *>(_mqttClient)->onDisconnect([this](espMqttClientTypes::DisconnectReason reason) { onMqttDisconnect(reason); });
|
||||||
static_cast<espMqttClient *>(_mqttClient)
|
static_cast<espMqttClient *>(_mqttClient)
|
||||||
@@ -76,7 +84,9 @@ void MqttSettingsService::loop() {
|
|||||||
_disconnectedAt = configureMqtt() ? 0 : uuid::get_uptime();
|
_disconnectedAt = configureMqtt() ? 0 : uuid::get_uptime();
|
||||||
_reconfigureMqtt = false;
|
_reconfigureMqtt = false;
|
||||||
}
|
}
|
||||||
_mqttClient->loop();
|
if (emsesp::EMSESP::system_.PSram() == 0) {
|
||||||
|
_mqttClient->loop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MqttSettingsService::isEnabled() {
|
bool MqttSettingsService::isEnabled() {
|
||||||
|
|||||||
@@ -1538,6 +1538,7 @@ EMSESP::EMSESP()
|
|||||||
// start all the core services
|
// start all the core services
|
||||||
// the services must be loaded in the correct order
|
// the services must be loaded in the correct order
|
||||||
void EMSESP::start() {
|
void EMSESP::start() {
|
||||||
|
system_.PSram(ESP.getPsramSize());
|
||||||
// don't need shell if running unit tests
|
// don't need shell if running unit tests
|
||||||
#ifndef EMSESP_UNITY
|
#ifndef EMSESP_UNITY
|
||||||
// Serial console's shell
|
// Serial console's shell
|
||||||
@@ -1669,6 +1670,9 @@ void EMSESP::loop() {
|
|||||||
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
|
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
|
||||||
mqtt_.loop(); // sends out anything in the MQTT queue
|
mqtt_.loop(); // sends out anything in the MQTT queue
|
||||||
webModulesService.loop(); // loop through the external library modules
|
webModulesService.loop(); // loop through the external library modules
|
||||||
|
if (system_.PSram() == 0) {
|
||||||
|
webSchedulerService.loop();
|
||||||
|
}
|
||||||
|
|
||||||
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
||||||
scheduled_fetch_values();
|
scheduled_fetch_values();
|
||||||
|
|||||||
@@ -485,7 +485,6 @@ void System::start() {
|
|||||||
|
|
||||||
// get current memory values
|
// get current memory values
|
||||||
fstotal_ = LittleFS.totalBytes() / 1024; // read only once, it takes 500 ms to read
|
fstotal_ = LittleFS.totalBytes() / 1024; // read only once, it takes 500 ms to read
|
||||||
psram_ = ESP.getPsramSize() / 1024;
|
|
||||||
appused_ = ESP.getSketchSize() / 1024;
|
appused_ = ESP.getSketchSize() / 1024;
|
||||||
appfree_ = esp_ota_get_running_partition()->size / 1024 - appused_;
|
appfree_ = esp_ota_get_running_partition()->size / 1024 - appused_;
|
||||||
refreshHeapMem(); // refresh free heap and max alloc heap
|
refreshHeapMem(); // refresh free heap and max alloc heap
|
||||||
|
|||||||
@@ -246,6 +246,10 @@ class System {
|
|||||||
uint32_t FStotal() {
|
uint32_t FStotal() {
|
||||||
return fstotal_;
|
return fstotal_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PSram(uint32_t psram) {
|
||||||
|
psram_ = psram / 1024;
|
||||||
|
}
|
||||||
uint32_t PSram() {
|
uint32_t PSram() {
|
||||||
return psram_;
|
return psram_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ void WebSchedulerService::begin() {
|
|||||||
snprintf(topic, sizeof(topic), "%s/#", F_(scheduler));
|
snprintf(topic, sizeof(topic), "%s/#", F_(scheduler));
|
||||||
Mqtt::subscribe(EMSdevice::DeviceType::SCHEDULER, topic, nullptr); // use empty function callback
|
Mqtt::subscribe(EMSdevice::DeviceType::SCHEDULER, topic, nullptr); // use empty function callback
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
xTaskCreate((TaskFunction_t)scheduler_task, "scheduler_task", 4096, NULL, 1, NULL);
|
if (EMSESP::system_.PSram()) {
|
||||||
|
xTaskCreate((TaskFunction_t)scheduler_task, "scheduler_task", 4096, NULL, 1, NULL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user