If I connect my ESP32 board to my PC via USB and upload any code via the Arduino IDE, all works fine.
Even if I disconnect the USB cable, when I reconnect it, the ESP32 board restarts and works perfectly.
If I disconnect the USB cable and power the ESP32 board by means a reliable power source (https://www.tek.com/en/products/keithley/dc-power-supplies/2220-2230-2231-series) either from Vin (5V) or 3.3 V, the ESP32 board doesn't work in any way even though the onboard LED is ON.
In detail:
The ESP32 acts as a BLE server to which a BLE client is connected configured on another ESP32 board running under Home Assistant.
Powering via USB, the BLE server sends data to the BLE client on Home Assistant. When I disconnect the USB cable from the PC and connect the ESP32 to an external power source it stops sending data in any way.
Any idea?
void setup()
{
Serial.begin(115200);
pinMode(25,OUTPUT);
Serial.println("Visualizza quanto trasmesso dal BLE Client a questo BLE Server: ");
BLEDevice::init("MyESP32-Cosimo");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setCallbacks(new MyCallbacks());
//pCharacteristic->setValue("Hello World");
std::string value = "Hello World";
pCharacteristic->setValue(value);
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
Best Answer
Problem solved.
It was only a bad ESP32 board .
It works when powered by USB and don't in anyway if powered by external source. Replacing it with a new, identical, board, it works fine even if is powered by 5V than 3,3 V.