WiFi

struct mg_wifi_data

struct mg_wifi_data {
  char *ssid, *pass;      // STA mode, SSID to connect to
  char *apssid, *appass;  // AP mode, our SSID
  uint32_t apip, apmask;  // AP mode, our IP address and mask
  uint8_t security;       // STA mode, TBD
  uint8_t apsecurity;     // AP mode, TBD
  uint8_t apchannel;      // AP mode, channel to use
  bool apmode;  // start in AP mode; 'false' -> connect to 'ssid' != NULL
};

Structure containing STA and AP credentials and configuration. When starting up, if apmode is true, AP mode will be entered (the Access Point will start). Otherwise, if ssid is not NULL, STA mode will be entered and a connection to that SSID will be attempted.

struct mg_wifi_scan_bss_data

struct mg_wifi_scan_bss_data {
  struct mg_str SSID;
  char *BSSID;
  int16_t RSSI;
  uint8_t security;
#define MG_WIFI_SECURITY_OPEN 0
#define MG_WIFI_SECURITY_WEP MG_BIT(0)
#define MG_WIFI_SECURITY_WPA MG_BIT(1)
#define MG_WIFI_SECURITY_WPA2 MG_BIT(2)
#define MG_WIFI_SECURITY_WPA3 MG_BIT(3)
  uint8_t channel;
  unsigned band : 2;
#define MG_WIFI_BAND_2G 0
#define MG_WIFI_BAND_5G 1
  unsigned has_n : 1;
};

Structure pointed to by ev_data when calling the interface event handler as a consequence of a call to mg_wifi_scan. The MG_TCPIP_EV_WIFI_SCAN_RESULT event is triggered for each entry, and a final MG_TCPIP_EV_WIFI_SCAN_END event is generated last.

mg_wifi_scan()

bool mg_wifi_scan(void);

Initiate a scan for available Wi-Fi networks, must be called in AP mode.

mg_wifi_connect()

bool mg_wifi_connect(struct mg_wifi_data *wifi);

Connect to the desired Wi-Fi network (STA mode), as defined by the argument

mg_wifi_disconnect()

bool mg_wifi_disconnect(void);

Disconnect from the current Wi-Fi network (STA mode)

mg_wifi_ap_start()

bool mg_wifi_ap_start(struct mg_wifi_data *wifi);

Start being an Access Point (AP mode), as defined by the argument

mg_wifi_ap_stop()

bool mg_wifi_ap_stop(void);

Stop being an Access Point