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:
AFTER sending the four bytes:
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.
Sending info to BLE-server service characteristic
Sending info to BLE-server service characteristic
Last edited by Angelo on Sun Jul 12, 2020 7:16 pm, edited 1 time in total.
Re: Sending info to BLE-server service characteristic
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
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:
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:
Re: Sending info to BLE-server service characteristic
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.
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
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. 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.
Please see this screenshot from log of the BLE Tool app, right after a successful BLE command request to a GoPro cam. 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
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.
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
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.
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
When you are sending from nRF connect, what value type you are using?
Who is online
Users browsing this forum: No registered users and 75 guests