If I am getting an integer value in 3 bytes, how best to convert it to something I can send using cJSON.
I can get the value and iterate over it, but once I put it in a char array, i cannot even see the value any longer.
Thoughts?
Code: Select all
{
uint8_t buf[BUF_SIZE];
memset(buf, 0, sizeof(buf));
// Read data from the UART
int checkIt = uart_write_bytes(UART_NUM_2, (const char *)hex, strlen(hex));
ESP_LOGI(LOG_TAG, "this is the length of transmit: %i: ", checkIt);
int len2 = uart_read_bytes(UART_NUM_2, buf, BUF_SIZE - 1, 1000 / portTICK_RATE_MS);
ParseData(buf);
}
ParseData(char * data)
{
//initialize char array to zeros
char temporary[4] = {0};
for(int i=0; i<3; i++)
{
//first two bytes are not needed, so skip them for now
temporary[i] = data[i+2];
ESP_LOGI(LOG_TAG, " temporary # %i %i ", i, temporary[i]);
}
temporary[3] = '\0';
ESP_LOGI(LOG_TAG, " temp char contents update %s ", temporary;
}
It is printing out nothing, even if I don't add the null character to it.
If I can get it to a single value (123), or even a char (string type), then I can add it to a cJSON object and send it.