WiFi Handler component  1.0
WiFi Handler component for open authenticator.
Classes | Macros | Typedefs | Functions
wifi_handler_station.h File Reference
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_pm.h"
#include "cJSON.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
Include dependency graph for wifi_handler_station.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  wifi_station_info
 stores information about wifi access point More...
 

Macros

#define WIFI_RECONNECT_RETRY_ATTEMPTS   2
 
#define WIFI_SSID_MAX_LENGTH   32
 
#define WIFI_PASS_MAX_LENGTH   64
 
#define WIFI_MAX_STATIONS   10
 
#define WIFI_MAX_STATION_INFO_STRING_SIZE   1040
 
#define WIFI_CONNECTED_BIT   BIT0
 
#define WIFI_FAIL_BIT   BIT1
 
#define WIFI_ERR_NOT_CONNECTED   -2
 
#define WIFI_ERR_ALREADY_RUNNING   -3
 
#define WIFI_ERR_STA_INFO   -4
 

Typedefs

typedef struct wifi_station_info wifi_station_info_t
 stores information about wifi access point More...
 

Functions

wifi_ap_record_t * get_wifi_station_info ()
 Gets the information about the currently connected access point. More...
 
esp_err_t start_wifi_station (char *wifi_station_info_json)
 starts wifi and connects to access points which are passed as json string to this function More...
 
esp_err_t stop_wifi_station ()
 disconnects from currently connected AP and turns off wifi More...
 

Macro Definition Documentation

◆ WIFI_CONNECTED_BIT

#define WIFI_CONNECTED_BIT   BIT0

used in event group, this bit represents connected bit

◆ WIFI_ERR_ALREADY_RUNNING

#define WIFI_ERR_ALREADY_RUNNING   -3

error code if wifi is already running and start_wifi_station() is called

◆ WIFI_ERR_NOT_CONNECTED

#define WIFI_ERR_NOT_CONNECTED   -2

error code if wifi failed to connect to any of the stored networks

◆ WIFI_ERR_STA_INFO

#define WIFI_ERR_STA_INFO   -4

error code if wifi_station_info_json passed is invalid or larger than expected value

◆ WIFI_FAIL_BIT

#define WIFI_FAIL_BIT   BIT1

used in event group, this bit represents the disconnected bit

◆ WIFI_MAX_STATION_INFO_STRING_SIZE

#define WIFI_MAX_STATION_INFO_STRING_SIZE   1040

max size of station info string

◆ WIFI_MAX_STATIONS

#define WIFI_MAX_STATIONS   10

max number of wifi stations to try to connect

◆ WIFI_PASS_MAX_LENGTH

#define WIFI_PASS_MAX_LENGTH   64

◆ WIFI_RECONNECT_RETRY_ATTEMPTS

#define WIFI_RECONNECT_RETRY_ATTEMPTS   2

number of times to try to reconnect to same wifi ssid

◆ WIFI_SSID_MAX_LENGTH

#define WIFI_SSID_MAX_LENGTH   32

Typedef Documentation

◆ wifi_station_info_t

stores information about wifi access point

Function Documentation

◆ get_wifi_station_info()

wifi_ap_record_t* get_wifi_station_info ( )

Gets the information about the currently connected access point.

Returns
wifi_ap_record_t* returns pointer to a static instance of wifi_ap_record_t, if esp32 is not connected to any access point, it return NULL

◆ start_wifi_station()

esp_err_t start_wifi_station ( char *  wifi_station_info_json)

starts wifi and connects to access points which are passed as json string to this function

wifi_station_info_json --> json structure is as follows:

{ "c": 3 (max 10, int, set by macro WIFI_MAX_STATIONS), "s": ["hello", "bye", "df"], "p": ["fakee", "nice", "ddddfs"] }

these ssid and pass are corresponding according to their array location, i.e pass of ssid[0] = pass[0] and so on

Flow of this function is as follows: 1) Tries to connect to the first wifi AP specified in the json string 1.1) If connected successfully return ESP_OK 1.2) If fails, then tries to reconnect, keeps on trying WIFI_RECONNECT_RETRY_ATTEMPTS times 1.2.1) If connected successfully return ESP_OK 1.2.2) If fails after retrying WIFI_RECONNECT_RETRY_ATTEMPTS times, fetches new wifi ssid from json string and goes back to step 1) 2) If it failed to connect to all wifi APs from the json string return ESP_FAIL

Parameters
wifi_station_info_jsonjson string which contains information about number of AP to which to try to connect to, and also their ssid and passwords
Returns
esp_err_t ESP_OK if connected successfully, WIFI_ERR_ALREADY_RUNNING if wifi is already running, WIFI_ERR_STA_INFO if the given station info is incorrect, WIFI_ERR_NOT_CONNECTED if it couldn't connect to any wifi network given in the list

◆ stop_wifi_station()

esp_err_t stop_wifi_station ( )

disconnects from currently connected AP and turns off wifi

Returns
esp_err_t ESP_OK