Converting valuestring or valueint from cJSON to send using uart_write_bytes is failing
Posted: Tue Dec 18, 2018 3:23 pm
So, currently, I am sending a JSON message containing a value I need to send from an ESP32 UART uart_write_bytes, but am not sure where I am going wrong in the conversion.
Currently, if I send 234, it goes out the UART as 50, 51, 52, and not 234.
Thoughts?
I am using esp-idf not Arduino.
Currently, if I send 234, it goes out the UART as 50, 51, 52, and not 234.
Thoughts?
I am using esp-idf not Arduino.
Code: Select all
cJSON* message'
int intValue = 0;
char *stringValue= "999";
if ((message = cJSON_GetObjectItem(root->child, "msg")) != NULL)
{
if((intValue = cJSON_GetObjectItem(message, "Number")->valueint) != NULL)
{
ESP_LOGI(LOG_TAG, " this is the Number %i ", intValue);
}
if((stringValue = cJSON_GetObjectItem(message, "Number")->valuestring) != NULL)
{
ESP_LOGI(LOG_TAG, " This is NumberString %s ", stringValue);
}
}
char numStrStr[3];
char *p = numStr;
for(int j = 0; j < sizeof(str); j++)
{
//hex[j] = *p++;
hex[j] = numStrStr[j];
}
char s[200];
uint8_t buf[BUF_SIZE];
sprintf(s, hex);
memset(buf, 0, sizeof(buf));
memset(s, 0, sizeof(s));
ESP_LOGI(LOG_TAG, "this is the hex: %s ", (char *)hex);
ESP_LOGI(LOG_TAG, "this is the hex as s: %s ", s);
int checkIt = uart_write_bytes(UART_NUM_2, (const char *)hex, strlen(hex));