fix race condition with multiple simultaneus requests

This commit is contained in:
cjkas 2026-03-25 16:09:08 +01:00
parent 2e379e6c1e
commit d5b8acecda
4 changed files with 203 additions and 21 deletions

View file

@ -1,8 +1,39 @@
#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <freertos/queue.h>
#include <freertos/semphr.h>
#include "Somfy.h"
#ifndef webserver_h
#define webserver_h
#define WEB_CMD_QUEUE_SIZE 8
#define WEB_CMD_TIMEOUT_MS 3000
enum class web_cmd_t : uint8_t {
shade_command, // moveToTarget or sendCommand
group_command, // group sendCommand
tilt_command, // moveToTiltTarget or sendTiltCommand
shade_repeat, // shade sendCommand/repeatFrame
group_repeat, // group sendCommand/repeatFrame
set_positions, // set shade position directly
shade_sensor, // shade sensor command
group_sensor, // group sensor command
};
struct web_command_t {
web_cmd_t type;
uint8_t shadeId;
uint8_t groupId;
uint8_t target; // 0-100 or 255 (none)
somfy_commands command;
int8_t repeat;
uint8_t stepSize;
int8_t position; // for setPositions
int8_t tiltPosition; // for setPositions/tilt
int8_t sunny; // for sensor
int8_t windy; // for sensor
};
class Web {
public:
bool uploadSuccess = false;
@ -36,5 +67,8 @@ class Web {
void handleBackup(AsyncWebServerRequest *request);
void handleReboot(AsyncWebServerRequest *request);
void handleNotFound(AsyncWebServerRequest *request);
private:
void processQueue();
bool queueCommand(const web_command_t &cmd);
};
#endif