I'm sending data from an ionic app (typescript) to an ESP32chip. Data from the app uses protocol buffer format. Here's the code:
this.provisionMgrAction.setAction('stop');
let bytesOfStuff = await this.provisionMgrAction.serializeBinary();
BleClient.write(this.deviceID, serviceID, characteristicID, bytesOfStuff);
On the ESP chip side (code in C), data is received as "stop". The log (ESP_LOGI line below) prints value of inbuf as "stop" (without quotation marks).
esp_err_t custom_prov_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen,
uint8_t **outbuf, ssize_t *outlen, void *priv_data)
{
if (inbuf) {
ESP_LOGI(TAG, "Received data: %.*s", inlen, (char *)inbuf);
if (strcmp(inbuf, "stop") == 0) {
ESP_LOGI(TAG, "print something");
}
}
}
But strcmp doesn't seem to work. I'm presuming it has something to do with the fact that when "stop" is sent over BLE from the client side app to the ESP32 chip, it comes without a null character, though I'm not sure how to confirm that. In any event, how do I make sure that strcmp equates the value of inbuf to "stop"? Do I need to add a null character to inbuf? If yes, how do I accomplish that? Or do I need to compare inbuf to "stop\0"? The length of inbuf (inlen) is printed out to be 2 more than the number of characters in the message that is transmitted to the chip over BLE (in this case, 6).
"%s"
) but as hex to reveal null and/or control characters. \$\endgroup\$