Hello,
I am trying to parse serial messages being sent to the ESP32 but the function "uart_read_bytes" seems to look for a NULL terminator similarly to printf. My message has special characters including the NULL terminator so I was wondering if there was any function I can use to extract the raw data from the uart rx buffer.
This is the message the ESP32 receives:
0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x5f 0x0d 0x00 0x1b 0x79
It breaks the message into 2 parts; the 2nd message being 0x00 0x1b 0x79.
ESP32 UART reading special characters including NULL
-
- Posts: 1725
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP32 UART reading special characters including NULL
No, it doesn't.
Since UART transmissions have no concept of 'messages', only of bytes, the size and number of chunks you receive depends on the sizes of buffers and timing. You'll have to determine what defines the start and/or end of a 'message' and piece together a message from the bytes you receive based on that.It breaks the message into 2 parts; the 2nd message being 0x00 0x1b 0x79.
Re: ESP32 UART reading special characters including NULL
That was what I expected to happen but when I print the RX buffer immediately after reading, I get multiple messages compared to the single message being sent to the esp32.
Do you see something wrong in the way I am using the function that would result in this ?
- int len;
- char tmp_buf[128] = "";
- uart_get_buffered_data_len(CONSOLE_UART_NUM, (size_t*)&len);
- uart_read_bytes(CONSOLE_UART_NUM, tmp_buf, len, (TickType_t)portMAX_DELAY);
- printf("s: ");
- for (int i = 0; i < len; i++)
- {
- printf("%c", tmp_buf[i]);
- }
- printf("\n");
-
- Posts: 1725
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP32 UART reading special characters including NULL
What do you mean? Do you get more bytes than were actually sent over the wire?
Or do you just get the bytes from more than one message with a single uart_read_bytes() call? - If so, that is also to be expected, depending on timing and buffers. When I wrote that you'd have to piece together the messages, I meant to imply that you'll also have to split the chunks of bytes into messages. The UART doesn't know when a 'message' starts or ends; it will just give you any bytes it receives in the order they arrived.
Can't tell.Do you see something wrong in the way I am using the function that would result in this ?
But in any case you should make sure that you limit the length you pass to uart_read_bytes() to not more than sizeof(tmp_buf) in case there are more bytes in the UART buffer(s) than would fit into tmp_buf.
Who is online
Users browsing this forum: No registered users and 222 guests