enhancement: new "config" module to access configuration in RAM

This is to allow moving some tasks/stack memory to SPIRAM, saving on
precious IRAM. HTTP server should also be more responsive.
This commit is contained in:
Sebastien
2019-11-06 23:31:13 -05:00
parent 86f0d4c7ea
commit cdbb198d8a
38 changed files with 1219 additions and 510 deletions

View File

@@ -91,7 +91,7 @@ static nvs_type_t str_to_type(const char *type)
return NVS_TYPE_ANY;
}
static const char *type_to_str(nvs_type_t type)
const char *type_to_str(nvs_type_t type)
{
for (int i = 0; i < TYPE_STR_PAIR_SIZE; i++) {
const type_str_pair_t *p = &type_str_pair[i];

View File

@@ -7,6 +7,7 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#include "nvs_flash.h"
#ifdef __cplusplus
extern "C" {
@@ -14,7 +15,7 @@ extern "C" {
// Register NVS functions
void register_nvs();
const char *type_to_str(nvs_type_t type);
#ifdef __cplusplus
}
#endif

View File

@@ -27,6 +27,7 @@
#include "esp_partition.h"
#include "esp_ota_ops.h"
#include "platform_esp32.h"
#include "nvs_utilities.h"
#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
#define WITH_TASKS_INFO 1
@@ -126,6 +127,9 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
}
esp_partition_iterator_release(it);
if(bFound) {
if(!wait_for_commit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
ESP_LOGI(TAG, "Restarting!.");
esp_restart();
}
@@ -136,6 +140,9 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
static int restart(int argc, char **argv)
{
if(!wait_for_commit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
ESP_LOGW(TAG, "Restarting");
esp_restart();
return 0;
@@ -143,6 +150,10 @@ static int restart(int argc, char **argv)
void simple_restart()
{
if(!wait_for_commit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
ESP_LOGW(TAG, "Restarting");
esp_restart();
}

View File

@@ -9,3 +9,4 @@
COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/main/
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/components/tools/

View File

@@ -402,7 +402,7 @@ void bt_sink_init(bt_cmd_cb_t cmd_cb, bt_data_cb_t data_cb)
*/
esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
char * pin_code = get_nvs_value_alloc_default(NVS_TYPE_STR, "bt_sink_pin", STR(CONFIG_BT_SINK_PIN), 0);
char * pin_code = config_alloc_get_default(NVS_TYPE_STR, "bt_sink_pin", STR(CONFIG_BT_SINK_PIN), 0);
if(strlen(pin_code)>ESP_BT_PIN_CODE_LEN){
ESP_LOGW(BT_AV_TAG, "BT Sink pin code [%s] too long. ", pin_code);
@@ -487,7 +487,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
switch (event) {
case BT_APP_EVT_STACK_UP: {
/* set up device name */
bt_name = (char * )get_nvs_value_alloc_default(NVS_TYPE_STR, "bt_name", CONFIG_BT_NAME, 0);
bt_name = (char * )config_alloc_get_default(NVS_TYPE_STR, "bt_name", CONFIG_BT_NAME, 0);
esp_bt_dev_set_device_name(bt_name);
free(bt_name);
esp_bt_gap_register_callback(bt_app_gap_cb);

View File

@@ -166,7 +166,7 @@ void hal_bluetooth_init(const char * options)
}
if(squeezelite_args.sink_name->count == 0)
{
squeezelite_conf.sink_name = get_nvs_value_alloc_default(NVS_TYPE_STR, "a2dp_sink_name", CONFIG_A2DP_SINK_NAME, 0);
squeezelite_conf.sink_name = config_alloc_get_default(NVS_TYPE_STR, "a2dp_sink_name", CONFIG_A2DP_SINK_NAME, 0);
if(squeezelite_conf.sink_name == NULL){
ESP_LOGW(TAG,"Unable to retrieve the a2dp sink name from nvs");
squeezelite_conf.sink_name = strdup(CONFIG_A2DP_SINK_NAME);
@@ -511,7 +511,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
/* set up device name */
char * a2dp_dev_name = get_nvs_value_alloc_default(NVS_TYPE_STR, "a2dp_dev_name", CONFIG_A2DP_DEV_NAME, 0);
char * a2dp_dev_name = config_alloc_get_default(NVS_TYPE_STR, "a2dp_dev_name", CONFIG_A2DP_DEV_NAME, 0);
if(a2dp_dev_name == NULL){
ESP_LOGW(TAG,"Unable to retrieve the a2dp device name from nvs");
esp_bt_dev_set_device_name(CONFIG_A2DP_DEV_NAME);

View File

@@ -9,4 +9,5 @@
COMPONENT_ADD_INCLUDEDIRS := .
CFLAGS += -Os -DPOSIX -DLINKALL -DLOOPBACK -DNO_FAAD -DEMBEDDED -DTREMOR_ONLY -DBYTES_PER_FRAME=4
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
#CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_INFO

View File

@@ -50,7 +50,7 @@ static void vCallbackFunction( TimerHandle_t xTimer ) {
}
bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
if (!leds[idx].gpio) return false;
if (!leds[idx].gpio || leds[idx].gpio<0 ) return false;
ESP_LOGD(TAG,"led_blink_core");
if (leds[idx].timer) {
@@ -96,7 +96,7 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
}
bool led_unpush(int idx) {
if (!leds[idx].gpio) return false;
if (!leds[idx].gpio || leds[idx].gpio<0) return false;
led_blink_core(idx, leds[idx].pushedon, leds[idx].pushedoff, true);
leds[idx].pushed = false;
@@ -105,6 +105,10 @@ bool led_unpush(int idx) {
}
bool led_config(int idx, gpio_num_t gpio, int onstate) {
if(gpio<0){
ESP_LOGW(TAG,"LED GPIO not configured");
return false;
}
ESP_LOGD(TAG,"Index %d, GPIO %d, on state %s", idx, gpio, onstate>0?"On":"Off");
if (idx >= MAX_LED) return false;
leds[idx].gpio = gpio;

View File

@@ -56,7 +56,7 @@ void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) {
ESP_ERROR_CHECK( mdns_init() );
ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
char * sink_name_buffer= (char *)get_nvs_value_alloc(NVS_TYPE_STR, "airplay_name");
char * sink_name_buffer= (char *)config_alloc_get(NVS_TYPE_STR, "airplay_name");
if(sink_name_buffer != NULL){
memset(sink_name, 0x00, sizeof(sink_name));
strncpy(sink_name,sink_name_buffer,sizeof(sink_name)-1 );

View File

@@ -8,6 +8,6 @@ COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_ADD_INCLUDEDIRS += include
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/main/
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/components/tools
CFLAGS += -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCONFIG_OTA_ALLOW_HTTP=1
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_INFO -DCONFIG_OTA_ALLOW_HTTP=1
#CFLAGS += -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCONFIG_OTA_ALLOW_HTTP=1
COMPONENT_EMBED_TXTFILES := ${PROJECT_PATH}/server_certs/github.pem

View File

@@ -329,7 +329,7 @@ esp_err_t process_recovery_ota(const char * bin_url){
#define OTA_CORE 0
#warning "OTA will run on core 0"
#else
#warning "OTA will run on core 1"
#pragma message "OTA will run on core 1"
#define OTA_CORE 1
#endif
ESP_LOGI(TAG, "Starting ota on core %u for : %s", OTA_CORE,urlPtr);
@@ -343,12 +343,20 @@ esp_err_t process_recovery_ota(const char * bin_url){
esp_err_t start_ota(const char * bin_url, bool bFromAppMain)
{
// uint8_t * get_nvs_value_alloc_default(NVS_TYPE_BLOB, "certs", server_cert_pem_start , server_cert_pem_end-server_cert_pem_start);
// uint8_t * config_alloc_get_default(NVS_TYPE_BLOB, "certs", server_cert_pem_start , server_cert_pem_end-server_cert_pem_start);
#if RECOVERY_APPLICATION
return process_recovery_ota(bin_url);
#else
ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url);
store_nvs_value(NVS_TYPE_STR, "fwurl", bin_url);
if(config_set_value(NVS_TYPE_STR, "fwurl", bin_url) != ESP_OK){
ESP_LOGE(TAG,"Failed to save the OTA url into nvs cache");
return ESP_FAIL;
}
if(!wait_for_commit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
return guided_factory();
return ESP_OK;

View File

@@ -289,14 +289,17 @@ $(document).ready(function(){
var val = $(this).val();
if (key != '') {
headers["X-Custom-"+key] = val;
data[key] = val;
data[key] = {};
data[key].value = val;
data[key].type = 33;
}
});
var key = $("#nvs-new-key").val();
var val = $("#nvs-new-value").val();
if (key != '') {
headers["X-Custom-"+key] = val;
data[key] = val;
data[key] = {};
data[key].value = val;
}
$.ajax({
url: '/config.json',
@@ -454,7 +457,7 @@ $(document).ready(function(){
//start timers
startCheckStatusInterval();
startRefreshAPInterval();
//startRefreshAPInterval();
$('[data-toggle="tooltip"]').tooltip({
html: true,
@@ -718,16 +721,16 @@ function getConfig() {
Object.keys(data).sort().forEach(function(key, i) {
if (data.hasOwnProperty(key)) {
if (key == 'autoexec') {
if (data["autoexec"] === "1") {
if (data["autoexec"].value === "1") {
$("#autoexec-cb")[0].checked=true;
} else {
$("#autoexec-cb")[0].checked=false;
}
} else if (key == 'autoexec1') {
$("textarea#autoexec1").val(data[key]);
$("textarea#autoexec1").val(data[key].value);
} else if (key == 'host_name') {
$("dhcp-name1").val(data[key]);
$("dhcp-name2").val(data[key]);
$("dhcp-name1").val(data[key].value);
$("dhcp-name2").val(data[key].value);
}
$("tbody#nvsTable").append(
@@ -738,7 +741,7 @@ function getConfig() {
"</td>"+
"</tr>"
);
$("input#"+key).val(data[key]);
$("input#"+key).val(data[key].value);
}
});
$("tbody#nvsTable").append(

View File

@@ -7,7 +7,8 @@
# please read the SDK documents if you need to do this.
#
COMPONENT_EMBED_FILES := style.css code.js index.html bootstrap.min.css.gz jquery.min.js.gz popper.min.js.gz bootstrap.min.js.gz
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG \
#CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_INFO \
-I$(COMPONENT_PATH)/../tools
COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_ADD_INCLUDEDIRS += $(COMPONENT_PATH)/../tools

View File

@@ -42,9 +42,8 @@ function to process requests, decode URLs, serve files, etc. etc.
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "config.h"
#define NVS_PARTITION_NAME "nvs"
#define NUM_BUFFER_LEN 101
/* @brief tag used for ESP serial console messages */
static const char TAG[] = "http_server";
@@ -87,7 +86,7 @@ const static char http_redirect_hdr_end[] = "/\n\n";
void http_server_start() {
ESP_LOGD(TAG,"http_server_start ");
ESP_LOGD(TAG, "http_server_start ");
if(task_http_server == NULL) {
xTaskCreate(&http_server, "http_server", 1024*5, NULL, WIFI_MANAGER_TASK_PRIORITY, &task_http_server);
}
@@ -99,7 +98,7 @@ void http_server(void *pvParameters) {
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, 80);
netconn_listen(conn);
ESP_LOGI(TAG, "HTTP Server listening on 80/tcp");
ESP_LOGI(TAG, "HTTP Server listening on 80/tcp");
do {
err = netconn_accept(conn, &newconn);
if(err == ERR_OK) {
@@ -108,7 +107,7 @@ void http_server(void *pvParameters) {
}
else
{
ESP_LOGE(TAG,"Error accepting new connection. Terminating HTTP server");
ESP_LOGE(TAG, "Error accepting new connection. Terminating HTTP server");
}
taskYIELD(); /* allows the freeRTOS scheduler to take over if needed. */
} while(err == ERR_OK);
@@ -144,7 +143,7 @@ char* http_server_search_header(char *request, char *header_name, int *len, char
char *ptr = NULL;
int currentLength=0;
ESP_LOGV(TAG, "searching for header name: [%s]", header_name);
ESP_LOGV(TAG, "searching for header name: [%s]", header_name);
ptr = strstr(request, header_name);
@@ -152,23 +151,23 @@ char* http_server_search_header(char *request, char *header_name, int *len, char
ret = ptr + strlen(header_name);
ptr = ret;
currentLength=(int)(ptr-request);
ESP_LOGV(TAG, "found string at %d", currentLength);
ESP_LOGV(TAG, "found string at %d", currentLength);
while (*ptr != '\0' && *ptr != '\n' && *ptr != '\r' && *ptr != ':' && ptr<bufEnd) {
ptr++;
}
if(*ptr==':') {
currentLength=(int)(ptr-ret);
ESP_LOGV(TAG, "Found parameter name end, length : %d", currentLength);
ESP_LOGV(TAG, "Found parameter name end, length : %d", currentLength);
// save the parameter name: the string between header name and ":"
*parm_name=malloc(currentLength+1);
if(*parm_name==NULL) {
ESP_LOGE(TAG, "Unable to allocate memory for new header name");
ESP_LOGE(TAG, "Unable to allocate memory for new header name");
return NULL;
}
memset(*parm_name, 0x00,currentLength+1);
strncpy(*parm_name,ret,currentLength);
ESP_LOGV(TAG, "Found parameter name : %s ", *parm_name);
ESP_LOGV(TAG, "Found parameter name : %s ", *parm_name);
ptr++;
while (*ptr == ' ' && ptr<bufEnd) {
ptr++;
@@ -183,12 +182,12 @@ char* http_server_search_header(char *request, char *header_name, int *len, char
// Terminate value inside its actual buffer so we can treat it as individual string
*ptr='\0';
currentLength=(int)(ptr-ret);
ESP_LOGV(TAG, "Found parameter value end, length : %d, value: %s", currentLength,ret );
ESP_LOGV(TAG, "Found parameter value end, length : %d, value: %s", currentLength,ret );
*next_position=++ptr;
return ret;
}
ESP_LOGD(TAG, "No more match for : %s", header_name);
ESP_LOGD(TAG, "No more match for : %s", header_name);
return NULL;
}
void http_server_send_resource_file(struct netconn *conn,const uint8_t * start, const uint8_t * end, char * content_type,char * encoding) {
@@ -196,7 +195,7 @@ void http_server_send_resource_file(struct netconn *conn,const uint8_t * start,
size_t buff_length= sizeof(http_hdr_template)+strlen(content_type)+strlen(encoding);
char * http_hdr=malloc(buff_length);
if( http_hdr == NULL) {
ESP_LOGE(TAG,"Cound not allocate %d bytes for headers.",buff_length);
ESP_LOGE(TAG, "Cound not allocate %d bytes for headers.",buff_length);
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
}
else
@@ -204,73 +203,25 @@ void http_server_send_resource_file(struct netconn *conn,const uint8_t * start,
memset(http_hdr,0x00,buff_length);
snprintf(http_hdr, buff_length-1,http_hdr_template,content_type,len,encoding);
netconn_write(conn, http_hdr, strlen(http_hdr), NETCONN_NOCOPY);
ESP_LOGD(TAG,"sending response : %s",http_hdr);
ESP_LOGD(TAG, "sending response : %s",http_hdr);
netconn_write(conn, start, end - start, NETCONN_NOCOPY);
free(http_hdr);
}
}
err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type) {
nvs_entry_info_t info;
char * num_buffer = NULL;
cJSON * nvs_json = cJSON_CreateObject();
num_buffer = malloc(NUM_BUFFER_LEN);
nvs_iterator_t it = nvs_entry_find(settings_partition, NULL, nvs_type);
if(it == NULL) {
ESP_LOGW(TAG, "No nvs entry found in %s",NVS_PARTITION_NAME );
err_t http_server_send_config_json(struct netconn *conn) {
char * json = config_alloc_get_json(false);
if(json!=NULL){
ESP_LOGD(TAG, "config json : %s",json );
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
netconn_write(conn, json, strlen(json), NETCONN_NOCOPY);
free(json);
}
while (it != NULL) {
nvs_entry_info(it, &info);
memset(num_buffer,0x00,NUM_BUFFER_LEN);
if(strstr(info.namespace_name, current_namespace)) {
void * value = get_nvs_value_alloc(nvs_type,info.key);
if(value==NULL)
{
ESP_LOGE(TAG,"nvs read failed.");
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY); //200ok
free(num_buffer);
cJSON_Delete(nvs_json);
return ESP_FAIL;
}
switch (nvs_type) {
case NVS_TYPE_I8:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%i", *(int8_t*)value);
break;
case NVS_TYPE_I16:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%i", *(int16_t*)value);
break;
case NVS_TYPE_I32:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%i", *(int32_t*)value);
break;
case NVS_TYPE_U8:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%u", *(uint8_t*)value);
break;
case NVS_TYPE_U16:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%u", *(uint16_t*)value);
break;
case NVS_TYPE_U32:
snprintf(num_buffer, NUM_BUFFER_LEN-1, "%u", *(uint32_t*)value);
break;
case NVS_TYPE_STR:
// string will be processed directly below
break;
case NVS_TYPE_I64:
case NVS_TYPE_U64:
default:
ESP_LOGE(TAG, "nvs type %u not supported", nvs_type);
break;
}
cJSON_AddItemToObject(nvs_json, info.key, cJSON_CreateString((nvs_type==NVS_TYPE_STR)?(char *)value:num_buffer));
free(value );
}
it = nvs_entry_next(it);
else{
ESP_LOGD(TAG, "Error retrieving config json string. ");
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
}
ESP_LOGD(TAG,"config json : %s\n", cJSON_Print(nvs_json));
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
netconn_write(conn, cJSON_Print(nvs_json), strlen(cJSON_Print(nvs_json)), NETCONN_NOCOPY);
cJSON_Delete(nvs_json);
free(num_buffer);
return ESP_OK;
}
@@ -285,8 +236,8 @@ void http_server_process_config(struct netconn *conn, char *inbuf) {
// /* extract the first line of the request */
// char *save_ptr = buf;
// char *line = strtok_r(save_ptr, new_line, &save_ptr);
// ESP_LOGD(TAG,"Processing line %s",line);
ESP_LOGD(TAG,"Processing request buffer: \n%s",inbuf);
// ESP_LOGD(TAG, "Processing line %s",line);
ESP_LOGD(TAG, "Processing request buffer: \n%s",inbuf);
char *last = NULL;
char *ptr = NULL;
last = ptr = inbuf;
@@ -299,7 +250,7 @@ void http_server_process_config(struct netconn *conn, char *inbuf) {
}
// terminate the header string
if( *(ptr) == '\0' ) {
ESP_LOGD(TAG, "End of buffer found");
ESP_LOGD(TAG, "End of buffer found");
return;
}
*ptr = '\0';
@@ -308,21 +259,21 @@ void http_server_process_config(struct netconn *conn, char *inbuf) {
ptr+=2;
}
if(ptr==last) {
ESP_LOGD(TAG,"Processing body. ");
ESP_LOGD(TAG, "Processing body. ");
break;
}
if(strlen(last)>0) {
ESP_LOGD(TAG,"Found Header Line %s ", last);
ESP_LOGD(TAG, "Found Header Line %s ", last);
//Content-Type: application/json
}
else {
ESP_LOGD(TAG,"Found end of headers");
ESP_LOGD(TAG, "Found end of headers");
bHeaders = false;
}
last=ptr;
}
else {
//ESP_LOGD(TAG,"Body content: %s", last);
//ESP_LOGD(TAG, "Body content: %s", last);
//cJSON * json = cJSON_Parse(last);
//cJSON_Delete(json);
//todo: implement body json parsing
@@ -336,13 +287,13 @@ void http_server_process_config(struct netconn *conn, char *inbuf) {
void dump_net_buffer(void * buf, u16_t buflen) {
char * curbuf = malloc(buflen+1);
ESP_LOGD(TAG,"netconn buffer, length=%u",buflen);
ESP_LOGV(TAG, "netconn buffer, length=%u",buflen);
if(curbuf==NULL) {
ESP_LOGE(TAG,"Unable to show netconn buffer. Malloc failed");
ESP_LOGE(TAG, "Unable to show netconn buffer. Malloc failed");
}
memset(curbuf,0x0, buflen+1);
memcpy(curbuf,buf,buflen);
ESP_LOGV(TAG,"netconn buffer content:\n%s",curbuf);
ESP_LOGV(TAG, "netconn buffer content:\n%s",curbuf);
free(curbuf);
}
@@ -354,22 +305,22 @@ void http_server_netconn_serve(struct netconn *conn) {
err_t err;
ip_addr_t remote_add;
u16_t port;
ESP_LOGD(TAG,"Serving page. Getting device AP address.");
ESP_LOGV(TAG, "Serving page. Getting device AP address.");
const char new_line[2] = "\n";
char * ap_ip_address= get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0);
char * ap_ip_address= config_alloc_get_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0);
if(ap_ip_address==NULL){
ESP_LOGE(TAG,"Unable to retrieve default AP IP Address");
ESP_LOGE(TAG, "Unable to retrieve default AP IP Address");
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
netconn_close(conn);
return;
}
ESP_LOGD(TAG,"Getting remote device IP address.");
ESP_LOGV(TAG, "Getting remote device IP address.");
netconn_getaddr(conn, &remote_add, &port, 0);
char * remote_address = strdup(ip4addr_ntoa(ip_2_ip4(&remote_add)));
ESP_LOGD(TAG,"Local Access Point IP address is: %s. Remote device IP address is %s. Receiving request buffer", ap_ip_address, remote_address);
ESP_LOGD(TAG, "Local Access Point IP address is: %s. Remote device IP address is %s. Receiving request buffer", ap_ip_address, remote_address);
err = netconn_recv(conn, &inbuf);
if(err == ERR_OK) {
ESP_LOGD(TAG,"Getting data buffer.");
ESP_LOGV(TAG, "Getting data buffer.");
netbuf_data(inbuf, (void**)&buf, &buflen);
dump_net_buffer(buf, buflen);
int lenH = 0;
@@ -382,14 +333,14 @@ void http_server_netconn_serve(struct netconn *conn) {
if(lenH>0){
strlcpy(host,temphost,lenH+1);
}
ESP_LOGD(TAG,"http_server_netconn_serve Host: [%s], host: [%s], Processing line [%s]",remote_address,host,line);
ESP_LOGD(TAG, "http_server_netconn_serve Host: [%s], host: [%s], Processing line [%s]",remote_address,host,line);
if(line) {
/* captive portal functionality: redirect to access point IP for HOST that are not the access point IP OR the STA IP */
const char * host_name=NULL;
if((err=tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &host_name )) !=ESP_OK) {
ESP_LOGE(TAG,"Unable to get host name. Error: %s",esp_err_to_name(err));
ESP_LOGE(TAG, "Unable to get host name. Error: %s",esp_err_to_name(err));
}
/* determine if Host is from the STA IP address */
@@ -399,7 +350,7 @@ void http_server_netconn_serve(struct netconn *conn) {
bool access_from_host_name = (host_name!=NULL) && strstr(host, host_name);
if(lenH > 0 && !strstr(host, ap_ip_address) && !(access_from_sta_ip || access_from_host_name)) {
ESP_LOGI(TAG,"Redirecting host [%s] to AP IP Address : %s",remote_address, ap_ip_address);
ESP_LOGI(TAG, "Redirecting host [%s] to AP IP Address : %s",remote_address, ap_ip_address);
netconn_write(conn, http_redirect_hdr_start, sizeof(http_redirect_hdr_start) - 1, NETCONN_NOCOPY);
netconn_write(conn, ap_ip_address, strlen(ap_ip_address), NETCONN_NOCOPY);
netconn_write(conn, http_redirect_hdr_end, sizeof(http_redirect_hdr_end) - 1, NETCONN_NOCOPY);
@@ -433,32 +384,43 @@ void http_server_netconn_serve(struct netconn *conn) {
}
//dynamic stuff
else if(strstr(line, "GET /scan.json ")) {
ESP_LOGI(TAG, "Starting wifi scan");
wifi_manager_scan_async();
}
else if(strstr(line, "GET /ap.json ")) {
/* if we can get the mutex, write the last version of the AP list */
ESP_LOGI(TAG,"Processing ap.json request");
ESP_LOGI(TAG, "Processing ap.json request");
if(wifi_manager_lock_json_buffer(( TickType_t ) 10)) {
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
char *buff = wifi_manager_get_ap_list_json();
netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
char *buff = wifi_manager_alloc_get_ap_list_json();
wifi_manager_unlock_json_buffer();
if(buff!=NULL){
netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
free(buff);
}
else {
ESP_LOGD(TAG, "Error retrieving ap list json string. ");
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
}
}
else {
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
ESP_LOGE(TAG, "http_server_netconn_serve: GET /ap.json failed to obtain mutex");
ESP_LOGE(TAG, "http_server_netconn_serve: GET /ap.json failed to obtain mutex");
}
/* request a wifi scan */
ESP_LOGI(TAG,"Starting wifi scan");
ESP_LOGI(TAG, "Starting wifi scan");
wifi_manager_scan_async();
ESP_LOGI(TAG,"Done serving ap.json");
ESP_LOGI(TAG, "Done serving ap.json");
}
else if(strstr(line, "GET /config.json ")) {
ESP_LOGI(TAG,"Serving config.json");
ESP_LOGI(TAG, "About to get config from flash");
http_server_nvs_dump(conn,NVS_TYPE_STR);
ESP_LOGD(TAG,"Done serving config.json");
ESP_LOGI(TAG, "Serving config.json");
ESP_LOGI(TAG, "About to get config from flash");
http_server_send_config_json(conn);
ESP_LOGD(TAG, "Done serving config.json");
}
else if(strstr(line, "POST /config.json ")) {
ESP_LOGI(TAG,"Serving POST config.json");
ESP_LOGI(TAG, "Serving POST config.json");
int lenA=0;
char * last_parm=save_ptr;
char * next_parm=save_ptr;
@@ -471,20 +433,21 @@ void http_server_netconn_serve(struct netconn *conn) {
while(last_parm!=NULL) {
// Search will return
ESP_LOGD(TAG, "Getting parameters from X-Custom headers");
ESP_LOGD(TAG, "Getting parameters from X-Custom headers");
last_parm = http_server_search_header(next_parm, "X-Custom-", &lenA, &last_parm_name,&next_parm,buf+buflen);
if(last_parm!=NULL && last_parm_name!=NULL) {
ESP_LOGI(TAG, "http_server_netconn_serve: POST config.json, config %s=%s", last_parm_name, last_parm);
ESP_LOGI(TAG, "http_server_netconn_serve: POST config.json, config %s=%s", last_parm_name, last_parm);
if(strcmp(last_parm_name, "fwurl")==0) {
// we're getting a request to do an OTA from that URL
ESP_LOGW(TAG, "Found OTA request!");
ESP_LOGW(TAG, "Found OTA request!");
otaURL=strdup(last_parm);
bOTA=true;
}
else {
ESP_LOGV(TAG, "http_server_netconn_serve: POST config.json Storing parameter");
err= store_nvs_value(NVS_TYPE_STR, last_parm_name , last_parm);
if(err!=ESP_OK) ESP_LOGE(TAG,"Unable to save nvs value. Error: %s",esp_err_to_name(err));
ESP_LOGV(TAG, "http_server_netconn_serve: POST config.json Storing parameter");
if(config_set_value(NVS_TYPE_STR, last_parm_name , last_parm) != ESP_OK){
ESP_LOGE(TAG, "Unable to save nvs value.");
}
}
}
if(last_parm_name!=NULL) {
@@ -498,10 +461,11 @@ void http_server_netconn_serve(struct netconn *conn) {
else {
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); //200ok
if(bOTA) {
#if RECOVERY_APPLICATION
ESP_LOGW(TAG, "Starting process OTA for url %s",otaURL);
ESP_LOGW(TAG, "Starting process OTA for url %s",otaURL);
#else
ESP_LOGW(TAG, "Restarting system to process OTA for url %s",otaURL);
ESP_LOGW(TAG, "Restarting system to process OTA for url %s",otaURL);
// close the connection cleanly
netconn_close(conn);
netconn_delete(conn);
@@ -510,97 +474,109 @@ void http_server_netconn_serve(struct netconn *conn) {
free(otaURL);
}
}
ESP_LOGI(TAG,"Done Serving POST config.json");
ESP_LOGI(TAG, "Done Serving POST config.json");
}
else if(strstr(line, "POST /connect.json ")) {
ESP_LOGI(TAG, "http_server_netconn_serve: POST /connect.json");
ESP_LOGI(TAG, "http_server_netconn_serve: POST /connect.json");
bool found = false;
int lenS = 0, lenP = 0;
int lenS = 0, lenP = 0, lenN = 0;
char *ssid = NULL, *password = NULL;
ssid = http_server_get_header(save_ptr, "X-Custom-ssid: ", &lenS);
password = http_server_get_header(save_ptr, "X-Custom-pwd: ", &lenP);
char * new_host_name_b = http_server_get_header(save_ptr, "X-Custom-host_name: ", &lenN);
if(lenN > 0){
lenN++;
char * new_host_name = malloc(lenN);
strlcpy(new_host_name, new_host_name_b, lenN);
if(config_set_value(NVS_TYPE_STR, "host_name", new_host_name) != ESP_OK){
ESP_LOGE(TAG, "Unable to save host name configuration");
}
free(new_host_name);
}
if(ssid && lenS <= MAX_SSID_SIZE && password && lenP <= MAX_PASSWORD_SIZE) {
wifi_config_t* config = wifi_manager_get_wifi_sta_config();
memset(config, 0x00, sizeof(wifi_config_t));
memcpy(config->sta.ssid, ssid, lenS);
memcpy(config->sta.password, password, lenP);
ESP_LOGD(TAG, "http_server_netconn_serve: wifi_manager_connect_async() call, with ssid: %s, password: %s", config->sta.ssid, config->sta.password);
ESP_LOGD(TAG, "http_server_netconn_serve: wifi_manager_connect_async() call, with ssid: %s, password: %s", config->sta.ssid, config->sta.password);
wifi_manager_connect_async();
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); //200ok
found = true;
}
else{
ESP_LOGE(TAG,"SSID or Password invalid");
ESP_LOGE(TAG, "SSID or Password invalid");
}
if(!found) {
/* bad request the authentification header is not complete/not the correct format */
netconn_write(conn, http_400_hdr, sizeof(http_400_hdr) - 1, NETCONN_NOCOPY);
ESP_LOGE(TAG, "bad request the authentification header is not complete/not the correct format");
ESP_LOGE(TAG, "bad request the authentification header is not complete/not the correct format");
}
ESP_LOGI(TAG, "http_server_netconn_serve: done serving connect.json");
ESP_LOGI(TAG, "http_server_netconn_serve: done serving connect.json");
}
else if(strstr(line, "DELETE /connect.json ")) {
ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json");
ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json");
/* request a disconnection from wifi and forget about it */
wifi_manager_disconnect_async();
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
ESP_LOGI(TAG, "http_server_netconn_serve: done serving DELETE /connect.json");
ESP_LOGI(TAG, "http_server_netconn_serve: done serving DELETE /connect.json");
}
else if(strstr(line, "POST /reboot_ota.json ")) {
ESP_LOGI(TAG, "http_server_netconn_serve: POST reboot.json");
ESP_LOGI(TAG, "http_server_netconn_serve: POST reboot.json");
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
netconn_close(conn);
netconn_delete(conn);
guided_restart_ota();
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST reboot.json");
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST reboot.json");
}
else if(strstr(line, "POST /reboot.json ")) {
ESP_LOGI(TAG, "http_server_netconn_serve: POST restart.json");
ESP_LOGI(TAG, "http_server_netconn_serve: POST restart.json");
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
netconn_close(conn);
netconn_delete(conn);
simple_restart();
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST restart.json");
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST restart.json");
}
else if(strstr(line, "POST /recovery.json ")) {
ESP_LOGI(TAG, "http_server_netconn_serve: POST recovery.json");
ESP_LOGI(TAG, "http_server_netconn_serve: POST recovery.json");
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
netconn_close(conn);
netconn_delete(conn);
guided_factory();
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST recovery.json");
ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST recovery.json");
}
else if(strstr(line, "GET /status.json ")) {
ESP_LOGI(TAG,"Serving status.json");
ESP_LOGI(TAG, "Serving status.json");
if(wifi_manager_lock_json_buffer(( TickType_t ) 10)) {
char *buff = wifi_manager_get_ip_info_json();
char *buff = wifi_manager_alloc_get_ip_info_json();
wifi_manager_unlock_json_buffer();
if(buff) {
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
free(buff);
}
else {
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
}
wifi_manager_unlock_json_buffer();
}
else {
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
}
ESP_LOGI(TAG,"Done Serving status.json");
ESP_LOGI(TAG, "Done Serving status.json");
}
else {
netconn_write(conn, http_400_hdr, sizeof(http_400_hdr) - 1, NETCONN_NOCOPY);
ESP_LOGE(TAG, "bad request from host: %s, request %s",remote_address, line);
ESP_LOGE(TAG, "bad request from host: %s, request %s",remote_address, line);
}
}
}
else {
ESP_LOGE(TAG, "URL not found processing for remote host : %s",remote_address);
ESP_LOGE(TAG, "URL not found processing for remote host : %s",remote_address);
netconn_write(conn, http_404_hdr, sizeof(http_404_hdr) - 1, NETCONN_NOCOPY);
}
free(host);
@@ -616,26 +592,26 @@ void http_server_netconn_serve(struct netconn *conn) {
}
bool http_server_lock_json_object(TickType_t xTicksToWait) {
ESP_LOGD(TAG,"Locking config json object");
ESP_LOGD(TAG, "Locking config json object");
if(http_server_config_mutex) {
if( xSemaphoreTake( http_server_config_mutex, xTicksToWait ) == pdTRUE ) {
ESP_LOGV(TAG,"config Json object locked!");
ESP_LOGV(TAG, "config Json object locked!");
return true;
}
else {
ESP_LOGW(TAG,"Semaphore take failed. Unable to lock config Json object mutex");
ESP_LOGW(TAG, "Semaphore take failed. Unable to lock config Json object mutex");
return false;
}
}
else {
ESP_LOGW(TAG,"Unable to lock config Json object mutex");
ESP_LOGW(TAG, "Unable to lock config Json object mutex");
return false;
}
}
void http_server_unlock_json_object() {
ESP_LOGD(TAG,"Unlocking json buffer!");
ESP_LOGD(TAG, "Unlocking json buffer!");
xSemaphoreGive( http_server_config_mutex );
}

View File

@@ -87,7 +87,6 @@ uint16_t ap_num = MAX_AP_NUM;
wifi_ap_record_t *accessp_records=NULL;
cJSON * accessp_cjson=NULL;
char *ip_info_json = NULL;
char *host_name = NULL;
char * release_url=NULL;
cJSON * ip_info_cjson=NULL;
wifi_config_t* wifi_manager_config_sta = NULL;
@@ -189,7 +188,22 @@ char * get_disconnect_code_desc(uint8_t reason){
}
return "";
}
void set_host_name(){
esp_err_t err;
ESP_LOGD(TAG, "Retrieving host name from nvs");
char * host_name = (char * )config_alloc_get(NVS_TYPE_STR, "host_name");
if(host_name ==NULL){
ESP_LOGE(TAG, "Could not retrieve host name from nvs");
}
else {
ESP_LOGD(TAG, "Setting host name to : %s",host_name);
if((err=tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, host_name)) !=ESP_OK){
ESP_LOGE(TAG, "Unable to set host name. Error: %s",esp_err_to_name(err));
}
free(host_name);
}
}
bool isGroupBitSet(uint8_t bit){
EventBits_t uxBits= xEventGroupGetBits(wifi_manager_event_group);
@@ -210,85 +224,76 @@ void wifi_manager_disconnect_async(){
void wifi_manager_init_wifi(){
/* event handler and event group for the wifi driver */
ESP_LOGD(TAG, "Initializing wifi. Creating event group");
ESP_LOGD(TAG, "Initializing wifi. Creating event group");
wifi_manager_event_group = xEventGroupCreate();
bHasConnected=false;
// Now Initialize the Wifi Stack
ESP_LOGD(TAG, "Initializing wifi. Initializing tcp_ip adapter");
ESP_LOGD(TAG, "Initializing wifi. Initializing tcp_ip adapter");
tcpip_adapter_init();
ESP_LOGD(TAG, "Initializing wifi. Creating the default event loop");
ESP_LOGD(TAG, "Initializing wifi. Creating the default event loop");
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_LOGD(TAG, "Initializing wifi. Getting default wifi configuration");
ESP_LOGD(TAG, "Initializing wifi. Getting default wifi configuration");
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGD(TAG, "Initializing wifi. Initializing wifi. ");
ESP_LOGD(TAG, "Initializing wifi. Initializing wifi. ");
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_LOGD(TAG, "Initializing wifi. Calling register handlers");
ESP_LOGD(TAG, "Initializing wifi. Calling register handlers");
wifi_manager_register_handlers();
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi storage as RAM");
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi storage as RAM");
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi mode to WIFI_MODE_NULL");
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi mode to WIFI_MODE_NULL");
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
ESP_LOGD(TAG, "Initializing wifi. Starting wifi");
ESP_LOGD(TAG, "Initializing wifi. Starting wifi");
ESP_ERROR_CHECK( esp_wifi_start() );
taskYIELD(); /* allows the freeRTOS scheduler to take over if needed. */
ESP_LOGD(TAG, "Initializing wifi. done");
taskYIELD();
ESP_LOGD(TAG, "Initializing wifi. done");
}
void wifi_manager_start(){
/* memory allocation */
ESP_LOGD(TAG, "wifi_manager_start. Creating message queue");
ESP_LOGD(TAG, "wifi_manager_start. Creating message queue");
wifi_manager_queue = xQueueCreate( 3, sizeof( queue_message) );
ESP_LOGD(TAG, "wifi_manager_start. Creating mutexes");
ESP_LOGD(TAG, "wifi_manager_start. Creating mutexes");
wifi_manager_json_mutex = xSemaphoreCreateMutex();
wifi_manager_sta_ip_mutex = xSemaphoreCreateMutex();
ESP_LOGD(TAG, "wifi_manager_start. Creating access point json structure");
ESP_LOGD(TAG, "wifi_manager_start. Creating access point json structure");
accessp_cjson = NULL;
accessp_cjson = wifi_manager_clear_ap_list_json(&accessp_cjson);
ip_info_json = NULL;
ESP_LOGD(TAG, "wifi_manager_start. Creating status jcon structure");
ESP_LOGD(TAG, "wifi_manager_start. Creating status jcon structure");
ip_info_cjson = wifi_manager_clear_ip_info_json(&ip_info_cjson);
ESP_LOGD(TAG, "wifi_manager_start. Allocating memory for wifi configuration structure");
ESP_LOGD(TAG, "wifi_manager_start. Allocating memory for wifi configuration structure");
wifi_manager_config_sta = (wifi_config_t*)malloc(sizeof(wifi_config_t));
memset(wifi_manager_config_sta, 0x00, sizeof(wifi_config_t));
// memset(&wifi_settings, 0x00, sizeof(wifi_settings));
ESP_LOGD(TAG, "wifi_manager_start. Allocating memory for callback functions registration");
ESP_LOGD(TAG, "wifi_manager_start. Allocating memory for callback functions registration");
cb_ptr_arr = malloc( sizeof( sizeof( void (*)( void* ) )) * MESSAGE_CODE_COUNT);
for(int i=0; i<MESSAGE_CODE_COUNT; i++){
cb_ptr_arr[i] = NULL;
}
ESP_LOGD(TAG, "About to set the STA IP String to 0.0.0.0");
ESP_LOGD(TAG, "About to set the STA IP String to 0.0.0.0");
wifi_manager_sta_ip = (char*)malloc(sizeof(char) * IP4ADDR_STRLEN_MAX);
wifi_manager_safe_update_sta_ip_string(NULL);
ESP_LOGD(TAG, "Retrieving host name from nvs");
host_name = (char * )get_nvs_value_alloc_default(NVS_TYPE_STR, "host_name", "squeezelite-esp32", 0);
if(host_name ==NULL){
ESP_LOGE(TAG, "Could not retrieve host name from nvs");
}
else {
ESP_LOGD(TAG, "Found host name %s ", host_name);
}
ESP_LOGD(TAG, "Getting release url ");
char * release_url = (char * )get_nvs_value_alloc_default(NVS_TYPE_STR, "release_url", QUOTE(SQUEEZELITE_ESP32_RELEASE_URL), 0);
ESP_LOGD(TAG, "Getting release url ");
char * release_url = (char * )config_alloc_get_default(NVS_TYPE_STR, "release_url", QUOTE(SQUEEZELITE_ESP32_RELEASE_URL), 0);
if(release_url == NULL){
ESP_LOGE(TAG,"Unable to retrieve the release url from nvs");
ESP_LOGE(TAG, "Unable to retrieve the release url from nvs");
}
else {
ESP_LOGD(TAG, "Found release url %s", release_url);
ESP_LOGD(TAG, "Found release url %s", release_url);
}
ESP_LOGD(TAG, "About to call init wifi");
ESP_LOGD(TAG, "About to call init wifi");
wifi_manager_init_wifi();
/* start wifi manager task */
ESP_LOGD(TAG, "Creating wifi manager task");
ESP_LOGD(TAG, "Creating wifi manager task");
xTaskCreate(&wifi_manager, "wifi_manager", 4096, NULL, WIFI_MANAGER_TASK_PRIORITY, &task_wifi_manager);
}
@@ -296,80 +301,74 @@ void wifi_manager_start(){
esp_err_t wifi_manager_save_sta_config(){
nvs_handle handle;
esp_err_t esp_err;
ESP_LOGI(TAG, "About to save config to flash");
ESP_LOGI(TAG, "About to save config to flash");
if(wifi_manager_config_sta){
esp_err = nvs_open(wifi_manager_nvs_namespace, NVS_READWRITE, &handle);
if (esp_err != ESP_OK) {
ESP_LOGE(TAG,"Unable to open name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
ESP_LOGE(TAG, "Unable to open name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
return esp_err;
}
esp_err = nvs_set_blob(handle, "ssid", wifi_manager_config_sta->sta.ssid, sizeof(wifi_manager_config_sta->sta.ssid));
if (esp_err != ESP_OK) {
ESP_LOGE(TAG,"Unable to save ssid in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
ESP_LOGE(TAG, "Unable to save ssid in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
return esp_err;
}
esp_err = nvs_set_blob(handle, "password", wifi_manager_config_sta->sta.password, sizeof(wifi_manager_config_sta->sta.password));
if (esp_err != ESP_OK) {
ESP_LOGE(TAG,"Unable to save password in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
ESP_LOGE(TAG, "Unable to save password in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
return esp_err;
}
// esp_err = nvs_set_blob(handle, "settings", &wifi_settings, sizeof(wifi_settings));
// if (esp_err != ESP_OK) {
// ESP_LOGE(TAG,"Unable to save wifi_settings in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
// ESP_LOGE(TAG, "Unable to save wifi_settings in name namespace %s. Error %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
// return esp_err;
// }
esp_err = nvs_commit(handle);
if (esp_err != ESP_OK) {
ESP_LOGE(TAG,"Unable to commit changes. Error %s", esp_err_to_name(esp_err));
ESP_LOGE(TAG, "Unable to commit changes. Error %s", esp_err_to_name(esp_err));
return esp_err;
}
nvs_close(handle);
ESP_LOGD(TAG, "wifi_manager_wrote wifi_sta_config: ssid:%s password:%s",wifi_manager_config_sta->sta.ssid,wifi_manager_config_sta->sta.password);
// ESP_LOGD(TAG, "wifi_manager_wrote wifi_settings: sta_static_ip (0 = dhcp client, 1 = static ip): %i",wifi_settings.sta_static_ip);
// ESP_LOGD(TAG, "wifi_manager_wrote wifi_settings: sta_ip_addr: %s", ip4addr_ntoa(&wifi_settings.sta_static_ip_config.ip));
// ESP_LOGD(TAG, "wifi_manager_wrote wifi_settings: sta_gw_addr: %s", ip4addr_ntoa(&wifi_settings.sta_static_ip_config.gw));
// ESP_LOGD(TAG, "wifi_manager_wrote wifi_settings: sta_netmask: %s", ip4addr_ntoa(&wifi_settings.sta_static_ip_config.netmask));
ESP_LOGD(TAG, "wifi_manager_wrote wifi_sta_config: ssid:%s password:%s",wifi_manager_config_sta->sta.ssid,wifi_manager_config_sta->sta.password);
}
return ESP_OK;
}
#define RETRIEVE_CONFIG_STRING_VALUE(name,def,var) value = get_nvs_value_alloc_default(NVS_TYPE_STR, name, def, 0); if(value!=NULL){ strlcpy(var, value, sizeof(var)); free(value); value=NULL;}
bool wifi_manager_fetch_wifi_sta_config(){
nvs_handle handle;
esp_err_t esp_err;
ESP_LOGD(TAG,"Fetching wifi sta config.");
if(nvs_open(wifi_manager_nvs_namespace, NVS_READONLY, &handle) == ESP_OK){
ESP_LOGD(TAG, "Fetching wifi sta config.");
esp_err=nvs_open(wifi_manager_nvs_namespace, NVS_READONLY, &handle);
if(esp_err == ESP_OK){
if(wifi_manager_config_sta == NULL){
ESP_LOGD(TAG,"Allocating memory for structure.");
ESP_LOGD(TAG, "Allocating memory for structure.");
wifi_manager_config_sta = (wifi_config_t*)malloc(sizeof(wifi_config_t));
}
memset(wifi_manager_config_sta, 0x00, sizeof(wifi_config_t));
/* ssid */
ESP_LOGD(TAG,"Fetching value for ssid.");
ESP_LOGD(TAG, "Fetching value for ssid.");
size_t sz = sizeof(wifi_manager_config_sta->sta.ssid);
uint8_t *buff = (uint8_t*)malloc(sizeof(uint8_t) * sz);
memset(buff,0x00,sizeof(uint8_t) * sz);
esp_err = nvs_get_blob(handle, "ssid", buff, &sz);
if(esp_err != ESP_OK){
ESP_LOGI(TAG,"No ssid found in nvs.");
free(buff);
ESP_LOGI(TAG, "No ssid found in nvs.");
FREE_AND_NULL(buff);
nvs_close(handle);
return false;
}
memcpy(wifi_manager_config_sta->sta.ssid, buff, sizeof(wifi_manager_config_sta->sta.ssid));
FREE_AND_NULL(buff);
ESP_LOGI(TAG, "wifi_manager_fetch_wifi_sta_config: ssid:%s ",wifi_manager_config_sta->sta.ssid);
ESP_LOGI(TAG, "wifi_manager_fetch_wifi_sta_config: ssid:%s ",wifi_manager_config_sta->sta.ssid);
/* password */
sz = sizeof(wifi_manager_config_sta->sta.password);
@@ -378,11 +377,11 @@ bool wifi_manager_fetch_wifi_sta_config(){
esp_err = nvs_get_blob(handle, "password", buff, &sz);
if(esp_err != ESP_OK){
// Don't take this as an error. This could be an opened access point?
ESP_LOGW(TAG,"No wifi password found in nvs");
ESP_LOGW(TAG, "No wifi password found in nvs");
}
else {
memcpy(wifi_manager_config_sta->sta.password, buff, sizeof(wifi_manager_config_sta->sta.password));
ESP_LOGI(TAG, "wifi_manager_fetch_wifi_sta_config: password:%s",wifi_manager_config_sta->sta.password);
ESP_LOGI(TAG, "wifi_manager_fetch_wifi_sta_config: password:%s",wifi_manager_config_sta->sta.password);
}
FREE_AND_NULL(buff);
nvs_close(handle);
@@ -390,35 +389,35 @@ bool wifi_manager_fetch_wifi_sta_config(){
return wifi_manager_config_sta->sta.ssid[0] != '\0';
}
else{
ESP_LOGE(TAG,"Failed to open nvs namespace %s.",wifi_manager_nvs_namespace);
ESP_LOGW(TAG, "wifi manager has no previous configuration. %s",esp_err_to_name(esp_err));
return false;
}
}
cJSON * wifi_manager_get_new_json(cJSON **old){
ESP_LOGD(TAG,"wifi_manager_get_new_json called");
ESP_LOGV(TAG, "wifi_manager_get_new_json called");
cJSON * root=*old;
if(root!=NULL){
cJSON_Delete(root);
*old=NULL;
}
ESP_LOGD(TAG,"wifi_manager_get_new_json done");
ESP_LOGV(TAG, "wifi_manager_get_new_json done");
return cJSON_CreateObject();
}
cJSON * wifi_manager_get_new_array_json(cJSON **old){
ESP_LOGD(TAG,"wifi_manager_get_new_array_json called");
ESP_LOGV(TAG, "wifi_manager_get_new_array_json called");
cJSON * root=*old;
if(root!=NULL){
cJSON_Delete(root);
*old=NULL;
}
ESP_LOGD(TAG,"wifi_manager_get_new_array_json done");
ESP_LOGV(TAG, "wifi_manager_get_new_array_json done");
return cJSON_CreateArray();
}
cJSON * wifi_manager_get_basic_info(cJSON **old){
const esp_app_desc_t* desc = esp_ota_get_app_description();
ESP_LOGD(TAG,"wifi_manager_get_basic_info called");
ESP_LOGV(TAG, "wifi_manager_get_basic_info called");
cJSON *root = wifi_manager_get_new_json(old);
cJSON_AddItemToObject(root, "project_name", cJSON_CreateString(desc->project_name));
cJSON_AddItemToObject(root, "version", cJSON_CreateString(desc->version));
@@ -431,26 +430,26 @@ cJSON * wifi_manager_get_basic_info(cJSON **old){
cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect );
cJSON_AddNumberToObject(root,"avg_conn_time", num_disconnect>0?(total_connected_time/num_disconnect):0 );
ESP_LOGV(TAG,"wifi_manager_get_basic_info done");
ESP_LOGV(TAG, "wifi_manager_get_basic_info done");
return root;
}
cJSON * wifi_manager_clear_ip_info_json(cJSON **old){
ESP_LOGV(TAG,"wifi_manager_clear_ip_info_json called");
ESP_LOGV(TAG, "wifi_manager_clear_ip_info_json called");
cJSON *root = wifi_manager_get_basic_info(old);
ESP_LOGV(TAG,"wifi_manager_clear_ip_info_json done");
ESP_LOGV(TAG, "wifi_manager_clear_ip_info_json done");
return root;
}
cJSON * wifi_manager_clear_ap_list_json(cJSON **old){
ESP_LOGV(TAG,"wifi_manager_clear_ap_list_json called");
ESP_LOGV(TAG, "wifi_manager_clear_ap_list_json called");
cJSON *root = wifi_manager_get_new_array_json(old);
ESP_LOGV(TAG,"wifi_manager_clear_ap_list_json done");
ESP_LOGV(TAG, "wifi_manager_clear_ap_list_json done");
return root;
}
void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code){
ESP_LOGD(TAG,"wifi_manager_generate_ip_info_json called");
ESP_LOGD(TAG, "wifi_manager_generate_ip_info_json called");
wifi_config_t *config = wifi_manager_get_wifi_sta_config();
ip_info_cjson = wifi_manager_get_basic_info(&ip_info_cjson);
@@ -473,7 +472,7 @@ void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code)
cJSON_AddItemToObject(ip_info_cjson, "gw", cJSON_CreateString(ip4addr_ntoa(&ip_info.gw)));
}
}
ESP_LOGV(TAG,"wifi_manager_generate_ip_info_json done");
ESP_LOGV(TAG, "wifi_manager_generate_ip_info_json done");
}
#define LOCAL_MAC_SIZE 20
char * get_mac_string(uint8_t mac[6]){
@@ -491,12 +490,12 @@ void wifi_manager_generate_access_points_json(cJSON ** ap_list){
for(int i=0; i<ap_num;i++){
cJSON * ap = cJSON_CreateObject();
if(ap == NULL) {
ESP_LOGE(TAG,"Unable to allocate memory for access point entry #%d",i);
ESP_LOGE(TAG, "Unable to allocate memory for access point entry #%d",i);
return;
}
cJSON * radio = cJSON_CreateObject();
if(radio == NULL) {
ESP_LOGE(TAG,"Unable to allocate memory for access point entry #%d",i);
ESP_LOGE(TAG, "Unable to allocate memory for access point entry #%d",i);
cJSON_Delete(ap);
return;
}
@@ -515,9 +514,18 @@ void wifi_manager_generate_access_points_json(cJSON ** ap_list){
cJSON_AddNumberToObject(radio, "low_rate", ap_rec.phy_lr?1:0);
cJSON_AddItemToObject(ap,"radio", radio);
cJSON_AddItemToArray(*ap_list, ap);
ESP_LOGD(TAG,"New access point found: %s", cJSON_Print(ap));
char * ap_json = cJSON_PrintUnformatted(ap);
if(ap_json!=NULL){
ESP_LOGD(TAG, "New access point found: %s", ap_json);
free(ap_json);
}
}
ESP_LOGV(TAG,"Full access point list: %s", cJSON_Print(*ap_list));
char * ap_list_json = cJSON_PrintUnformatted(*ap_list);
if(ap_list_json!=NULL){
ESP_LOGV(TAG, "Full access point list: %s", ap_list_json);
free(ap_list_json);
}
}
bool wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait){
@@ -542,7 +550,7 @@ void wifi_manager_unlock_sta_ip_string(){
void wifi_manager_safe_update_sta_ip_string(struct ip4_addr * ip4){
if(wifi_manager_lock_sta_ip_string(portMAX_DELAY)){
strcpy(wifi_manager_sta_ip, ip4!=NULL?ip4addr_ntoa(ip4):"0.0.0.0");
ESP_LOGI(TAG, "Set STA IP String to: %s", wifi_manager_sta_ip);
ESP_LOGI(TAG, "Set STA IP String to: %s", wifi_manager_sta_ip);
wifi_manager_unlock_sta_ip_string();
}
}
@@ -552,31 +560,31 @@ char* wifi_manager_get_sta_ip_string(){
}
bool wifi_manager_lock_json_buffer(TickType_t xTicksToWait){
ESP_LOGV(TAG,"Locking json buffer");
ESP_LOGV(TAG, "Locking json buffer");
if(wifi_manager_json_mutex){
if( xSemaphoreTake( wifi_manager_json_mutex, xTicksToWait ) == pdTRUE ) {
ESP_LOGV(TAG,"Json buffer locked!");
ESP_LOGV(TAG, "Json buffer locked!");
return true;
}
else{
ESP_LOGE(TAG,"Semaphore take failed. Unable to lock json buffer mutex");
ESP_LOGE(TAG, "Semaphore take failed. Unable to lock json buffer mutex");
return false;
}
}
else{
ESP_LOGV(TAG,"Unable to lock json buffer mutex");
ESP_LOGV(TAG, "Unable to lock json buffer mutex");
return false;
}
}
void wifi_manager_unlock_json_buffer(){
ESP_LOGV(TAG,"Unlocking json buffer!");
ESP_LOGV(TAG, "Unlocking json buffer!");
xSemaphoreGive( wifi_manager_json_mutex );
}
char* wifi_manager_get_ap_list_json(){
return cJSON_Print(accessp_cjson);
char* wifi_manager_alloc_get_ap_list_json(){
return cJSON_PrintUnformatted(accessp_cjson);
}
@@ -585,17 +593,17 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
if(event_base== WIFI_EVENT){
switch(event_id) {
case WIFI_EVENT_WIFI_READY:
ESP_LOGI(TAG, "WIFI_EVENT_WIFI_READY");
ESP_LOGI(TAG, "WIFI_EVENT_WIFI_READY");
break;
case WIFI_EVENT_SCAN_DONE:
ESP_LOGD(TAG, "WIFI_EVENT_SCAN_DONE");
ESP_LOGD(TAG, "WIFI_EVENT_SCAN_DONE");
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_SCAN_BIT);
wifi_manager_send_message(EVENT_SCAN_DONE, NULL);
break;
case WIFI_EVENT_STA_AUTHMODE_CHANGE:
ESP_LOGI(TAG, "WIFI_EVENT_STA_AUTHMODE_CHANGE");
ESP_LOGI(TAG, "WIFI_EVENT_STA_AUTHMODE_CHANGE");
// structwifi_event_sta_authmode_change_t
// Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event
//
@@ -610,12 +618,12 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
case WIFI_EVENT_AP_START:
ESP_LOGI(TAG, "WIFI_EVENT_AP_START");
ESP_LOGI(TAG, "WIFI_EVENT_AP_START");
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STARTED_BIT);
break;
case WIFI_EVENT_AP_STOP:
ESP_LOGD(TAG,"WIFI_EVENT_AP_STOP");
ESP_LOGD(TAG, "WIFI_EVENT_AP_STOP");
break;
case WIFI_EVENT_AP_PROBEREQRECVED:{
@@ -632,37 +640,37 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
wifi_event_ap_probe_req_rx_t * s =(wifi_event_ap_probe_req_rx_t*)event_data;
char * mac = get_mac_string(s->mac);
ESP_LOGD(TAG,"WIFI_EVENT_AP_PROBEREQRECVED. RSSI: %d, MAC: %s",s->rssi, STR_OR_BLANK(mac));
ESP_LOGD(TAG, "WIFI_EVENT_AP_PROBEREQRECVED. RSSI: %d, MAC: %s",s->rssi, STR_OR_BLANK(mac));
FREE_AND_NULL(mac);
}
break;
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
ESP_LOGD(TAG,"WIFI_EVENT_STA_WPS_ER_SUCCESS");
ESP_LOGD(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
break;
case WIFI_EVENT_STA_WPS_ER_FAILED:
ESP_LOGD(TAG,"WIFI_EVENT_STA_WPS_ER_FAILED");
ESP_LOGD(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
break;
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
ESP_LOGD(TAG,"WIFI_EVENT_STA_WPS_ER_TIMEOUT");
ESP_LOGD(TAG, "WIFI_EVENT_STA_WPS_ER_TIMEOUT");
break;
case WIFI_EVENT_STA_WPS_ER_PIN:
ESP_LOGD(TAG,"WIFI_EVENT_STA_WPS_ER_PIN");
ESP_LOGD(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
break;
case WIFI_EVENT_AP_STACONNECTED: /* a user disconnected from the SoftAP */
ESP_LOGI(TAG, "WIFI_EVENT_AP_STACONNECTED");
ESP_LOGI(TAG, "WIFI_EVENT_AP_STACONNECTED");
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT);
break;
case WIFI_EVENT_AP_STADISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_AP_STADISCONNECTED");
ESP_LOGI(TAG, "WIFI_EVENT_AP_STADISCONNECTED");
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT);
break;
case WIFI_EVENT_STA_START:
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
break;
case WIFI_EVENT_STA_STOP:
ESP_LOGI(TAG, "WIFI_EVENT_STA_STOP");
ESP_LOGI(TAG, "WIFI_EVENT_STA_STOP");
break;
case WIFI_EVENT_STA_CONNECTED:{
@@ -687,11 +695,11 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
// authentication mode used by AP
//, get_mac_string(EVENT_HANDLER_ARG_FIELD(wifi_event_ap_probe_req_rx_t, mac)));
ESP_LOGD(TAG, "WIFI_EVENT_STA_CONNECTED. ");
ESP_LOGD(TAG, "WIFI_EVENT_STA_CONNECTED. ");
wifi_event_sta_connected_t * s =(wifi_event_sta_connected_t*)event_data;
char * bssid = get_mac_string(s->bssid);
char * ssid = strdup((char*)s->ssid);
ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED. Channel: %d, Access point: %s, BSSID: %s ", s->channel, STR_OR_BLANK(ssid), (bssid));
ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED. Channel: %d, Access point: %s, BSSID: %s ", s->channel, STR_OR_BLANK(ssid), (bssid));
FREE_AND_NULL(bssid);
FREE_AND_NULL(ssid);
@@ -717,22 +725,22 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
// reason of disconnection
wifi_event_sta_disconnected_t * s =(wifi_event_sta_disconnected_t*)event_data;
char * bssid = get_mac_string(s->bssid);
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED. From BSSID: %s, reason code: %d (%s)", STR_OR_BLANK(bssid),s->reason, get_disconnect_code_desc(s->reason));
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED. From BSSID: %s, reason code: %d (%s)", STR_OR_BLANK(bssid),s->reason, get_disconnect_code_desc(s->reason));
FREE_AND_NULL(bssid);
if(last_connected>0) total_connected_time+=((esp_timer_get_time()-last_connected)/(1000*1000));
last_connected = 0;
num_disconnect++;
ESP_LOGW(TAG,"Wifi disconnected. Number of disconnects: %d, Average time connected: %d", num_disconnect, num_disconnect>0?(total_connected_time/num_disconnect):0);
ESP_LOGW(TAG, "Wifi disconnected. Number of disconnects: %d, Average time connected: %d", num_disconnect, num_disconnect>0?(total_connected_time/num_disconnect):0);
/* if a DISCONNECT message is posted while a scan is in progress this scan will NEVER end, causing scan to never work again. For this reason SCAN_BIT is cleared too */
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_WIFI_CONNECTED_BIT | WIFI_MANAGER_SCAN_BIT);
// We want to process this message asynchronously, so make sure we copy the event buffer
ESP_LOGD(TAG,"Preparing to trigger event EVENT_STA_DISCONNECTED ");
ESP_LOGD(TAG, "Preparing to trigger event EVENT_STA_DISCONNECTED ");
void * parm=malloc(sizeof(wifi_event_sta_disconnected_t));
memcpy(parm,event_data,sizeof(wifi_event_sta_disconnected_t));
ESP_LOGD(TAG,"Triggering EVENT_STA_DISCONNECTED ");
ESP_LOGD(TAG, "Triggering EVENT_STA_DISCONNECTED ");
/* post disconnect event with reason code */
wifi_manager_send_message(EVENT_STA_DISCONNECTED, parm );
}
@@ -766,7 +774,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
char * ip=strdup(ip4addr_ntoa(&(s->ip_info.ip)));
char * gw=strdup(ip4addr_ntoa(&(s->ip_info.gw)));
char * nm=strdup(ip4addr_ntoa(&(s->ip_info.netmask)));
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP. IP=%s, Gateway=%s, NetMask=%s, Interface: %s %s",
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP. IP=%s, Gateway=%s, NetMask=%s, Interface: %s %s",
ip,
gw,
nm,
@@ -784,16 +792,16 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
}
break;
case IP_EVENT_STA_LOST_IP:
ESP_LOGI(TAG, "IP_EVENT_STA_LOST_IP");
ESP_LOGI(TAG, "IP_EVENT_STA_LOST_IP");
break;
case IP_EVENT_AP_STAIPASSIGNED:
ESP_LOGI(TAG, "IP_EVENT_AP_STAIPASSIGNED");
ESP_LOGI(TAG, "IP_EVENT_AP_STAIPASSIGNED");
break;
case IP_EVENT_GOT_IP6:
ESP_LOGI(TAG, "IP_EVENT_GOT_IP6");
ESP_LOGI(TAG, "IP_EVENT_GOT_IP6");
break;
case IP_EVENT_ETH_GOT_IP:
ESP_LOGI(TAG, "IP_EVENT_ETH_GOT_IP");
ESP_LOGI(TAG, "IP_EVENT_ETH_GOT_IP");
break;
default:
break;
@@ -826,7 +834,7 @@ void set_status_message(message_severity_t severity, const char * message){
ip_info_cjson = wifi_manager_get_new_json(&ip_info_cjson);
}
if(ip_info_cjson==NULL){
ESP_LOGE(TAG,"Error setting status message. Unable to allocate cJSON.");
ESP_LOGE(TAG, "Error setting status message. Unable to allocate cJSON.");
return;
}
cJSON * item=cJSON_GetObjectItem(ip_info_cjson, "message");
@@ -836,14 +844,13 @@ void set_status_message(message_severity_t severity, const char * message){
}
char* wifi_manager_get_ip_info_json(){
return cJSON_Print(ip_info_cjson);
char* wifi_manager_alloc_get_ip_info_json(){
return cJSON_PrintUnformatted(ip_info_cjson);
}
void wifi_manager_destroy(){
vTaskDelete(task_wifi_manager);
task_wifi_manager = NULL;
free(host_name);
/* heap buffers */
free(ip_info_json);
free(release_url);
@@ -973,45 +980,54 @@ void wifi_manager_config_ap(){
.ssid_len = 0,
},
};
ESP_LOGD(TAG,"Configuring Access Point.");
ESP_LOGI(TAG, "Configuring Access Point.");
ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP)); /* stop AP DHCP server */
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ssid", CONFIG_DEFAULT_AP_SSID, 0);
/*
* Set access point mode IP adapter configuration
*/
value = config_alloc_get_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0);
if(value!=NULL){
strlcpy((char *)ap_config.ap.ssid, value,sizeof(ap_config.ap.ssid) );
ESP_LOGD(TAG,"AP SSID: %s", (char *)ap_config.ap.ssid);
}
FREE_AND_NULL(value);
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_pwd", DEFAULT_AP_PASSWORD, 0);
if(value!=NULL){
strlcpy((char *)ap_config.ap.password, value,sizeof(ap_config.ap.password) );
ESP_LOGD(TAG,"AP Password: %s", (char *)ap_config.ap.password);
}
FREE_AND_NULL(value);
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0);
if(value!=NULL){
ESP_LOGD(TAG,"IP Address: %s", value);
ESP_LOGI(TAG, "IP Address: %s", value);
inet_pton(AF_INET,value, &info.ip); /* access point is on a static IP */
}
FREE_AND_NULL(value);
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_gateway", CONFIG_DEFAULT_AP_GATEWAY, 0);
value = config_alloc_get_default(NVS_TYPE_STR, "ap_ip_gateway", CONFIG_DEFAULT_AP_GATEWAY, 0);
if(value!=NULL){
ESP_LOGD(TAG,"Gateway: %s", value);
ESP_LOGI(TAG, "Gateway: %s", value);
inet_pton(AF_INET,value, &info.gw); /* access point is on a static IP */
}
FREE_AND_NULL(value);
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_netmask", CONFIG_DEFAULT_AP_NETMASK, 0);
value = config_alloc_get_default(NVS_TYPE_STR, "ap_ip_netmask", CONFIG_DEFAULT_AP_NETMASK, 0);
if(value!=NULL){
ESP_LOGD(TAG,"Netmask: %s", value);
ESP_LOGI(TAG, "Netmask: %s", value);
inet_pton(AF_INET,value, &info.netmask); /* access point is on a static IP */
}
FREE_AND_NULL(value);
value = get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_channel", STR(CONFIG_DEFAULT_AP_CHANNEL), 0);
ESP_LOGD(TAG, "Setting tcp_ip info for interface TCPIP_ADAPTER_IF_AP");
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
/*
* Set Access Point configuration
*/
value = config_alloc_get_default(NVS_TYPE_STR, "ap_ssid", CONFIG_DEFAULT_AP_SSID, 0);
if(value!=NULL){
ESP_LOGD(TAG,"Channel: %s", value);
strlcpy((char *)ap_config.ap.ssid, value,sizeof(ap_config.ap.ssid) );
ESP_LOGI(TAG, "AP SSID: %s", (char *)ap_config.ap.ssid);
}
FREE_AND_NULL(value);
value = config_alloc_get_default(NVS_TYPE_STR, "ap_pwd", DEFAULT_AP_PASSWORD, 0);
if(value!=NULL){
strlcpy((char *)ap_config.ap.password, value,sizeof(ap_config.ap.password) );
ESP_LOGI(TAG, "AP Password: %s", (char *)ap_config.ap.password);
}
FREE_AND_NULL(value);
value = config_alloc_get_default(NVS_TYPE_STR, "ap_channel", STR(CONFIG_DEFAULT_AP_CHANNEL), 0);
if(value!=NULL){
ESP_LOGI(TAG, "Channel: %s", value);
ap_config.ap.channel=atoi(value);
}
FREE_AND_NULL(value);
@@ -1021,25 +1037,23 @@ void wifi_manager_config_ap(){
ap_config.ap.max_connection = DEFAULT_AP_MAX_CONNECTIONS;
ap_config.ap.beacon_interval = DEFAULT_AP_BEACON_INTERVAL;
ESP_LOGD(TAG,"Auth Mode: %d", ap_config.ap.authmode);
ESP_LOGD(TAG,"SSID Hidden: %d", ap_config.ap.ssid_hidden);
ESP_LOGD(TAG,"Max Connections: %d", ap_config.ap.max_connection);
ESP_LOGD(TAG,"Beacon interval: %d", ap_config.ap.beacon_interval);
ESP_LOGI(TAG, "Auth Mode: %d", ap_config.ap.authmode);
ESP_LOGI(TAG, "SSID Hidden: %d", ap_config.ap.ssid_hidden);
ESP_LOGI(TAG, "Max Connections: %d", ap_config.ap.max_connection);
ESP_LOGI(TAG, "Beacon interval: %d", ap_config.ap.beacon_interval);
ESP_LOGD(TAG,"Setting tcp_ip info for interface TCPIP_ADAPTER_IF_AP");
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
ESP_LOGD(TAG,"Starting dhcps on interface TCPIP_ADAPTER_IF_AP");
ESP_LOGD(TAG, "Starting dhcps on interface TCPIP_ADAPTER_IF_AP");
ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP)); /* start AP DHCP server */
ESP_LOGD(TAG,"Setting wifi mode as WIFI_MODE_APSTA");
ESP_LOGD(TAG, "Setting wifi mode as WIFI_MODE_APSTA");
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
ESP_LOGD(TAG,"Setting wifi AP configuration for WIFI_IF_AP");
ESP_LOGD(TAG, "Setting wifi AP configuration for WIFI_IF_AP");
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));
ESP_LOGD(TAG,"Setting wifi bandwidth (%d) for WIFI_IF_AP",DEFAULT_AP_BANDWIDTH);
ESP_LOGD(TAG, "Setting wifi bandwidth (%d) for WIFI_IF_AP",DEFAULT_AP_BANDWIDTH);
ESP_ERROR_CHECK(esp_wifi_set_bandwidth(WIFI_IF_AP, DEFAULT_AP_BANDWIDTH));
ESP_LOGD(TAG,"Setting wifi power save (%d) for WIFI_IF_AP",DEFAULT_STA_POWER_SAVE);
ESP_LOGD(TAG, "Setting wifi power save (%d) for WIFI_IF_AP",DEFAULT_STA_POWER_SAVE);
ESP_ERROR_CHECK(esp_wifi_set_ps(DEFAULT_STA_POWER_SAVE));
ESP_LOGD(TAG,"Done configuring Soft Access Point");
ESP_LOGD(TAG, "Done configuring Soft Access Point");
dns_server_start();
}
@@ -1065,37 +1079,37 @@ void wifi_manager( void * pvParameters ){
case EVENT_SCAN_DONE:
/* As input param, it stores max AP number ap_records can hold. As output param, it receives the actual AP number this API returns.
* As a consequence, ap_num MUST be reset to MAX_AP_NUM at every scan */
ESP_LOGD(TAG,"Getting AP list records");
ESP_LOGD(TAG, "Getting AP list records");
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_num));
if(ap_num>0){
accessp_records = (wifi_ap_record_t*)malloc(sizeof(wifi_ap_record_t) * ap_num);
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records));
/* make sure the http server isn't trying to access the list while it gets refreshed */
ESP_LOGD(TAG,"Preparing to build ap JSON list");
ESP_LOGD(TAG, "Preparing to build ap JSON list");
if(wifi_manager_lock_json_buffer( pdMS_TO_TICKS(1000) )){
/* Will remove the duplicate SSIDs from the list and update ap_num */
wifi_manager_filter_unique(accessp_records, &ap_num);
wifi_manager_generate_access_points_json(&accessp_cjson);
wifi_manager_unlock_json_buffer();
ESP_LOGD(TAG,"Done building ap JSON list");
ESP_LOGD(TAG, "Done building ap JSON list");
}
else{
ESP_LOGE(TAG, "could not get access to json mutex in wifi_scan");
ESP_LOGE(TAG, "could not get access to json mutex in wifi_scan");
}
free(accessp_records);
}
else{
//
ESP_LOGD(TAG,"No AP Found. Emptying the list.");
ESP_LOGD(TAG, "No AP Found. Emptying the list.");
accessp_cjson = wifi_manager_get_new_array_json(&accessp_cjson);
}
/* callback */
if(cb_ptr_arr[msg.code]) {
ESP_LOGD(TAG,"Invoking SCAN DONE callback");
ESP_LOGD(TAG, "Invoking SCAN DONE callback");
(*cb_ptr_arr[msg.code])(NULL);
ESP_LOGD(TAG,"Done Invoking SCAN DONE callback");
ESP_LOGD(TAG, "Done Invoking SCAN DONE callback");
}
break;
case EVENT_REFRESH_OTA:
@@ -1106,12 +1120,12 @@ void wifi_manager( void * pvParameters ){
break;
case ORDER_START_WIFI_SCAN:
ESP_LOGD(TAG, "MESSAGE: ORDER_START_WIFI_SCAN");
ESP_LOGD(TAG, "MESSAGE: ORDER_START_WIFI_SCAN");
/* if a scan is already in progress this message is simply ignored thanks to the WIFI_MANAGER_SCAN_BIT uxBit */
if(! isGroupBitSet(WIFI_MANAGER_SCAN_BIT) ){
if(esp_wifi_scan_start(&scan_config, false)!=ESP_OK){
ESP_LOGW(TAG,"Unable to start scan; wifi is trying to connect");
ESP_LOGW(TAG, "Unable to start scan; wifi is trying to connect");
// set_status_message(WARNING, "Wifi Connecting. Cannot start scan.");
}
else {
@@ -1119,7 +1133,7 @@ void wifi_manager( void * pvParameters ){
}
}
else {
ESP_LOGW(TAG,"Scan already in progress!");
ESP_LOGW(TAG, "Scan already in progress!");
}
@@ -1129,14 +1143,14 @@ void wifi_manager( void * pvParameters ){
break;
case ORDER_LOAD_AND_RESTORE_STA:
ESP_LOGI(TAG, "MESSAGE: ORDER_LOAD_AND_RESTORE_STA. About to fetch wifi STA configuration");
ESP_LOGI(TAG, "MESSAGE: ORDER_LOAD_AND_RESTORE_STA. About to fetch wifi STA configuration");
if(wifi_manager_fetch_wifi_sta_config()){
ESP_LOGI(TAG, "Saved wifi found on startup. Will attempt to connect.");
ESP_LOGI(TAG, "Saved wifi found on startup. Will attempt to connect.");
wifi_manager_send_message(ORDER_CONNECT_STA, (void*)CONNECTION_REQUEST_RESTORE_CONNECTION);
}
else{
/* no wifi saved: start soft AP! This is what should happen during a first run */
ESP_LOGI(TAG, "No saved wifi found on startup. Starting access point.");
ESP_LOGI(TAG, "No saved wifi found on startup. Starting access point.");
wifi_manager_send_message(ORDER_START_AP, NULL);
}
@@ -1146,25 +1160,25 @@ void wifi_manager( void * pvParameters ){
break;
case ORDER_CONNECT_STA:
ESP_LOGI(TAG, "MESSAGE: ORDER_CONNECT_STA - Begin");
ESP_LOGI(TAG, "MESSAGE: ORDER_CONNECT_STA - Begin");
/* very important: precise that this connection attempt is specifically requested.
* Param in that case is a boolean indicating if the request was made automatically
* by the wifi_manager.
* */
if((BaseType_t)msg.param == CONNECTION_REQUEST_USER) {
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Connection request with no nvs connection saved yet");
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Connection request with no nvs connection saved yet");
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_STA_CONNECT_BIT);
}
else if((BaseType_t)msg.param == CONNECTION_REQUEST_RESTORE_CONNECTION) {
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Connection request after restoring the AP configuration");
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Connection request after restoring the AP configuration");
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RESTORE_STA_BIT);
/* STA - Wifi Station configuration setup */
//todo: support static ip address
// if(wifi_settings.sta_static_ip) {
// // There's a static ip address configured, so
// ESP_LOGI(TAG, "Assigning static ip to STA interface. IP: %s , GW: %s , Mask: %s",
// ESP_LOGI(TAG, "Assigning static ip to STA interface. IP: %s , GW: %s , Mask: %s",
// ip4addr_ntoa(&wifi_settings.sta_static_ip_config.ip),
// ip4addr_ntoa(&wifi_settings.sta_static_ip_config.gw),
// ip4addr_ntoa(&wifi_settings.sta_static_ip_config.netmask));
@@ -1177,10 +1191,10 @@ void wifi_manager( void * pvParameters ){
// else {
/* start DHCP client if not started*/
tcpip_adapter_dhcp_status_t status;
ESP_LOGD(TAG, "wifi_manager: Checking if DHCP client for STA interface is running");
ESP_LOGD(TAG, "wifi_manager: Checking if DHCP client for STA interface is running");
ESP_ERROR_CHECK(tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status));
if (status!=TCPIP_ADAPTER_DHCP_STARTED) {
ESP_LOGI(TAG, "wifi_manager: Start DHCP client for STA interface");
ESP_LOGI(TAG, "wifi_manager: Start DHCP client for STA interface");
ESP_ERROR_CHECK(tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA));
// }
}
@@ -1188,7 +1202,7 @@ void wifi_manager( void * pvParameters ){
uxBits = xEventGroupGetBits(wifi_manager_event_group);
if( uxBits & WIFI_MANAGER_WIFI_CONNECTED_BIT ){
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Wifi connected bit set, ordering disconnect (WIFI_MANAGER_WIFI_CONNECTED_BIT)");
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - Wifi connected bit set, ordering disconnect (WIFI_MANAGER_WIFI_CONNECTED_BIT)");
wifi_manager_send_message(ORDER_DISCONNECT_STA, NULL);
/* todo: reconnect */
}
@@ -1198,16 +1212,14 @@ void wifi_manager( void * pvParameters ){
esp_wifi_get_mode(&mode);
if( WIFI_MODE_APSTA != mode && WIFI_MODE_STA !=mode ){
// the soft ap is not started, so let's set the WiFi mode to STA
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting mode WIFI_MODE_STA");
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting mode WIFI_MODE_STA");
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
}
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting config for WIFI_IF_STA");
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting config for WIFI_IF_STA");
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, wifi_manager_get_wifi_sta_config()));
ESP_LOGD(TAG,"Setting host name to : %s",host_name);
if((err=tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, host_name)) !=ESP_OK){
ESP_LOGE(TAG,"Unable to set host name. Error: %s",esp_err_to_name(err));
}
ESP_LOGI(TAG,"Wifi Connecting...");
set_host_name();
ESP_LOGI(TAG, "Wifi Connecting...");
ESP_ERROR_CHECK(esp_wifi_connect());
}
@@ -1219,14 +1231,14 @@ void wifi_manager( void * pvParameters ){
case EVENT_STA_DISCONNECTED:{
wifi_event_sta_disconnected_t disc_event;
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_DISCONNECTED");
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_DISCONNECTED");
if(msg.param == NULL){
ESP_LOGE(TAG,"MESSAGE: EVENT_STA_DISCONNECTED - expected parameter not found!");
ESP_LOGE(TAG, "MESSAGE: EVENT_STA_DISCONNECTED - expected parameter not found!");
}
else{
memcpy(&disc_event,(wifi_event_sta_disconnected_t*)msg.param,sizeof(disc_event));
free(msg.param);
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_DISCONNECTED with Reason code: %d (%s)", disc_event.reason, get_disconnect_code_desc(disc_event.reason));
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_DISCONNECTED with Reason code: %d (%s)", disc_event.reason, get_disconnect_code_desc(disc_event.reason));
}
/* this even can be posted in numerous different conditions
@@ -1286,7 +1298,7 @@ void wifi_manager( void * pvParameters ){
uxBits = xEventGroupGetBits(wifi_manager_event_group);
if( uxBits & WIFI_MANAGER_REQUEST_STA_CONNECT_BIT ){
ESP_LOGW(TAG, "WiFi Disconnected while processing user connect request. Wrong password?");
ESP_LOGW(TAG, "WiFi Disconnected while processing user connect request. Wrong password?");
/* there are no retries when it's a user requested connection by design. This avoids a user hanging too much
* in case they typed a wrong password for instance. Here we simply clear the request bit and move on */
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_STA_CONNECT_BIT);
@@ -1297,7 +1309,7 @@ void wifi_manager( void * pvParameters ){
}
else if (uxBits & WIFI_MANAGER_REQUEST_DISCONNECT_BIT){
ESP_LOGI(TAG, "WiFi disconnected by user");
ESP_LOGI(TAG, "WiFi disconnected by user");
/* user manually requested a disconnect so the lost connection is a normal event. Clear the flag and restart the AP */
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_DISCONNECT_BIT);
@@ -1308,44 +1320,37 @@ void wifi_manager( void * pvParameters ){
/* erase configuration */
if(wifi_manager_config_sta){
ESP_LOGI(TAG, "Erasing WiFi Configuration.");
ESP_LOGI(TAG, "Erasing WiFi Configuration.");
memset(wifi_manager_config_sta, 0x00, sizeof(wifi_config_t));
/* save NVS memory */
wifi_manager_save_sta_config();
}
/* start SoftAP */
ESP_LOGD(TAG, "Disconnect processing complete. Ordering an AP start.");
ESP_LOGD(TAG, "Disconnect processing complete. Ordering an AP start.");
wifi_manager_send_message(ORDER_START_AP, NULL);
}
else{
/* lost connection ? */
ESP_LOGE(TAG, "WiFi Connection lost.");
ESP_LOGE(TAG, "WiFi Connection lost.");
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){
wifi_manager_generate_ip_info_json( UPDATE_LOST_CONNECTION );
wifi_manager_unlock_json_buffer();
}
if(retries < WIFI_MANAGER_MAX_RETRY){
ESP_LOGD(TAG, "Issuing ORDER_CONNECT_STA to retry connection.");
ESP_LOGD(TAG, "Issuing ORDER_CONNECT_STA to retry connection.");
if(!bHasConnected) retries++;
wifi_manager_send_message(ORDER_CONNECT_STA, (void*)CONNECTION_REQUEST_AUTO_RECONNECT);
}
else{
/* In this scenario the connection was lost beyond repair: kick start the AP! */
retries = 0;
ESP_LOGW(TAG, "All connect retry attempts failed.");
ESP_LOGW(TAG, "All connect retry attempts failed.");
/* if it was a restore attempt connection, we clear the bit */
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RESTORE_STA_BIT);
/* erase configuration that could not be used to connect */
// if(wifi_manager_config_sta){
// ESP_LOGW(TAG, "Erasing wifi manager config.");
// memset(wifi_manager_config_sta, 0x00, sizeof(wifi_config_t));
// /* save empty connection info in NVS memory */
// wifi_manager_save_sta_config();
// }
ESP_LOGD(TAG, "Issuing ORDER_START_AP to trigger AP start.");
ESP_LOGD(TAG, "Issuing ORDER_START_AP to trigger AP start.");
/* start SoftAP */
wifi_manager_send_message(ORDER_START_AP, NULL);
}
@@ -1357,16 +1362,16 @@ void wifi_manager( void * pvParameters ){
break;
case ORDER_START_AP:
ESP_LOGI(TAG, "MESSAGE: ORDER_START_AP");
ESP_LOGI(TAG, "MESSAGE: ORDER_START_AP");
wifi_manager_config_ap();
ESP_LOGD(TAG,"AP Starting, requesting wifi scan.");
ESP_LOGD(TAG, "AP Starting, requesting wifi scan.");
wifi_manager_scan_async();
/* callback */
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
break;
case EVENT_STA_GOT_IP:
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_GOT_IP");
ESP_LOGI(TAG, "MESSAGE: EVENT_STA_GOT_IP");
uxBits = xEventGroupGetBits(wifi_manager_event_group);
@@ -1381,11 +1386,11 @@ void wifi_manager( void * pvParameters ){
/* save wifi config in NVS if it wasn't a restored of a connection */
if(uxBits & WIFI_MANAGER_REQUEST_RESTORE_STA_BIT){
ESP_LOGD(TAG,"Configuration came from nvs, no need to save.");
ESP_LOGD(TAG, "Configuration came from nvs, no need to save.");
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RESTORE_STA_BIT);
}
else{
ESP_LOGD(TAG,"Connection was initiated by user, storing config to nvs.");
ESP_LOGD(TAG, "Connection was initiated by user, storing config to nvs.");
wifi_manager_save_sta_config();
}
@@ -1396,11 +1401,11 @@ void wifi_manager( void * pvParameters ){
wifi_manager_unlock_json_buffer();
}
else {
ESP_LOGW(TAG,"Unable to lock status json buffer. ");
ESP_LOGW(TAG, "Unable to lock status json buffer. ");
}
/* bring down DNS hijack */
ESP_LOGD(TAG,"Stopping dns server.");
ESP_LOGD(TAG, "Stopping dns server.");
dns_server_stop();
bHasConnected=true;
@@ -1416,7 +1421,7 @@ void wifi_manager( void * pvParameters ){
}
break;
case ORDER_DISCONNECT_STA:
ESP_LOGI(TAG, "MESSAGE: ORDER_DISCONNECT_STA. Calling esp_wifi_disconnect()");
ESP_LOGI(TAG, "MESSAGE: ORDER_DISCONNECT_STA. Calling esp_wifi_disconnect()");
/* precise this is coming from a user request */
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_DISCONNECT_BIT);

View File

@@ -48,7 +48,7 @@ extern "C" {
#if RECOVERY_APPLICATION==1
#elif RECOVERY_APPLICATION==0
#warning "compiling for squeezelite."
#pragma message "compiling for squeezelite."
#else
#error "unknown configuration"
#endif
@@ -268,8 +268,8 @@ void filter_unique( wifi_ap_record_t * aplist, uint16_t * ap_num);
void wifi_manager( void * pvParameters );
char* wifi_manager_get_ap_list_json();
char* wifi_manager_get_ip_info_json();
char* wifi_manager_alloc_get_ap_list_json();
char* wifi_manager_alloc_get_ip_info_json();
cJSON * wifi_manager_clear_ap_list_json(cJSON **old);
/**