Sending array of bytes to Lamp via BLE

gdogshankmasta
Posts: 2
Joined: Sun Jul 08, 2018 6:26 am

Sending array of bytes to Lamp via BLE

Postby gdogshankmasta » Sun Jul 08, 2018 6:35 am

So I bought these RGB LED floor lamps from amazon and the app on the phone left me wanting more but I have no idea what I'm doing in regards to bluetooth or arduino programming. My end goal is to get control of them from my Adafruit ESP32 Huzzah board, out of which I can make a remote and connect to the web via wifi so I can do cool stuff like make it change color based on time of day à la f.lux, whether or not I'm home, and so forth.

That being said, the first thing I did was use a BTLE utility app to connect to the lamps and find where it stored the relevant info: RGB values, white led brightness value, on/off and modes etc.

The picture shows these values which are as of now the only ones I care about. I got the adafruit sniffer too and I have all the info on the various modes recorded into a file so I can play with those later.

I copied the relevant service and characteristic UUIDs into one of the example sketches for the ESP32/Arduino board and successfully connected to the lamp and sent it the string the sketch generates, causing it to flash wildly(great success).


Basically I need to send an array of 20 bytes that looks like what is shown in the app screenshot and I don't know how to do it:

02:f9:f9:f9:f9:00:00:00:00:00:00:00:00:00:00:00:00:01:00:00 -- On

or

32:f9:f9:f9:f9:00:00:00:00:00:00:00:00:00:00:00:00:01:00:00 -- Off


02 and 32 are the codes for on/off, respectively.

Here is the code for the example:

https://pastebin.com/KQABJ82d


Here is the relevant part of the code where the value is sent to the lamp:

Code: Select all

   // If we are connected to a peer BLE Server, update the characteristic each time we are reached
      // with the current time since boot.
      if (connected) {
        String newValue = "Time since boot: " + String(millis()/1000);
        Serial.println("Setting new characteristic value to \"" + newValue + "\"");
       
        // Set the characteristic's value to be the array of bytes that is actually a string.
        pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
      }
     
      delay(1000); // Delay a second between loops.    

I'm stuck here.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Sending array of bytes to Lamp via BLE

Postby chegewara » Wed Jul 11, 2018 2:15 am

Code: Select all

uint8_t array[20] = {0x32,0xf9,0xf9,0xf9,0xf9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00};
pRemoteCharacteristic->writeValue(array, 20);

gdogshankmasta
Posts: 2
Joined: Sun Jul 08, 2018 6:26 am

Re: Sending array of bytes to Lamp via BLE

Postby gdogshankmasta » Wed Jul 11, 2018 4:03 am

I knew it was a simple solution. Thank you.

Who is online

Users browsing this forum: No registered users and 109 guests