Hi All,
I am trying to work on a BLE lock which is currently being operated through a mobile app using the react-native ble plx.
I was trying to make it work through the ESP32 so that it can be controlled remotely. I have prepared the data and is being sent to esp32 through aws iot. data is received but when trying to write to the lock it doesn't respond.
In order to see whether it is something wrong with command or not I installed the noble in my mac and passed the same command through the noble write method and it works and lock responds.
Command is created from a buffer in javascript for noble and this makes lock work
let buffer = encData.slice(0, 20);
console.log(i + ": " + buffer.toString("hex"));
//The buffer value in hex is aa5510f0988fbef125a97eee5e7ae2beeaff79
foundCharacteristic.write(buffer, true, function(error) {
console.log("set characteristic value ");
});
I checked a BLE server using the BLE Scanner app in ios and cloned the same characteristics of the lock and could see the value 0xaa5510f0988fbef125a97eee5e7ae2beeaff79 in the app.
When doing for the ESP, I pass this hex value aa5510f0988fbef125a97eee5e7ae2beeaff79 to aws iot and is received in the ESP32 and then the ble scanning is done and the required service and characteristics are found and are written through the following method using the Ble_Client example.
String input = "aa5510f0988fbef125a97eee5e7ae2beeaff79"
if (connected) {
Serial.println("Setting new characteristic value to \"" + input + "\"");
// Set the characteristic's value to be the array of bytes that is actually a string.
Serial.println(input.c_str());
pRemoteCharacteristic->writeValue((uint8_t*)input.c_str(), input.length());
connected = false;
}
This never works for me .Am I passing the correct way the value or something missing? I am able to scan and get the services and characteristcs but the write is a failure. Not sure whether some conversion issues or what is going wrong. Please do help me if there is something to be done. I have been trying for so long.
Thanks in advance
Try with uint8_t input[] = {...};, unless you need to get length from String. But for testing purpose you can test it that way.
Maybe you write to wrong characteristic?
@chegewara Thanks for the reply. I debugged and tested again with the BLE connect to check what comes from the ESP32 and from the noble.
In noble project
let buffer = encryptedData();// -> which returns a buffer
console.log(i + ": " + buffer.toString("hex")); //aa5510f0988fbef125a97eee5e7ae2beeaff79
The above aa5510f0988fbef125a97eee5e7ae2beeaff79 string value I pass and send it to aws iot to receive in the ESP and this is what is written to the ble device.
In the ble scanner app I could see the
But noble takes the write() a buffer as input so characteristics.write(buffer) is received as the following in the ble scanner
I find the aa5510f0988fbef125a97eee5e7ae2beeaff79 has to reach as hex in the ble device when the esp32 characteristics.write(input) is called .The input is also string "aa5510f0988fbef125a97eee5e7ae2beeaff79".
Most helpful comment
Try with
uint8_t input[] = {...};, unless you need to get length from String. But for testing purpose you can test it that way.Maybe you write to wrong characteristic?