I am using an android app (mobile phone) and an ESP32, connected to each other via BLE. I am trying to send a string from the mobile phone to the ESP32. The android app sends a string in byte array form and the esp receives it. But I am having trouble retrieving the value on the ESP firmware.
Below is the code for the method that I tried. The whole point of this code is for the string that was sent from the android app to be stored in this variable: INCOMING_STRING1
. I tried setting up the receiving variable as a character array (I think that's what this variable is for), and then used strcpy
assuming that the contents of the incoming data (passed in through the character parameter) would be copied to INCOMING_STRING1
, however, it doesn't work.
//Variables
const uint8_t *character;
char INCOMING_STRING1[64];
//Elsewhere in code...
//event comes from the ESP BLE module when a BLE event happens
switch(event)
{
case ESP_GATTS_WRITE_EVT:
writeHandle(param->write.handle);
break;
...
}
//Elsewhere in code...
static void writeHandle(uint16_t handle)
{
get_attr_ret = esp_ble_gatts_get_attr_value(handle, &length, &character);
//There's different handles for different "channels"
if(handle == 45)
{
//supposed to take string that was received
strcpy(INCOMING_STRING1, character);
//then print it to make sure
printf("%s", INCOMING_STRING1);
}
}
I'm aware that this is probably a type miss match, since the incoming data is of type uint8_t
and the variable to store the string is type char
. I've always struggled with type casting and type manipulation in general, any help is appreciated!
Here's the error messages I get at this moment:
error: pointer targets in passing argument 2 of 'strcpy' differ in signedness [-Werror=pointer-sign] strcpy(INCOMING_STRING1, character); ^ note: expected 'const char * restrict' but argument is of type 'const uint8_t * {aka const unsigned char *}'