forked from xiaozhi/xiaozhi-esp32
v2.1.0: Upgrade esp-wifi-connect to 3.0; New device state machine (#1528)
* Upgrade component version * update fonts component version * Handle OTA error code * Update project version to 2.1.0 and add device state machine implementation - Upgrade esp-wifi-connect to 3.0.0, allowing reconfiguring wifi without rebooting - Introduce device state machine with state change notification in new files - Remove obsolete device state event files - Update application logic to utilize new state machine - Minor adjustments in various board implementations for state handling * fix compile errors * Refactor power saving mode implementation to use PowerSaveLevel enumeration - Updated Application class to replace SetPowerSaveMode with SetPowerSaveLevel, allowing for LOW_POWER and PERFORMANCE settings. - Modified various board implementations to align with the new power save level structure. - Ensured consistent handling of power save levels across different board files, enhancing code maintainability and clarity. * Refactor power save level checks across multiple board implementations - Updated the condition for power save level checks in various board files to ensure that the power save timer only wakes up when the level is not set to LOW_POWER. - Improved consistency in handling power save levels, enhancing code clarity and maintainability. * Refactor EnterWifiConfigMode calls in board implementations - Updated calls to EnterWifiConfigMode to use the appropriate instance reference (self or board) across multiple board files. - Improved code consistency and clarity in handling device state during WiFi configuration mode entry. * Add cellular modem event handling and improve network status updates - Introduced new network events for cellular modem operations, including detecting, registration errors, and timeouts. - Enhanced the Application class to handle different network states and update the display status accordingly. - Refactored Ml307Board to implement a callback mechanism for network events, improving modularity and responsiveness. - Updated dual_network_board and board headers to support new network event callbacks, ensuring consistent handling across board implementations. * update esp-wifi-connect version * Update WiFi configuration tool messages across multiple board implementations to clarify user actions
This commit is contained in:
@@ -20,8 +20,11 @@ MqttProtocol::MqttProtocol() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateIdle) {
|
||||
ESP_LOGI(TAG, "Reconnecting to MQTT server");
|
||||
app.Schedule([protocol]() {
|
||||
protocol->StartMqttClient(false);
|
||||
auto alive = protocol->alive_; // Capture alive flag
|
||||
app.Schedule([protocol, alive]() {
|
||||
if (*alive) {
|
||||
protocol->StartMqttClient(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -32,6 +35,10 @@ MqttProtocol::MqttProtocol() {
|
||||
|
||||
MqttProtocol::~MqttProtocol() {
|
||||
ESP_LOGI(TAG, "MqttProtocol deinit");
|
||||
|
||||
// Mark as dead first to prevent any pending scheduled tasks from executing
|
||||
*alive_ = false;
|
||||
|
||||
if (reconnect_timer_ != nullptr) {
|
||||
esp_timer_stop(reconnect_timer_);
|
||||
esp_timer_delete(reconnect_timer_);
|
||||
@@ -109,8 +116,11 @@ bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
auto session_id = cJSON_GetObjectItem(root, "session_id");
|
||||
ESP_LOGI(TAG, "Received goodbye message, session_id: %s", session_id ? session_id->valuestring : "null");
|
||||
if (session_id == nullptr || session_id_ == session_id->valuestring) {
|
||||
Application::GetInstance().Schedule([this]() {
|
||||
CloseAudioChannel();
|
||||
auto alive = alive_; // Capture alive flag
|
||||
Application::GetInstance().Schedule([this, alive]() {
|
||||
if (*alive) {
|
||||
CloseAudioChannel();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (on_incoming_json_ != nullptr) {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
|
||||
#define MQTT_PING_INTERVAL_SECONDS 90
|
||||
#define MQTT_RECONNECT_INTERVAL_MS 60000
|
||||
@@ -33,6 +35,9 @@ public:
|
||||
bool IsAudioChannelOpened() const override;
|
||||
|
||||
private:
|
||||
// Alive flag for safe scheduled callbacks - set to false in destructor
|
||||
std::shared_ptr<std::atomic<bool>> alive_ = std::make_shared<std::atomic<bool>>(true);
|
||||
|
||||
EventGroupHandle_t event_group_handle_;
|
||||
|
||||
std::string publish_topic_;
|
||||
|
||||
Reference in New Issue
Block a user