Sending info to BLE-server service characteristic
Posted: 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:
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.
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.