Fix 'Too many messages queued'
This commit is contained in:
parent
f2a290af30
commit
887b64ddf2
1 changed files with 34 additions and 14 deletions
|
@ -9,7 +9,7 @@
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <Credentials/Credentials.h>
|
#include <Credentials/Credentials.h>
|
||||||
|
|
||||||
const int STEPS = 5;
|
int STEPS = 5;
|
||||||
|
|
||||||
BluetoothSerial bt;
|
BluetoothSerial bt;
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
@ -23,37 +23,57 @@ LightController *light;
|
||||||
void TaskBlink(void *pvParameters);
|
void TaskBlink(void *pvParameters);
|
||||||
void TaskAnalogRead(void *pvParameters);
|
void TaskAnalogRead(void *pvParameters);
|
||||||
|
|
||||||
void setup()
|
void websocketTask(void *parameter)
|
||||||
{
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
websocket->sendMessage(light->getBjtState(), light->getBjtCount());
|
||||||
|
websocket->clearBuffer();
|
||||||
|
|
||||||
int bjtCount = 4;
|
vTaskDelay(90 / portTICK_PERIOD_MS);
|
||||||
const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
|
}
|
||||||
computer = new SerialCommunicator(Serial, 9600, 5, 50);
|
vTaskDelete(NULL);
|
||||||
phone = new BluetoothCommunicator(bt, 5, 50);
|
}
|
||||||
light = new LightController(bjtPin, bjtCount);
|
|
||||||
|
|
||||||
|
void registerTasks()
|
||||||
|
{
|
||||||
|
xTaskCreate(websocketTask, "websocketTask", 10000, NULL, 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void connectWifi()
|
||||||
|
{
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PW);
|
WiFi.begin(WIFI_SSID, WIFI_PW);
|
||||||
Serial.println("Connecting to WiFi");
|
Serial.print("Connecting to WiFi");
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
Serial.println("");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
int bjtCount = 4;
|
||||||
|
const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
|
||||||
|
computer = new SerialCommunicator(Serial, 9600, 5, 50);
|
||||||
|
phone = new BluetoothCommunicator(bt, 5, 50);
|
||||||
|
light = new LightController(bjtPin, bjtCount);
|
||||||
websocket = new WebsocketCommunicator(ws, server, 50);
|
websocket = new WebsocketCommunicator(ws, server, 50);
|
||||||
|
|
||||||
|
connectWifi();
|
||||||
|
registerTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
light->updateState(computer->receiveMessage(), STEPS);
|
light->updateState(computer->receiveMessage(), STEPS);
|
||||||
light->updateState(phone->receiveMessage(), STEPS);
|
light->updateState(phone->receiveMessage(), STEPS);
|
||||||
websocket->sendMessage(light->getBjtState(), light->getBjtCount());
|
computer->sendMessage(light->getBjtState(), light->getBjtCount());
|
||||||
websocket->clearBuffer();
|
computer->clearBuffer();
|
||||||
// computer->sendMessage(light->getBjtState(), light->getBjtCount());
|
phone->sendMessage(light->getBjtState(), light->getBjtCount());
|
||||||
// computer->clearBuffer();
|
phone->clearBuffer();
|
||||||
// phone->sendMessage(light->getBjtState(), light->getBjtCount());
|
|
||||||
// phone->clearBuffer();
|
|
||||||
|
|
||||||
ws.cleanupClients();
|
ws.cleanupClients();
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
Reference in a new issue