Sending info to BLE-server service characteristic

Angelo
Posts: 5
Joined: Thu Jul 09, 2020 1:26 pm

Sending info to BLE-server service characteristic

Postby Angelo » Thu Jul 09, 2020 2:32 pm

Hi, I am using an ESP32 and Arduino IDE to build a camera controller for a GoPro Hero 8. I have got it with no problem using WiFi, but BLE is supposed to drain the battery much less and, I hope, improve the performance.
The problem with BLE and ESP32 is I haven't been able to send a command successfully.

The GoPro announces an specific service and an specific characteristic to receive action requests. For instance, to fire the camera shutter, you need to send the following bytes: 0x03,0x01,0x01,0x01.
If you use a BLE tool on a smartphone you can easiliy connect to the GoPro service and issue that command, and the camera takes a picture or starts recording.

If I use this code on the ESP32 arduino IDE:
byte data[4] = { 0x03, 0x01, 0x01, 0x01};
rs = String((char *)data);
Serial.print("Sending command ");Serial.println(rs.c_str());
pRemoteCharacteristic->writeValue((uint8_t*)rs.c_str(), strlen(rs.c_str()), true);

the camera does nothing.

I have tested my code against a GATT server on my Android Phone, using the same app BLE Tool.
This is what I see in the Ble Tool log.
BEFORE sending the four bytes:
Awaiting_data.jpg
Awaiting_data.jpg (61.22 KiB) Viewed 7609 times

AFTER sending the four bytes:
Data_received.jpg
Data_received.jpg (82.64 KiB) Viewed 7609 times

You can see that the for bytes 03 01 01 01 are effectively sent, BUT the field value is filled with two numbers I did not send and I don't know where they come from. I think this is the problem. Using a different tool that fills just the field data works fine.
Does someone know what I am missing? Could this be a libraries problem, or am I doing something wrong?

Thank you in advance.
Last edited by Angelo on Sun Jul 12, 2020 7:16 pm, edited 1 time in total.

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

Re: Sending info to BLE-server service characteristic

Postby chegewara » Fri Jul 10, 2020 7:33 am

Code: Select all

uint8_t data[4] = { 0x03, 0x01, 0x01, 0x01};
rs = String((char *)data);
Serial.print("Sending command ");Serial.println(rs.c_str());
pRemoteCharacteristic->writeValue(data, 4, true);

Angelo
Posts: 5
Joined: Thu Jul 09, 2020 1:26 pm

Re: Sending info to BLE-server service characteristic

Postby Angelo » Mon Jul 13, 2020 7:56 am

Thank you cheguewara,
the code you suggest produces the same effect. The characteristic value field is filled with those 259,000 and 257,000 that I cannot tell where they come from.
See the log in the BLE Tool app:
log.jpg
log.jpg (57.49 KiB) Viewed 7601 times

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

Re: Sending info to BLE-server service characteristic

Postby chegewara » Mon Jul 13, 2020 10:16 am

In that case its all fine. App you are using is trying to interpret received values and display in human readable version value.
Since its not a string app is trying to interpret it as numbers. So you have 0x0301 little endian it will be 0x103 which is 259 decimal and 0x0101 little endian is 0x101 which is 257 decimal. Why this app is adding 0s hard to say, but important is that raw data received is what you send and expecting to receive.

Angelo
Posts: 5
Joined: Thu Jul 09, 2020 1:26 pm

Re: Sending info to BLE-server service characteristic

Postby Angelo » Tue Jul 14, 2020 8:23 am

Thank you very much chegewara, I understand.
Please see this screenshot from log of the BLE Tool app, right after a successful BLE command request to a GoPro cam.
SmartSelect_20200714-101342_BLE Tool.jpg
SmartSelect_20200714-101342_BLE Tool.jpg (39.32 KiB) Viewed 7557 times
The app lets you introduce the data to send in hex. In this case just "03010101". As you see, the data field is completed with those bytes, but the value field remains empty. The camera receives and executes this command correctly. This is what I am not able to get using ESP32 and Arduino. What do you think I may be missing?
Thanks again for your kind help.

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

Re: Sending info to BLE-server service characteristic

Postby chegewara » Tue Jul 14, 2020 10:11 am

The reason i posted code snippet in first place is because you were using string. If you are using string then additional 0x0 can be added at the end.
When you are sending binary data its safer to use uint8_t instead of char or std::string, even with strings you can use uint8_t if you dont care about 0x0 terminator being truncated.

Angelo
Posts: 5
Joined: Thu Jul 09, 2020 1:26 pm

Re: Sending info to BLE-server service characteristic

Postby Angelo » Wed Jul 15, 2020 11:53 am

Thank you chegewara,
I am not able to make this work. Using an android app or any other utility, I can send the four bytes to the GoPro and it works, but definitely cannot do it using an ESP32 program.
I'll explore other options, raspberry and such. There is a few python samples to do this. Thank you for your kindness.

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

Re: Sending info to BLE-server service characteristic

Postby chegewara » Wed Jul 15, 2020 3:37 pm

When you are sending from nRF connect, what value type you are using?

Angelo
Posts: 5
Joined: Thu Jul 09, 2020 1:26 pm

Re: Sending info to BLE-server service characteristic

Postby Angelo » Wed Jul 15, 2020 5:03 pm

Byte.
SmartSelect_20200715-185312_nRF Connect.jpg
SmartSelect_20200715-185312_nRF Connect.jpg (49.3 KiB) Viewed 7423 times

Who is online

Users browsing this forum: No registered users and 59 guests