I am trying to pass a *byte type variable to a function which uses *char type variable. However, I have no luck doing that
I am using Arduino IDE and programming ESP32 devices
This is the function to which I am trying to pass a char* payload ( It is JSON type string which I need to parse)
This payload variable comes from this function:
The error that I am getting:
I am using Arduino IDE and programming ESP32 devices
This is the function to which I am trying to pass a char* payload ( It is JSON type string which I need to parse)
Code:
void parse_item_inside(char* payload){
cJSON* jsonObj = cJSON_Parse((char*)(payload));
// Get pointer to specific field in JSON object
cJSON* item = cJSON_GetObjectItem(jsonObj, "item");
cJSON* serial = cJSON_GetObjectItem(jsonObj, "serial");
cJSON* quantity = cJSON_GetObjectItem(jsonObj, "quantity");
if (item != NULL)
{
//Get integer value - other fields allow access to strings, floats etc.
strcpy(item_inside.item,item->valuestring);
strcpy(item_inside.serial,serial->valuestring);
item_inside.quantity = quantity->valueint;
OLED_display(item_inside.quantity);
}
// Delete JSON object (don't forget this)
cJSON_Delete(jsonObj);
}
This payload variable comes from this function:
Code:
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
char message[length + 1];
strncpy (message, (char*)payload, length);
message[length] = '\0';
Serial.println(message);
if (strcmp(topic,item_inside_topic) == 0){ //if number_to_pick received, means the complecataion has been scanned and initiate the pick_to_light
parse_item_inside(payload);
}
}
Code:
invalid conversion from 'byte* {aka unsigned char*}' to 'const char*' [-fpermissive]