Guten Morgen Community,
dies ist mein erster Post, und ich möchte nicht unhöflich wirken das ich so eine Frage stelle.
Ich habe mich schon versucht hier über die Suche durch zu wurschteln und konnte nicht so richtig fündig werden. Liegt wohl auch daran das ich der totale Noob bin.
Nun zu meiner Frage bzw. Problem.
Ich besitze ein Bluetooth-Gerät welches eine Verbindung zu einer APP herstellt.
Starte ich diese APP wird ein Profil erkannt. Es gibt zwei Profile
Ich würde ganz gerne das Bluetooth Gerät auf einen ESP transferieren. Was ich auch bereits hinbekommen habe, allerdings Verbindet der ESP sich immer mit den falschen Profil.
Im Arduino Sketch habe ich die UUID und den Device Name angepasst und die Verbindung klappte.
Ich denke das das Bluetooth Gerät Standardmäßig immer mit den Profil startet und das zweite benötigt eine weitere Abfrage.
Ich habe leider keinen Plan wie die Abfrage nach dem zweiten Profil aussehen muss, damit er auf das Profil wechselt, oder gleich mit den richtigen Profil startet.
Vielleicht ist jemand so nett und kann mir helfen wie die Abfrage dazu aussehen muss.
Ich hänge mal das Sketch File an welches ich nutze. Ich habe die UUIDs mal ge- xxx zur Sicherheit, da ich nicht weiß ob man die Zeigen darf.
Ich kann gerne aus Wireshark weitere Informationen zur Verfügung stellen.
Hoffe das sich keiner auf den Schlips getreten fühlt das ich so unbeholfen und direkt frage.
Gruß
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <BLEService.h>
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false;
bool oldDeviceConnected = false;
uint32_t value = 0;
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "xxxxxx60-xx00-xx22-xxx1-xxxxxxxxxxeb"
#define CHARACTERISTIC_UUID "xxxxxx61-xx00-xx22-xxx1-xxxxxxxxxxeb"
#define CHARACTERISTIC_UUID2 "xxxxxx62-xx00-xx22-xxx1-xxxxxxxxxxeb"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
BLEDevice::startAdvertising();
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("Name vom Bluetooth Gerät");
// 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_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_INDICATE
);
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
// Create a BLE Descriptor
pCharacteristic->addDescriptor(new BLE2902());
// 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((uint8_t*)&value, 4);
pCharacteristic->notify();
value++;
delay(10); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms
}
// 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;
}
}