I have been having difficulties in connecting my ESP32 to my phone using MIT App Inventor in BLE mode (with BluetoothLE extension). It works fine when I am with Classic Bluetooth (BluetoothClient).
What are these problems? Are you using the latest version of the BLE extension? Have you tried BLE connection with another app?
And finally, we can't see your blocks and code from ESP.
What are these problems? it shown in the list, but it can not connect, no error shown
Are you using the latest version of the BLE extension? yes
Have you tried BLE connection with another app? yes, nRF Connect
And finally, we can't see your blocks and code from ESP, shown in below:
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleNotify.cpp
Ported to Arduino ESP32 by Evandro Copercini
updated by chegewara and MoThunderz
*/
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
BLEDescriptor *pDescr;
BLE2902 *pBLE2902;
bool deviceConnected = false;
bool oldDeviceConnected = false;
uint32_t value = 0;
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "484f7e50-ccde-448c-bbeb-607649e301b8"// "3c6eabe3-411f-4ecb-8cb4-f6bfa1dd6c6a"
#define CHARACTERISTIC_UUID "a0c6ba51-7ca2-493e-b679-6a372c060c8d"//"ecb909af-8776-4823-a5d5-c0d9c41cbea2"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("ESP32_2");
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_NOTIFY
);
// Create a BLE Descriptor
pDescr = new BLEDescriptor((uint16_t)0x2901);
pDescr->setValue("A very interesting variable");
pCharacteristic->addDescriptor(pDescr);
pBLE2902 = new BLE2902();
pBLE2902->setNotifications(true);
pCharacteristic->addDescriptor(pBLE2902);
// Start the service
pService->start();
// Start advertising
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(false);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
BLEDevice::startAdvertising();
Serial.println("Waiting a client connection to notify...");
}
void loop() {
// notify changed value
if (deviceConnected) {
pCharacteristic->setValue(value);
pCharacteristic->notify();
value++;
delay(1000);
}
// disconnecting
if (!deviceConnected && oldDeviceConnected) {
delay(500); // give the bluetooth stack the chance to get things ready
pServer->startAdvertising(); // restart advertising
Serial.println("start advertising");
oldDeviceConnected = deviceConnected;
}
// connecting
if (deviceConnected && !oldDeviceConnected) {
// do stuff here on connecting
oldDeviceConnected = deviceConnected;
}
}
I don't see any irregularities here. This should probably work. I would have to try your code in esp32.
Thank you,
Please use ESP-WROOM-32. I think ESP32-WROOM-32D is work. I have no access to get ESP32-WROOM-32D locally, that is why I am trying to get a solution for ESP32-WROOM-32.
I've heard of this problem before. Someone had the same problem and even provided a link to a tutorial in which someone also described this problem. The 32 versions were probably withdrawn and their place was taken by the 32D. Unfortunately, I don't have version 32 in my resources.
Congratulation!!! Now it work for ESP32-WROOM-32 by adding KI04_Bluetooth1 extension from 160.- Bluetooth Low Energy. BLE. Librería. De AI2 a ESP32. De ESP32 a AI2.
Now I connected two BLE with a single MIT app inventor.
Thank you all of them for trying to resolve my problem!!!
I'm trying to connect to a ESP32-Wrover and same problem. I can scan, see the devices but when run connect, notingh happens, it displays the error: "Connection status was set to OS code 4".
But the same APP is able to connect to other device what uses a rn4870 BLE component.
At the same time, I can connect to the ESP32 program with others app.
So it looks like there is an incompatibility betweem BluetoothLE and ESP32 and Arduino ESP32 v2.0.14 based on ESP-IDF v4.4.6
Some other info would be helpful.
Android version, show your blocks, load up your aia file...
Could be a permission issue or something else.