Hi, I am really grateful for all the work you did with the ESP32 and the 8266. I have some led strips controlled by BLE controller receiving commands from a Android phone app.
I would like to turn on the lights from a ESP32.
I followed this tutorial on how to get the command codes from the phone .
nilhcem.com/iot/reverse-engineering-simple-bluetooth-devices
_BLE_Address = "ff:ff:1a:00:46:d2"; serviceUUID("0000fff0-0000-1000-8000-00805f9b34fb"); charUUID("0000fff1-0000-1000-8000-00805f9b34fb");
the value that turns the light on and of is 0x04
Do you have any sample programs that directly connects to a BLE device and sends a code to activate something.
Thank you
Jose Nunes
Hello Jose, you should be able to use the example that you can find in your Arduino IDE: File > Examples > ESP32 BLE Arduino > BLE_Client.
Basically, you just need to set the service UUID and Characteristic with your value. Then, your ESP32 will scan for nearby BLE devices with that Service and Characteristic. That example also already connects to the device.
Then, in the loop you can modify that section to write that value 0x04:
pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
I don’t have any examples on that exact subject, but using that sketch should help you do what you’re looking for.
Regards,
Rui
Hi Rui
Thank you for your response.
You pointed me to the right direction. I got it to work!
The only issue is that I have 3 of these controllers in the same room. Is there a way that I can connect to the one I want to control or connect to all 3 and turn all the lights on or off? If I can not connect them all the same time , how can I connect to one, turn light on then connect to the next on and turn the light on?
All three controllers have the same service and characteristic UUIDs
Thank you again
Jose Nunes
Just a note , in case anyone is trying this. The line I added is
uint8_t array[20] = {0x04,0xf00,,0xf00,,0xf00,,0xf00,,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00}; pRemoteCharacteristic->writeValue(array, 20);
The receiver did not accept a string, but requires a 20 byte code
As you’ve mentioned in your first comment, you usually identify the BLE device by Mac Address.
It’s easy to get your own device Mac Address using: BLEDevice::getAddress():
- techtutorialsx.com/2018/03/09/esp32-arduino-getting-the-bluetooth-device-address/
To recognize the other device, you usually identify it by Service and Characteristic…
I couldn’t find any method implemented to get the other device Mac Address. Unfortunately I think it’s not implemented at the moment: https://github.com/nkolban/esp32-snippets/issues/552