• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Using a ESP 32 to controll BLE led light controller

Q&A Forum › Category: ESP32 › Using a ESP 32 to controll BLE led light controller
0 Vote Up Vote Down
Jose Nunes asked 4 years ago

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

3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Jose Nunes answered 4 years ago

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

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.