Send UART data while HTTP active

#1

If you are asking a question, please follow this template:

  1. My goal is:
    [Send received data from MG_EV_HTTP_CHUNK to UART]
  2. 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;
]

  1. 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.
    ]
  2. 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.
    ]
#2

Have a look at the http-fetch example.

#4

I build and load “htt-fetch” example. when I run the code, it has error… anything I missed ??
in order to have it works on ESP8266 ?

mos build --platform esp8266

mos call Fetch ‘{“url”: “http://mongoose-os.com/downloads/mos/version.json”, “uart”: 0}’

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

#5

It looks like you are on Windows. There might be some escaping issues with it.
Sorry, I can’t help.

#6

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

case MG_EV_HTTP_CHUNK:
LOG(LL_INFO, (“mgos_get_free_heap_size : %d”, mgos_get_free_heap_size()));
LOG(LL_INFO, (“mgos_get_min_free_heap_size : %d”, mgos_get_min_free_heap_size()));
connect->flags |= MG_F_DELETE_CHUNK;
break;

#7

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

#8

I mean these… because you get this

In bash under Linux we usually use a backslash to escape those double quotes needed to write stringified JSON

#9

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.

mgos_get_free_heap_size()
mgos_get_min_free_heap_size()

  1. 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.

  2. 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.

#10

Found a solution:

Probably something like this

mos call Fetch "{\"url\":\"http://mongoose-os.com/downloads/mos/version.json\", "uart\":0}"