ESP-LiveControl  1.99.1
HTTP server, AJAX API backend and Vue.js web application implementing self-contained, zero-install WiFi remote control of hardware modules attached to the Espressif ESP32 SoC
wifi_configurator.hpp
Go to the documentation of this file.
1 
6 #ifndef WIFI_CONFIGURATOR_HPP__
7 #define WIFI_CONFIGURATOR_HPP__
8 
9 #include "nvs.h"
10 
11 #include <DNSServer.h>
12 
13 #include <ESPAsyncWebServer.h>
14 #include "ArduinoJson.h"
15 #include "AsyncJson.h"
16 
17 #include "app_state_model.hpp"
18 
19 
36 {
37 public:
39  AsyncWebServer *http_backend,
40  DNSServer *dns_server);
41 
43 
49  void begin();
50 
51  void print_ap_info();
52  void print_station_info();
53 
54 private:
55  AppState &state;
56  AsyncWebServer *http_backend;
57  DNSServer *dns_server;
58 
59  nvs_handle_t _nvs_handle;
60  uint8_t _restart_counter = 0;
61 
62  // ESPAsyncWebServer HTTP request handler for WiFi configuration API endpoint
63  AsyncCallbackJsonWebHandler *_http_request_handler = nullptr;
64 
65  void _counting_device_restart();
66 
67  esp_err_t _restore_state_from_nvs(NetworkConfig &conf);
68  esp_err_t _save_state_to_nvs(NetworkConfig &conf);
69 
70  bool _reconnect_ap_mode(NetworkConfig &conf);
71  bool _reconnect_station_mode(NetworkConfig &conf);
72 
73  // Looks up if current state says this is AP or station mode and calls
74  // _configure and _reconnect for the respective mode
75  bool _reconfigure_reconnect_network_interface(NetworkConfig &conf);
76 
77  bool _configure_station_mode(NetworkConfig &conf);
78  bool _configure_ap_mode(NetworkConfig &conf);
79 
80  bool _on_request_do_configuration(JsonObject &json_obj, AsyncWebServerRequest *request);
81 
82  // On request, send configuration JSON encoded as HTTP body
83  void _send_config_response(NetworkConfig &conf, AsyncWebServerRequest *request);
84 
85  // Register all application HTTP GET API callbacks into the HTPP server
86  void _register_http_api();
87 
88  // Configure a DNSServer instance
89  void _setup_dns_server();
90 
91  // Optionally, configure MDNS server
92  void _setup_mdns_server();
93 };
94 
95 #endif /* WIFI_CONFIGURATOR_HPP__ */
Reconnect to or set up a WiFi network connection.
Definition: wifi_configurator.hpp:36
void begin()
Reconnect to or set up a WiFi network connection.
Definition: wifi_configurator.cpp:62
Application state containing data and settings model.
Definition: app_state_model.hpp:50
WiFi network configuration structure with default values.
Definition: app_config.hpp:34