Page 1 of 1

Sending info to BLE-server service characteristic

Posted: Thu Jul 09, 2020 2:32 pm
by Angelo
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 6707 times

AFTER sending the four bytes:
Data_received.jpg
Data_received.jpg (82.64 KiB) Viewed 6707 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.

Re: Sending info to BLE-server service characteristic

Posted: Fri Jul 10, 2020 7:33 am
by chegewara

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);

Re: Sending info to BLE-server service characteristic

Posted: Mon Jul 13, 2020 7:56 am
by Angelo
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 6699 times

Re: Sending info to BLE-server service characteristic

Posted: Mon Jul 13, 2020 10:16 am
by chegewara
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.

Re: Sending info to BLE-server service characteristic

Posted: Tue Jul 14, 2020 8:23 am
by Angelo
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 6655 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.

Re: Sending info to BLE-server service characteristic

Posted: Tue Jul 14, 2020 10:11 am
by chegewara
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.

Re: Sending info to BLE-server service characteristic

Posted: Wed Jul 15, 2020 11:53 am
by Angelo
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.

Re: Sending info to BLE-server service characteristic

Posted: Wed Jul 15, 2020 3:37 pm
by chegewara
When you are sending from nRF connect, what value type you are using?

Re: Sending info to BLE-server service characteristic

Posted: Wed Jul 15, 2020 5:03 pm
by Angelo
Byte.
SmartSelect_20200715-185312_nRF Connect.jpg
SmartSelect_20200715-185312_nRF Connect.jpg (49.3 KiB) Viewed 6521 times