1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
36
37
41
42
43
44
45
46
50
51
52
53
64
65
73
74
78
79
83
84
#include <string.h>
#include <esp_log.h>
#include <esp_err.h>
#include <esp_wifi.h>
#include <protocomm.h>
#include <protocomm_console.h>
#include "wifi_provisioning/scheme_console.h"
#include "wifi_provisioning_priv.h"8 includes
static const char *TAG = "wifi_prov_scheme_console";
extern const wifi_prov_scheme_t wifi_prov_scheme_console;
static esp_err_t prov_start(protocomm_t *pc, void *config)
{
if (!pc) {
ESP_LOGE(TAG, "Protocomm handle cannot be null");
return ESP_ERR_INVALID_ARG;
}{...}
if (!config) {
ESP_LOGE(TAG, "Cannot start with null configuration");
return ESP_ERR_INVALID_ARG;
}{...}
protocomm_console_config_t *console_config = (protocomm_console_config_t *) config;
esp_err_t err = protocomm_console_start(pc, console_config);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to start protocomm HTTP server");
return ESP_FAIL;
}{...}
return ESP_OK;
}{ ... }
static void *new_config(void)
{
protocomm_console_config_t *console_config = malloc(sizeof(protocomm_console_config_t));
if (!console_config) {
ESP_LOGE(TAG, "Error allocating memory for new configuration");
return NULL;
}{...}
protocomm_console_config_t default_config = PROTOCOMM_CONSOLE_DEFAULT_CONFIG();
memcpy(console_config, &default_config, sizeof(default_config));
return console_config;
}{ ... }
static void delete_config(void *config)
{
if (!config) {
ESP_LOGE(TAG, "Cannot delete null configuration");
return;
}{...}
free(config);
}{ ... }
static esp_err_t set_config_service(void *config, const char *service_name, const char *service_key)
{
return ESP_OK;
}{ ... }
static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, uint16_t uuid)
{
return ESP_OK;
}{ ... }
const wifi_prov_scheme_t wifi_prov_scheme_console = {
.prov_start = prov_start,
.prov_stop = protocomm_console_stop,
.new_config = new_config,
.delete_config = delete_config,
.set_config_service = set_config_service,
.set_config_endpoint = set_config_endpoint,
.wifi_mode = WIFI_MODE_STA
}{...};