Files
maze32/components/maze32_network/include/maze32_network.h
T

74 lines
2.4 KiB
C

#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