• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

AsyncElegantOTA & BluetoothSerial

Q&A Forum › Category: ESP32 › AsyncElegantOTA & BluetoothSerial
0 Vote Up Vote Down
lubond asked 4 years ago

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");
    }
}
// ---------------------------------------------------------
Question Tags: AsyncElegantOTA, BluetoothSerial
7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
lubond answered 4 years ago

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 ..

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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
 

0 Vote Up Vote Down
lubond answered 4 years ago

Thank you.

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

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.

0 Vote Up Vote Down
lubond answered 4 years ago

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

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

At $5 per board I can dedicate one to WiFi and one to BLE and talk to each other over I2C, SPI or UART.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.