It is all about Bluetooth classic. I want the BLE, to connect multiple device to a single app.
First sentence:
yes, but the all examples are for classic
I configured the esp32 for BLE, still not shown in the device list
/*
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 "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
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");
// 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;
}
}
For additional information,
The developer of this code said:
"Confirmed to work on:ESP32-WROOM-32D
Does not work on (will not connect):
ESP32-WROOM-32"
My is ESP32-WROOM-32
good news, i found it in the list, but not connect. i found similar question in this forum, but not resolved (ESP32-WROOM-32 Does not Work with MIT App Inventor in BLE Mode (BluetoothLE)?)
waiting your support
when I add location sensor it shows the list of Bluetooth devices
I am using ESP-WROOM-32 module, is this device can connect to MIT app inventor?
Do not use ESP-WROOM-32, use ESP32-WROOM-32D instead.
I have no access to get ESP32-WROOM-32D locally, that is why I am trying to get a solution for ESP32-WROOM-32.
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!!!
HI,
attached a screenshot of my work.
When looking to the mit app in settings, I do not find anything to enable as mentioned.
regards
ludo
Hi,
thanks for your quick feedback.
What do you mean by not using the latest version ? I only installed my software just a few days ago....(I see [grafik] in you message, but do not see a picture).
What do I change in my app to not use the permission ?
regards
Ludo
Check it.
Try this (and post a screenshot):
Sorry,
do not understand. Please tell me for what I need the latest version.
And show me a screenshot of where to change the BLE permission.
regards
Ludo