Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Cfg.set( { wifi: { ap: { enable: false } } }); in C ?

edited August 2 in Mongoose OS

Trying to turn off AP after wifi connected -- find below the code but does not work- unable to figure out what is wrong

#ifdef MGOS_HAVE_WIFI
  #include mgos_wifi.h
  #endif
#ifdef MGOS_HAVE_WIFI
static void wifi_cb(int ev, void *evd, void *arg) {
  switch (ev) {
    case MGOS_WIFI_EV_STA_DISCONNECTED:
      LOG(LL_INFO, ("WiFi STA disconnected %p", arg));
      break;
    case MGOS_WIFI_EV_STA_CONNECTING:
      LOG(LL_INFO, ("WiFi STA connecting %p", arg));
      break;
    case MGOS_WIFI_EV_STA_CONNECTED:
    ev= MGOS_WIFI_CONNECTED;
  ap_cfg.enable = false;
  mgos_sys_config_set_wifi_ap_enable(false);
    save_cfg(&mgos_sys_config, NULL);
  if (!mgos_wifi_setup_ap(&ap_cfg)) {
       LOG(LL_ERROR, ("AP off"));
      }
    break;
}
      LOG(LL_INFO, ("WiFi STA connected %p", arg));
      break;
      case MGOS_WIFI_EV_STA_IP_ACQUIRED:
       struct mgos_config_wifi_ap ap_cfg;
    memcpy(&ap_cfg, mgos_sys_config_get_wifi_ap(), sizeof(ap_cfg));
      ap_cfg.enable = false;
      mgos_sys_config_set_wifi_ap_enable(false);
      save_cfg(&mgos_sys_config, NULL);
       if (!mgos_wifi_setup_ap(&ap_cfg)) {
  LOG(LL_ERROR, ("AP setup failed"));
}  
       mgos_system_restart(0);

  }
      break;
    case MGOS_WIFI_EV_AP_STA_CONNECTED: {
      struct mgos_wifi_ap_sta_connected_arg *aa =
          (struct mgos_wifi_ap_sta_connected_arg *) evd;
      LOG(LL_INFO, ("WiFi AP STA connected MAC %02x:%02x:%02x:%02x:%02x:%02x",
                    aa->mac[0], aa->mac[1], aa->mac[2], aa->mac[3], aa->mac[4],
                    aa->mac[5]));
      break;
    }
    case MGOS_WIFI_EV_AP_STA_DISCONNECTED: {
      struct mgos_wifi_ap_sta_disconnected_arg *aa =
          (struct mgos_wifi_ap_sta_disconnected_arg *) evd;
      LOG(LL_INFO,
          ("WiFi AP STA disconnected MAC %02x:%02x:%02x:%02x:%02x:%02x",
           aa->mac[0], aa->mac[1], aa->mac[2], aa->mac[3], aa->mac[4],
           aa->mac[5]));
      break;
    }
  }
  (void) arg;
}
#endif /* MGOS_HAVE_WIFI */


#ifdef MGOS_HAVE_WIFI
  mgos_event_add_group_handler(MGOS_WIFI_EV_BASE, wifi_cb, NULL);
#endif
Sign In or Register to comment.