If you are asking a question, please follow this template:
My goal is:
[Send received data from MG_EV_HTTP_CHUNK to UART]
My actions are:
[
void HttpEvent_cb(struct mg_connection *connect, int event, void *evtData, void *data2)
{
int avail;
switch(event)
{
case MG_EV_HTTP_CHUNK:
avail=mgos_uart_write_avail(UART_NO);
LOG(LL_INFO, (“MG_EV_HTTP_CHUNK : len=%d : %d”,msg->body.len, avail));
if (msg->body.len)
{ // Send UART max just for testing
mgos_uart_write(msg->body.p, 255);
}
connect->flags |= MG_F_DELETE_CHUNK;
break;
]
The result I see is:
[
By checking the mgos_uart_write_avail(), the UART data will not be empty until MG_EV_CLOSE is received.
]
My expectation & question is:
[
Should the UART able to send out while HTTP event still active ?
I try to send the data to PC for analysis. But the site has over 20KB of data from MG_EV_HTTP_CHUNK which not possible to store all data before sending.
]
Using port COM3
Error: /src/cli/dev/dev_conn_impl.go:156: Args ['{url:] is not a valid JSON string
/src/cli/dev/dev_conn_impl.go:180:
/src/cli/main.go:198: call failed
Yes. I am Windows guy.
So these example only tested on Linux ?
btw, my original question was, is this all it needs to “free” heap memory ??
But I put a reading of heap size, it just keep increasing until MG_EV_CLOSE
It’s not a problem of tested or untested of the example. Your shell has a syntax, you have to know how to escape quotes and double quotes in your command interpreter, it is a matter of your platform, your OS.
Search the forum, probably someone posted how to do it
Thanks for the info…
I have created a test application base on the http-fetch example.
I pretty much confirmed the limitation by printing out heap size on each state of the HTTP event.
The heap memory will not be “freed” until MG_EV_CLOSE The page I need to access has 12KB from the MG_EV_HTTP_CHUNK. Making it difficult to keep copy before it can pass to JSON decoding.
The UART is not fast enough to send data before it reach the MG_EV_CLOSE. So, it have to store the data before sending.