Hello everyone!
Can you please advise me why AsyncElegantOTA does not work in parallel with the BluetoothSerial ? To use AsyncElegantOTA service I must end BluetoothSerial and vice versa.
The only way I found and works for me is here. My real code is more complicated, but I’ll simplify it like this:
#include <Arduino.h> #include <WiFi.h> #include <AsyncTCP.h> #include <ESPAsyncWebServer.h> #include <AsyncElegantOTA.h> #include <BluetoothSerial.h> AsyncWebServer server(80); BluetoothSerial SerialBT; bool ota_need; // "we just need OTA service" flag bool bt_need; // "we just need BT service" flag bool ota_is_up; // "OTA service up" flag bool bt_is_up; // "BT service up" flag void setupService(); void setup() { Serial.begin(115200); SerialBT.begin("ESP32"); bt_is_up = true; bt_need = true; // Wifi connect code here // ... // server.begin() // not yet ota_is_up = false; ota_need = false; AsyncElegantOTA.begin(&server); } void loop() { // other code here setupService(); // setup service based on currrent needs // other code here } // --------------------------------------------------------- // Up or down OTA / BT services, based on current needs // --------------------------------------------------------- void setupService() { // ota_need = TRUEORFALSE; // both changed somewhere in code // bt_need = TRUEORFALSE; // // OTA need? if ( ota_need ) { // BT down: if (bt_is_up) { SerialBT.end(); // end BluetoothSerial delay(1000); // or other way of "BT down" verification bt_is_up = false; } // Server up: if (!ota_is_up) { server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "Hi! I am ESP32."); }); server.begin(); // start AsyncElegantOTA service ota_is_up = true; Serial.println("HTTP server goes up"); } // else Serial.println("HTTP server already up"); } // BT need? if ( bt_need ) { // Server down: if (ota_is_up) { server.end(); // end AsyncWebServer delay(1000); // or other way of "server down" verification ota_is_up = false; } // BT up: if (!bt_is_up) { SerialBT.begin("ESP32"); // start BluetoothSerial bt_is_up = true; Serial.println("SerialBT server goes up"); } // else Serial.println("SerialBT server already up"); } } // ---------------------------------------------------------
Hi.
I haven’t tried AsyncElegantOTA with Bluetooth.
You can try to open an issue related to this subject on the library GitHub page: https://github.com/ayushsharma82/AsyncElegantOTA/issues.
Regards,
Sara
Thank you Sara,
I think that problem is not explicitly in ElegantOTA, but in parallel functionality AsyncServer and BT. Have you already tried this two things at the same time? Probably only my configurations may bee wrong ..
Hi again.
No, I haven’t tried Bluetooth with the AsyncWebServer simultaneously.
It might be a conflict related to using both at the same time, but I haven’t experimented with it.
Regards,
Sara
I have tried this and found that you can have both stacks running at the same time but the issue is with using the radio. The ESP32 only has one radio so you need to multiplex the use of it. This causes loss of packets and/or slow access. To mitigate I don’t use any “delay”‘s and everything is interrupt driven. Even so I still miss packets if I need to listen for both.
I am now starting to redefine my project requirements and will either use WiFi exclusively with ESP-NOW or use two ESP-32’s and dedicate one to WiFi and one to BLE (Luckily these things are cheap).
YMMV. It depends on what your project is doing.
Thank you Steve,
Most of people suggest to multiplex “radio”. But to be honest I’m not sure if methodes end(), stop()) do it. Quite long discussion about it is here
At $5 per board I can dedicate one to WiFi and one to BLE and talk to each other over I2C, SPI or UART.