ESP32 BLE Philips HUE Bulb
Posted: Sat May 07, 2022 9:35 pm
Hi to all,
I'm new here. And I have a problem.
I have a Philips Hue ble bulb and I want to control it with a ESP32.
As a IDE I use Arduino. I took the BLE CLient example and used it.
I can connect to the bulb but when i want to read the value from the characteristic (uint8_t* test = pRemoteCharacteristic->readRawData();) then in test there is just the nullptr. I used the nRF Connect app on a iPad to test if the service and characteristic is the right one. With this app I can switch the Bulb on and off and I can dimm it. But with my ESP32 i cant read or write the value.
I'm not the best programmer and totaly new to BLE.
Can anyone help me with this or knows what I am missing/doing wrong?
Thanks in advance
Shaunie
I'm new here. And I have a problem.
I have a Philips Hue ble bulb and I want to control it with a ESP32.
As a IDE I use Arduino. I took the BLE CLient example and used it.
Code: Select all
//-----------------------------------------------------------------\\
//
// BLE Phillips HUE Lampe schalten bzw. Dimmen
// c7:f7:7e:8e:76:0a
//-----------------------------------------------------------------\\
#include "BLEDevice.h"
static BLEUUID serviceUUID("932c32bd-0000-47a2-835a-a8d455b859dd"); //Service der Lampe
static BLEUUID charONFUUID("932c32bd-0002-47a2-835a-a8d455b859dd"); //Characteristic für an und aus
static BLEUUID charDIMUUID("932c32bd-0003-47a2-835a-a8d455b859dd"); //Characteristic für Dimmen
bool conected = false;
static BLEAdvertisedDevice* myDevice;
class MyCallbacks: public BLEAdvertisedDeviceCallbacks
{
void onResult(BLEAdvertisedDevice advertisedDevice)
{
const char* compareAddress = advertisedDevice.getAddress().toString().c_str();
//BLEAddress adress = advertisedDevice.getAddress();
if (strcmp(compareAddress, "c7:f7:7e:8e:76:0a") == 0)
{
Serial.print("found it");
advertisedDevice.getScan()->stop();
myDevice = new BLEAdvertisedDevice(advertisedDevice);
conected = true;
}
}
};
bool ConnectToServer()
{
BLEClient* pMyClient = BLEDevice::createClient();
pMyClient->connect(myDevice);
Serial.println("connected is here");
conected = false;
BLERemoteService* pRemoteService = pMyClient->getService(serviceUUID);
BLERemoteCharacteristic* pRemoteCharacteristic = pRemoteService->getCharacteristic(charONFUUID);
if (pRemoteCharacteristic->canRead())
{
Serial.println("canRead");
std::string myValue;
uint8_t* test = pRemoteCharacteristic->readRawData();
if (test == nullptr)
{
Serial.println("Fail-NullPointer");
}
}
//Serial.println(pMyClient->getService(serviceUUID).toString().c_str());
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
BLEDevice::init("");
BLEScan* pMyScan = BLEDevice::getScan();
pMyScan->setAdvertisedDeviceCallbacks(new MyCallbacks());
pMyScan->start(2);
}
void loop() {
// put your main code here, to run repeatedly:
if (conected == true)
{
ConnectToServer();
Serial.println("HI");
}
delay(200);
}
I'm not the best programmer and totaly new to BLE.
Can anyone help me with this or knows what I am missing/doing wrong?
Thanks in advance
Shaunie