Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

New Event Handlers?

jonwjonw USA
edited January 2018 in Mongoose OS

Now that mgos_net_add_event_handler is depreciated, and events are being handled differently now, how do I create an application specific callback or event handler? If I wanted to disable WiFi on an Ethernet Connect Event, how do I add a handler to catch the Ethernet Connect Event?


  • jonwjonw USA
    edited January 2018

    I received an answer to my question on Gitter:

    Event group callbacks are now used for handling events on the application level using mgos_event_add_group_handler
    Event groups are defined in their respective modules.
    Event data is passed as pointer evd, which points to the event data defined in that specific module.

    Using network events as an example, this is how you would register your own callback:

        static void net_cb(int ev, void *evd, void *arg) {
          switch (ev) {
            case MGOS_NET_EV_DISCONNECTED:
              LOG(LL_INFO, ("%s", "Net disconnected"));
            case MGOS_NET_EV_CONNECTING:
              LOG(LL_INFO, ("%s", "Net connecting..."));
            case MGOS_NET_EV_CONNECTED:
              LOG(LL_INFO, ("%s", "Net connected"));
            case MGOS_NET_EV_IP_ACQUIRED:
              LOG(LL_INFO, ("%s", "Net got IP address"));
      (void) evd;
      (void) arg;
        mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, net_cb, NULL);

    MGOS_EVENT_GRP_NET group is defined in the network module
    The event APIs are defined in mgos_event.h
    *evd for this group, is a pointer to struct mgos_net_event_data, which is defined in the network module (containing interface type, interface instance, and IP information)

Sign In or Register to comment.