feat: implement Wi-Fi provisioning and persistent configuration
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#ifndef MAZE32_NETWORK_H
|
||||
#define MAZE32_NETWORK_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_netif.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "maze32_wifi_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAZE32_WIFI_SCAN_LIMIT 8U
|
||||
|
||||
typedef enum {
|
||||
MAZE32_NETWORK_BOOTING = 0,
|
||||
MAZE32_NETWORK_STATION_CONNECTING,
|
||||
MAZE32_NETWORK_STATION_CONNECTED,
|
||||
MAZE32_NETWORK_PROVISIONING,
|
||||
MAZE32_NETWORK_ERROR,
|
||||
} maze32_network_state_t;
|
||||
|
||||
typedef struct {
|
||||
char ssid[MAZE32_WIFI_SSID_MAX_BYTES + 1U];
|
||||
int8_t rssi;
|
||||
uint8_t auth_mode;
|
||||
} maze32_wifi_scan_result_t;
|
||||
|
||||
typedef struct {
|
||||
EventGroupHandle_t events;
|
||||
SemaphoreHandle_t operation_mutex;
|
||||
esp_netif_t *station_netif;
|
||||
esp_netif_t *access_point_netif;
|
||||
volatile maze32_network_state_t state;
|
||||
unsigned int retry_count;
|
||||
char access_point_ssid[24];
|
||||
maze32_reconfiguration_guard_fn reconfiguration_guard;
|
||||
void *guard_context;
|
||||
httpd_handle_t server;
|
||||
} maze32_network_t;
|
||||
|
||||
esp_err_t maze32_network_init(maze32_network_t *network,
|
||||
maze32_reconfiguration_guard_fn guard,
|
||||
void *guard_context);
|
||||
esp_err_t maze32_network_start(maze32_network_t *network);
|
||||
esp_err_t maze32_network_apply_credentials(maze32_network_t *network,
|
||||
const maze32_wifi_credentials_t *credentials);
|
||||
esp_err_t maze32_network_reset_credentials(maze32_network_t *network);
|
||||
void maze32_network_retry_saved_credentials(void *context);
|
||||
void maze32_network_return_to_provisioning(void *context);
|
||||
esp_err_t maze32_network_scan(maze32_network_t *network,
|
||||
maze32_wifi_scan_result_t *results,
|
||||
size_t capacity,
|
||||
size_t *count);
|
||||
maze32_network_state_t maze32_network_state(const maze32_network_t *network);
|
||||
const char *maze32_network_state_name(maze32_network_state_t state);
|
||||
const char *maze32_network_access_point_ssid(const maze32_network_t *network);
|
||||
esp_err_t maze32_network_ip_address(const maze32_network_t *network,
|
||||
char *output,
|
||||
size_t output_size);
|
||||
esp_err_t maze32_provisioning_register(httpd_handle_t server, maze32_network_t *network);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MAZE32_PROVISIONING_PROTOCOL_H
|
||||
#define MAZE32_PROVISIONING_PROTOCOL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "maze32_wifi_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int maze32_provisioning_parse_credentials(const char *body,
|
||||
size_t length,
|
||||
maze32_wifi_credentials_t *credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user