NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

ESP32 C3 (Super Mini) whit Samsung Galaxy S23+ and later

Open leandro-san opened this issue 3 months ago • 5 comments

My code works well on several Samsung Android devices, but it doesn't work on the Galaxy S23 and later.

What parameters and settings should I add to make it work on the Galaxy S23 and later?

I'm using:

pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 180)

leandro-san avatar Aug 30 '25 22:08 leandro-san

I would just remove that line completely and see if it works.

h2zero avatar Aug 30 '25 22:08 h2zero

Thanks for the reply h2zero. I tested without this line, and it still doesn't work.

leandro-san avatar Aug 31 '25 01:08 leandro-san

I can't solve this problem. The ESP can't be seen on Galaxy S23 and later smartphones, but it works perfectly on earlier versions. The sample codes provided with the library also don't work on these devices. Could it be something related to MTU? Where am I going wrong? What do you recommend?

My code:

#include <NimBLEDevice.h>

NimBLECharacteristic* pCharacteristic    = nullptr;
bool                  deviceConnected    = false;
uint8_t connectedDevices = 0;
#define MAX_CONNECTIONS     2

#define SERVICE_UUID        "0000FFE0-0000-1000-8000-00805F9B34FB" // (0000181a-0000-1000-8000-00805f9b34fb   6e400001-b5a3-f393-e0a9-e50e24dcca9e  0000FFE0-0000-1000-8000-00805F9B34FB  00001800-0000-1000-8000-00805F9B34FB
#define CHARACTERISTIC_UUID "0000FFE1-0000-1000-8000-00805F9B34FB" // (00002a6d-0000-1000-8000-00805f9b34fb   6e400003-b5a3-f393-e0a9-e50e24dcca9e  0000FFE1-0000-1000-8000-00805F9B34FB  00002902-0000-1000-8000-00805f9b34fb

class ServerCallbacks : public NimBLEServerCallbacks {

    void onConnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo) override {
      connectedDevices++;
      //Serial.printf("Device connected, total: %d\n", connectedDevices);

      if (connectedDevices >= MAX_CONNECTIONS) {
            NimBLEDevice::stopAdvertising();
            //Serial.println("Max connections reached, advertising stopped");
            }
      else {
            NimBLEDevice::startAdvertising();
            }
            pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 180);
            deviceConnected = true; 
      };
    
    void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) override {
      connectedDevices--;
      //Serial.printf("Device connected, total: %d\n", connectedDevices);
      
      if (connectedDevices < MAX_CONNECTIONS) {
            NimBLEDevice::startAdvertising();
            //Serial.println("Advertising restarted");
            }    
       }
     } serverCallbacks;

    void onAdvComplete(NimBLEAdvertising* pAdvertising) {
      if (deviceConnected) {
      return;
      }
      pAdvertising->setScanFilter(false, false);
      pAdvertising->start();
      }
void setup() {
NimBLEDevice::init("ESP SERVER");

    NimBLEServer* pServer = NimBLEDevice::createServer();
    pServer->setCallbacks(&serverCallbacks);
    pServer->advertiseOnDisconnect(true);

    NimBLEService* pService = pServer->createService(SERVICE_UUID);

    pCharacteristic =
        pService->createCharacteristic(CHARACTERISTIC_UUID,
                                       NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::NOTIFY);
    pService->start();

    NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
    pAdvertising->setName("ESP SERVER");
    pAdvertising->addServiceUUID(SERVICE_UUID);
    pAdvertising->enableScanResponse(false);
    pAdvertising->setAdvertisingCompleteCallback(onAdvComplete);
    pAdvertising->start();
    }
void loop() {
//
}

leandro-san avatar Sep 01 '25 14:09 leandro-san

There's nothing wrong with your code, and I am not able to reproduce any issues. This is probably an issue with the client device.

h2zero avatar Sep 02 '25 14:09 h2zero

Thank you h2zero

leandro-san avatar Sep 03 '25 23:09 leandro-san