Adding an Event handler for "HTTP GET" to API using mg_connect_http?


Hello everyone,
Having an issue with sending data to an API on the web.

  1. My goal is:
    To send a HTTP GET to an API, only need the send an URL.

  2. My actions are:
    I have been looking at the post:
    I am not great at C and I am having trouble understanding how to use/create the event handler.

This is the code I have added:

struct mg_connection *mg_connect_http(

    struct mg_mgr *mgr,

    MG_CB(mg_event_handler_t event_handler, void *user_data), apiUrl, NULL, NULL);

    mg_connect_http(mgos_get_mgr(), event_handler, apiUrl, NULL, NULL);
  1. The result I see is:
    My code wont build.

  2. My expectation & question is:
    A full example of creating the event handler and using it to do a HTTP GET would be awesome.

Thanks in advance,


Simple application to get leap-seconds.list from

1 Like

Awesome! It works! Thanks!

Now the URL is “called” at boot.
I don’'t really understand the code, how do I “call” the URL again? Do I need to execute:
mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, net_event_handler, NULL);
Every time I want to send something to the API (the URL)?

I read the sensor, I then want to call an the API URL ++ “field0=newValue”. If that makes sense.

Kind regards and thanks again,


This is what you need.


Ah, that is the call to the URL?
I will test that! Thanks!