ensure we don't keep queueing http requests when we're not in the looping state.

This commit is contained in:
pulipakaa24
2026-01-12 16:26:25 -06:00
parent 45fa356d66
commit d21632da8d
4 changed files with 14 additions and 4 deletions

View File

@@ -6,12 +6,16 @@
#include "cJSON.h" #include "cJSON.h"
#include "encoder.hpp" #include "encoder.hpp"
#include "WiFi.hpp" #include "WiFi.hpp"
#include "socketIO.hpp"
TaskHandle_t wakeTaskHandle = NULL; TaskHandle_t wakeTaskHandle = NULL;
void wakeTimer(void* pvParameters) { void wakeTimer(void* pvParameters) {
while (1) { while (1) {
vTaskDelay(pdMS_TO_TICKS(60000)); vTaskDelay(pdMS_TO_TICKS(60000));
// avoid accumulating events during re-setup or calibration
if (setupTaskHandle != NULL || socketIOactive
|| uxQueueMessagesWaiting(main_event_queue) > 2) continue;
main_event_type_t evt = EVENT_REQUEST_POS; main_event_type_t evt = EVENT_REQUEST_POS;
xQueueSend(main_event_queue, &evt, portMAX_DELAY); xQueueSend(main_event_queue, &evt, portMAX_DELAY);
} }

View File

@@ -142,10 +142,6 @@ void initMainLoop() {
void IRAM_ATTR watchdogCallback(void* arg) { void IRAM_ATTR watchdogCallback(void* arg) {
if (runningManual || runningServer) { if (runningManual || runningServer) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
main_event_type_t evt = EVENT_CLEAR_CALIB;
BaseType_t result = xQueueSendFromISR(main_event_queue, &evt, &xHigherPriorityTaskWoken);
if (result == pdPASS) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
topEnc->pauseWatchdog(); topEnc->pauseWatchdog();
// get ready for recalibration by clearing all these listeners // get ready for recalibration by clearing all these listeners
@@ -153,6 +149,10 @@ void IRAM_ATTR watchdogCallback(void* arg) {
topEnc->wandListen.store(false, std::memory_order_release); topEnc->wandListen.store(false, std::memory_order_release);
topEnc->serverListen.store(false, std::memory_order_release); topEnc->serverListen.store(false, std::memory_order_release);
servoOff(); servoOff();
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
main_event_type_t evt = EVENT_CLEAR_CALIB;
BaseType_t result = xQueueSendFromISR(main_event_queue, &evt, &xHigherPriorityTaskWoken);
if (result == pdPASS) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
} }
else { else {
// if no movement is running, we're fine // if no movement is running, we're fine

View File

@@ -12,6 +12,7 @@
static esp_socketio_client_handle_t io_client; static esp_socketio_client_handle_t io_client;
static esp_socketio_packet_handle_t tx_packet = NULL; static esp_socketio_packet_handle_t tx_packet = NULL;
static bool stopSocketFlag = false; static bool stopSocketFlag = false;
std::atomic<bool> socketIOactive{false};
// Event handler for Socket.IO events // Event handler for Socket.IO events
static void socketio_event_handler(void *handler_args, esp_event_base_t base, static void socketio_event_handler(void *handler_args, esp_event_base_t base,
@@ -300,6 +301,8 @@ void initSocketIO() {
esp_socketio_register_events(io_client, SOCKETIO_EVENT_ANY, socketio_event_handler, NULL); esp_socketio_register_events(io_client, SOCKETIO_EVENT_ANY, socketio_event_handler, NULL);
esp_socketio_client_start(io_client); esp_socketio_client_start(io_client);
socketIOactive = true;
} }
void stopSocketIO() { void stopSocketIO() {
@@ -310,6 +313,7 @@ void stopSocketIO() {
io_client = NULL; io_client = NULL;
tx_packet = NULL; tx_packet = NULL;
} }
socketIOactive = false;
} }
// Helper function to emit Socket.IO event with data // Helper function to emit Socket.IO event with data

View File

@@ -2,6 +2,8 @@
#define SOCKETIO_HPP #define SOCKETIO_HPP
#include <atomic> #include <atomic>
extern std::atomic<bool> socketIOactive;
// Initialize Socket.IO client and connect to server // Initialize Socket.IO client and connect to server
void initSocketIO(); void initSocketIO();