mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 12:50:49 +03:00
Major refactoring. OTA Works now (yes, yes... really works! )
This commit is contained in:
@@ -11,3 +11,6 @@ CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG \
|
||||
-I$(COMPONENT_PATH)/../tools
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
COMPONENT_ADD_INCLUDEDIRS += $(COMPONENT_PATH)/../tools
|
||||
COMPONENT_ADD_INCLUDEDIRS += $(COMPONENT_PATH)/../squeezelite-ota
|
||||
COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/main/
|
||||
|
||||
|
||||
@@ -33,16 +33,19 @@ function to process requests, decode URLs, serve files, etc. etc.
|
||||
|
||||
#include "http_server.h"
|
||||
#include "cmd_system.h"
|
||||
#include "../squeezelite-ota/squeezelite-ota.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "squeezelite-ota.h"
|
||||
#include "nvs_utilities.h"
|
||||
#define NVS_PARTITION_NAME "nvs"
|
||||
|
||||
/* @brief tag used for ESP serial console messages */
|
||||
static const char TAG[] = "http_server";
|
||||
static const char json_start[] = "{ \"autoexec\": %u, \"list\": [";
|
||||
static const char json_end[] = "]}";
|
||||
static const char template[] = "{ \"%s\": \"%s\" }";
|
||||
static const char array_separator[]=",";
|
||||
static const char json_start[] = "{\n";
|
||||
static const char json_end[] = "\n}";
|
||||
static const char template[] = " \"%s\": \"%s\" ";
|
||||
static const char template_u[] = " \"%s\": %u ";
|
||||
static const char template_i[] = " \"%s\": %i ";
|
||||
static const char array_separator[]=",\n";
|
||||
static char *s = "\"";
|
||||
static char *r = "\\\"";
|
||||
/* @brief task handle for the http server */
|
||||
@@ -86,13 +89,13 @@ const static char http_redirect_hdr_end[] = "/\n\n";
|
||||
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION http_server_start(){
|
||||
void http_server_start(){
|
||||
|
||||
if(task_http_server == NULL){
|
||||
xTaskCreate(&http_server, "http_server", 1024*5, NULL, WIFI_MANAGER_TASK_PRIORITY-1, &task_http_server);
|
||||
}
|
||||
}
|
||||
void CODE_RAM_LOCATION http_server(void *pvParameters) {
|
||||
void http_server(void *pvParameters) {
|
||||
|
||||
struct netconn *conn, *newconn;
|
||||
err_t err;
|
||||
@@ -120,7 +123,7 @@ void CODE_RAM_LOCATION http_server(void *pvParameters) {
|
||||
}
|
||||
|
||||
|
||||
char* CODE_RAM_LOCATION http_server_get_header(char *request, char *header_name, int *len) {
|
||||
char* http_server_get_header(char *request, char *header_name, int *len) {
|
||||
*len = 0;
|
||||
char *ret = NULL;
|
||||
char *ptr = NULL;
|
||||
@@ -137,7 +140,7 @@ char* CODE_RAM_LOCATION http_server_get_header(char *request, char *header_name,
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
char* CODE_RAM_LOCATION http_server_search_header(char *request, char *header_name, int *len, char ** parm_name, char ** next_position, char * bufEnd) {
|
||||
char* http_server_search_header(char *request, char *header_name, int *len, char ** parm_name, char ** next_position, char * bufEnd) {
|
||||
*len = 0;
|
||||
char *ret = NULL;
|
||||
char *ptr = NULL;
|
||||
@@ -190,7 +193,7 @@ char* CODE_RAM_LOCATION http_server_search_header(char *request, char *header_na
|
||||
ESP_LOGD(TAG, "No more match for : %s", header_name);
|
||||
return NULL;
|
||||
}
|
||||
void CODE_RAM_LOCATION http_server_send_resource_file(struct netconn *conn,const uint8_t * start, const uint8_t * end, char * content_type,char * encoding){
|
||||
void http_server_send_resource_file(struct netconn *conn,const uint8_t * start, const uint8_t * end, char * content_type,char * encoding){
|
||||
uint16_t len=end - start;
|
||||
size_t buff_length= sizeof(http_hdr_template)+strlen(content_type)+strlen(encoding);
|
||||
char * http_hdr=malloc(buff_length);
|
||||
@@ -209,7 +212,80 @@ void CODE_RAM_LOCATION http_server_send_resource_file(struct netconn *conn,const
|
||||
}
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn) {
|
||||
err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type, bool * bFirst){
|
||||
nvs_entry_info_t info;
|
||||
|
||||
int locbuflen=1024+strlen(template)+1;
|
||||
char * config_buffer = malloc(locbuflen);
|
||||
memset(config_buffer, 0x00,locbuflen);
|
||||
|
||||
if(!config_buffer)
|
||||
{
|
||||
ESP_LOGE(TAG,"Unable to allocate buffer for config.json!");
|
||||
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
nvs_iterator_t it = nvs_entry_find(NVS_PARTITION_NAME, NULL, nvs_type);
|
||||
if (it == NULL) {
|
||||
ESP_LOGW(TAG, "No nvs entry found in %s",NVS_PARTITION_NAME );
|
||||
}
|
||||
while (it != NULL){
|
||||
nvs_entry_info(it, &info);
|
||||
if(strstr(info.namespace_name, current_namespace)){
|
||||
if(!*bFirst){
|
||||
netconn_write(conn, array_separator, strlen(array_separator), NETCONN_NOCOPY);
|
||||
*bFirst=true;
|
||||
}
|
||||
void * value = get_nvs_value_alloc(nvs_type,info.key);
|
||||
if(value==NULL)
|
||||
{
|
||||
ESP_LOGE(TAG,"nvs read failed.");
|
||||
free(config_buffer);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
switch (nvs_type) {
|
||||
case NVS_TYPE_I8:
|
||||
snprintf(config_buffer, locbuflen-1, template_i, info.key, *(int8_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_I16:
|
||||
snprintf(config_buffer, locbuflen-1, template_i, info.key, *(int16_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_I32:
|
||||
snprintf(config_buffer, locbuflen-1, template_i, info.key, *(int32_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_U8:
|
||||
snprintf(config_buffer, locbuflen-1, template_u, info.key, *(uint8_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_U16:
|
||||
snprintf(config_buffer, locbuflen-1, template_u, info.key, *(uint16_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_U32:
|
||||
snprintf(config_buffer, locbuflen-1, template_u, info.key, *(uint32_t*)value);
|
||||
break;
|
||||
case NVS_TYPE_STR:
|
||||
strreplace((char *)value, s, r);
|
||||
snprintf(config_buffer, locbuflen-1, template, info.key, (char *)value);
|
||||
break;
|
||||
case NVS_TYPE_I64:
|
||||
case NVS_TYPE_U64:
|
||||
default:
|
||||
ESP_LOGE(TAG, "nvs type %u not supported", nvs_type);
|
||||
break;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,"Namespace %s, json chunk: %s", info.namespace_name, config_buffer);
|
||||
netconn_write(conn, config_buffer, strlen(config_buffer), NETCONN_NOCOPY);
|
||||
free(value );
|
||||
}
|
||||
it = nvs_entry_next(it);
|
||||
}
|
||||
free(config_buffer);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
void http_server_netconn_serve(struct netconn *conn) {
|
||||
|
||||
struct netbuf *inbuf;
|
||||
char *buf = NULL;
|
||||
@@ -292,56 +368,12 @@ void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn) {
|
||||
}
|
||||
else if(strstr(line, "GET /config.json ")){
|
||||
ESP_LOGI(TAG,"Serving config.json");
|
||||
|
||||
char * autoexec_value=NULL;
|
||||
uint8_t autoexec_flag=0;
|
||||
int locbuflen=MAX_COMMAND_LINE_SIZE*4+strlen(template)+1;
|
||||
char * config_buffer = malloc(locbuflen);
|
||||
|
||||
if(!config_buffer)
|
||||
{
|
||||
ESP_LOGE(TAG,"Unable to allocate buffer for config.json!");
|
||||
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i=1;
|
||||
size_t l = 0;
|
||||
nvs_entry_info_t info;
|
||||
|
||||
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
|
||||
autoexec_flag = wifi_manager_get_flag();
|
||||
snprintf(config_buffer,locbuflen-1, json_start, autoexec_flag);
|
||||
netconn_write(conn, config_buffer, strlen(config_buffer), NETCONN_NOCOPY);
|
||||
|
||||
ESP_LOGI(TAG, "About to get config from flash");
|
||||
nvs_iterator_t it = nvs_entry_find(NVS_PARTITION_NAME, NULL, NVS_TYPE_STR);
|
||||
if (it == NULL) {
|
||||
ESP_LOGW(TAG, "No nvs entry found in %s",NVS_PARTITION_NAME );
|
||||
}
|
||||
while (it != NULL){
|
||||
nvs_entry_info(it, &info);
|
||||
if(strstr(info.namespace_name, current_namespace)){
|
||||
if(i>1)
|
||||
{
|
||||
netconn_write(conn, array_separator, strlen(array_separator), NETCONN_NOCOPY);
|
||||
ESP_LOGD(TAG,"%s", array_separator);
|
||||
}
|
||||
|
||||
autoexec_value = wifi_manager_alloc_get_config(info.key, &l);
|
||||
strreplace(autoexec_value, s, r);
|
||||
ESP_LOGI(TAG,"Namespace %s, key=%s, value=%s", info.namespace_name, info.key,autoexec_value );
|
||||
snprintf(config_buffer, locbuflen-1, template, info.key, autoexec_value);
|
||||
netconn_write(conn, config_buffer, strlen(config_buffer), NETCONN_NOCOPY);
|
||||
ESP_LOGD(TAG,"Freeing memory for command [%s] value [%s]", info.key, autoexec_value);
|
||||
free(autoexec_value );
|
||||
i++;
|
||||
}
|
||||
it = nvs_entry_next(it);
|
||||
}
|
||||
free(config_buffer);
|
||||
netconn_write(conn, json_end, strlen(json_end), NETCONN_NOCOPY);
|
||||
}
|
||||
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
|
||||
netconn_write(conn, json_start, strlen(json_start), NETCONN_NOCOPY);
|
||||
ESP_LOGI(TAG, "About to get config from flash");
|
||||
bool bFirst=true;
|
||||
http_server_nvs_dump(conn,NVS_TYPE_STR , &bFirst);
|
||||
netconn_write(conn, json_end, strlen(json_end), NETCONN_NOCOPY);
|
||||
ESP_LOGD(TAG,"Done serving config.json");
|
||||
}
|
||||
else if(strstr(line, "POST /config.json ")){
|
||||
@@ -351,7 +383,6 @@ void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn) {
|
||||
char * last_parm=save_ptr;
|
||||
char * next_parm=save_ptr;
|
||||
char * last_parm_name=NULL;
|
||||
uint8_t autoexec_flag=0;
|
||||
bool bErrorFound=false;
|
||||
bool bOTA=false;
|
||||
char * otaURL=NULL;
|
||||
@@ -367,14 +398,11 @@ void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn) {
|
||||
ESP_LOGI(TAG, "OTA parameter found!");
|
||||
otaURL=strdup(last_parm);
|
||||
bOTA=true;
|
||||
}else if(strcmp(last_parm_name, "autoexec")==0){
|
||||
autoexec_flag = atoi(last_parm);
|
||||
wifi_manager_save_autoexec_flag(autoexec_flag);
|
||||
}
|
||||
else {
|
||||
if(lenA < MAX_COMMAND_LINE_SIZE ){
|
||||
ESP_LOGD(TAG, "http_server_netconn_serve: config.json/ Storing parameter");
|
||||
wifi_manager_save_autoexec_config(last_parm,last_parm_name,lenA);
|
||||
wifi_manager_save_config(last_parm,last_parm_name,lenA);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -474,7 +502,7 @@ void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn) {
|
||||
netbuf_delete(inbuf);
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION strreplace(char *src, char *str, char *rep)
|
||||
void strreplace(char *src, char *str, char *rep)
|
||||
{
|
||||
char *p = strstr(src, str);
|
||||
if (p)
|
||||
|
||||
@@ -130,21 +130,21 @@ const int WIFI_MANAGER_SCAN_BIT = BIT7;
|
||||
const int WIFI_MANAGER_REQUEST_DISCONNECT_BIT = BIT8;
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_refresh_ota_json(){
|
||||
void wifi_manager_refresh_ota_json(){
|
||||
wifi_manager_send_message(EVENT_REFRESH_OTA, NULL);
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_scan_async(){
|
||||
void wifi_manager_scan_async(){
|
||||
wifi_manager_send_message(ORDER_START_WIFI_SCAN, NULL);
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_disconnect_async(){
|
||||
void wifi_manager_disconnect_async(){
|
||||
wifi_manager_send_message(ORDER_DISCONNECT_STA, NULL);
|
||||
//xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_WIFI_DISCONNECT_BIT); TODO: delete
|
||||
}
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_start(){
|
||||
void wifi_manager_start(){
|
||||
|
||||
/* disable the default wifi logging */
|
||||
esp_log_level_set("wifi", ESP_LOG_NONE);
|
||||
@@ -175,22 +175,8 @@ void CODE_RAM_LOCATION wifi_manager_start(){
|
||||
xTaskCreate(&wifi_manager, "wifi_manager", 4096, NULL, WIFI_MANAGER_TASK_PRIORITY, &task_wifi_manager);
|
||||
}
|
||||
|
||||
uint8_t CODE_RAM_LOCATION wifi_manager_get_flag(){
|
||||
uint8_t value=0;
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
ESP_LOGI(TAG, "About to get config from flash");
|
||||
|
||||
esp_err = nvs_open(current_namespace, NVS_READWRITE, &handle);
|
||||
if (esp_err != ESP_OK) return 0;
|
||||
|
||||
esp_err= nvs_get_u8(handle, "autoexec", &value);
|
||||
nvs_close(handle);
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
char * CODE_RAM_LOCATION wifi_manager_alloc_get_config(char * name, size_t * l){
|
||||
char * wifi_manager_alloc_get_config(char * name, size_t * l){
|
||||
|
||||
size_t len=0;
|
||||
char * value=NULL;
|
||||
@@ -223,40 +209,8 @@ char * CODE_RAM_LOCATION wifi_manager_alloc_get_config(char * name, size_t * l){
|
||||
|
||||
}
|
||||
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_autoexec_flag(uint8_t flag){
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
ESP_LOGI(TAG, "About to save autoexec flag to flash");
|
||||
esp_err=nvs_open(current_namespace, NVS_READWRITE, &handle);
|
||||
if(esp_err==ESP_ERR_NVS_NOT_INITIALIZED){
|
||||
ESP_LOGE(TAG,"Unable to open nvs namespace %s. nvs is not initialized.",wifi_manager_nvs_namespace);
|
||||
}
|
||||
else if (esp_err != ESP_OK) {
|
||||
ESP_LOGE(TAG,"Unable to open nvs namespace %s. Error: %s", wifi_manager_nvs_namespace, esp_err_to_name(esp_err));
|
||||
return esp_err;
|
||||
}
|
||||
|
||||
esp_err = nvs_set_u8(handle, "autoexec", flag);
|
||||
if (esp_err != ESP_OK){
|
||||
ESP_LOGE(TAG,"Unable to save autoexec flag value %u",flag);
|
||||
nvs_close(handle);
|
||||
return esp_err;
|
||||
}
|
||||
|
||||
esp_err = nvs_commit(handle);
|
||||
if (esp_err != ESP_OK){
|
||||
ESP_LOGE(TAG,"nvs commit error");
|
||||
return esp_err;
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
|
||||
ESP_LOGD(TAG, "wifi_manager_wrote autoexec flag value %u",flag);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_autoexec_config(char * value, char * name, int len){
|
||||
esp_err_t wifi_manager_save_config(char * value, char * name, int len){
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
ESP_LOGI(TAG, "About to save config to flash. Name: %s, value: %s", name,value);
|
||||
@@ -289,7 +243,7 @@ esp_err_t CODE_RAM_LOCATION wifi_manager_save_autoexec_config(char * value, char
|
||||
|
||||
}
|
||||
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_sta_config(){
|
||||
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");
|
||||
@@ -331,7 +285,7 @@ esp_err_t CODE_RAM_LOCATION wifi_manager_save_sta_config(){
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool CODE_RAM_LOCATION wifi_manager_fetch_wifi_sta_config(){
|
||||
bool wifi_manager_fetch_wifi_sta_config(){
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
|
||||
@@ -408,12 +362,12 @@ bool CODE_RAM_LOCATION wifi_manager_fetch_wifi_sta_config(){
|
||||
}
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_clear_ip_info_json(){
|
||||
void wifi_manager_clear_ip_info_json(){
|
||||
strcpy(ip_info_json, "{}\n");
|
||||
}
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code){
|
||||
void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code){
|
||||
wifi_config_t *config = wifi_manager_get_wifi_sta_config();
|
||||
if(update_reason_code == UPDATE_OTA) {
|
||||
update_reason_code = last_update_reason_code;
|
||||
@@ -497,11 +451,11 @@ void CODE_RAM_LOCATION wifi_manager_generate_ip_info_json(update_reason_code_t u
|
||||
}
|
||||
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_clear_access_points_json(){
|
||||
void wifi_manager_clear_access_points_json(){
|
||||
strcpy(accessp_json, "[]\n");
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_generate_acess_points_json(){
|
||||
void wifi_manager_generate_acess_points_json(){
|
||||
strcpy(accessp_json, "[");
|
||||
|
||||
|
||||
@@ -530,7 +484,7 @@ void CODE_RAM_LOCATION wifi_manager_generate_acess_points_json(){
|
||||
|
||||
}
|
||||
|
||||
bool CODE_RAM_LOCATION wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait){
|
||||
bool wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait){
|
||||
if(wifi_manager_sta_ip_mutex){
|
||||
if( xSemaphoreTake( wifi_manager_sta_ip_mutex, xTicksToWait ) == pdTRUE ) {
|
||||
return true;
|
||||
@@ -545,11 +499,11 @@ bool CODE_RAM_LOCATION wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait){
|
||||
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_unlock_sta_ip_string(){
|
||||
void wifi_manager_unlock_sta_ip_string(){
|
||||
xSemaphoreGive( wifi_manager_sta_ip_mutex );
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_safe_update_sta_ip_string(uint32_t ip){
|
||||
void wifi_manager_safe_update_sta_ip_string(uint32_t ip){
|
||||
if(wifi_manager_lock_sta_ip_string(portMAX_DELAY)){
|
||||
|
||||
struct ip4_addr ip4;
|
||||
@@ -565,11 +519,11 @@ void CODE_RAM_LOCATION wifi_manager_safe_update_sta_ip_string(uint32_t ip){
|
||||
}
|
||||
}
|
||||
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_sta_ip_string(){
|
||||
char* wifi_manager_get_sta_ip_string(){
|
||||
return wifi_manager_sta_ip;
|
||||
}
|
||||
|
||||
bool CODE_RAM_LOCATION wifi_manager_lock_json_buffer(TickType_t xTicksToWait){
|
||||
bool wifi_manager_lock_json_buffer(TickType_t xTicksToWait){
|
||||
if(wifi_manager_json_mutex){
|
||||
if( xSemaphoreTake( wifi_manager_json_mutex, xTicksToWait ) == pdTRUE ) {
|
||||
return true;
|
||||
@@ -584,15 +538,15 @@ bool CODE_RAM_LOCATION wifi_manager_lock_json_buffer(TickType_t xTicksToWait){
|
||||
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_unlock_json_buffer(){
|
||||
void wifi_manager_unlock_json_buffer(){
|
||||
xSemaphoreGive( wifi_manager_json_mutex );
|
||||
}
|
||||
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_ap_list_json(){
|
||||
char* wifi_manager_get_ap_list_json(){
|
||||
return accessp_json;
|
||||
}
|
||||
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_event_handler(void *ctx, system_event_t *event)
|
||||
esp_err_t wifi_manager_event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch(event->event_id) {
|
||||
|
||||
@@ -666,11 +620,11 @@ esp_err_t CODE_RAM_LOCATION wifi_manager_event_handler(void *ctx, system_event_t
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
wifi_config_t* CODE_RAM_LOCATION wifi_manager_get_wifi_sta_config(){
|
||||
wifi_config_t* wifi_manager_get_wifi_sta_config(){
|
||||
return wifi_manager_config_sta;
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_connect_async(){
|
||||
void wifi_manager_connect_async(){
|
||||
/* in order to avoid a false positive on the front end app we need to quickly flush the ip json
|
||||
* There'se a risk the front end sees an IP or a password error when in fact
|
||||
* it's a remnant from a previous connection
|
||||
@@ -683,11 +637,11 @@ void CODE_RAM_LOCATION wifi_manager_connect_async(){
|
||||
}
|
||||
|
||||
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_ip_info_json(){
|
||||
char* wifi_manager_get_ip_info_json(){
|
||||
return ip_info_json;
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_destroy(){
|
||||
void wifi_manager_destroy(){
|
||||
vTaskDelete(task_wifi_manager);
|
||||
task_wifi_manager = NULL;
|
||||
|
||||
@@ -716,7 +670,7 @@ void CODE_RAM_LOCATION wifi_manager_destroy(){
|
||||
wifi_manager_queue = NULL;
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_filter_unique( wifi_ap_record_t * aplist, uint16_t * aps) {
|
||||
void wifi_manager_filter_unique( wifi_ap_record_t * aplist, uint16_t * aps) {
|
||||
int total_unique;
|
||||
wifi_ap_record_t * first_free;
|
||||
total_unique=*aps;
|
||||
@@ -767,27 +721,27 @@ void CODE_RAM_LOCATION wifi_manager_filter_unique( wifi_ap_record_t * aplist, ui
|
||||
*aps = total_unique;
|
||||
}
|
||||
|
||||
BaseType_t CODE_RAM_LOCATION wifi_manager_send_message_to_front(message_code_t code, void *param){
|
||||
BaseType_t wifi_manager_send_message_to_front(message_code_t code, void *param){
|
||||
queue_message msg;
|
||||
msg.code = code;
|
||||
msg.param = param;
|
||||
return xQueueSendToFront( wifi_manager_queue, &msg, portMAX_DELAY);
|
||||
}
|
||||
|
||||
BaseType_t CODE_RAM_LOCATION wifi_manager_send_message(message_code_t code, void *param){
|
||||
BaseType_t wifi_manager_send_message(message_code_t code, void *param){
|
||||
queue_message msg;
|
||||
msg.code = code;
|
||||
msg.param = param;
|
||||
return xQueueSend( wifi_manager_queue, &msg, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager_set_callback(message_code_t message_code, void (*func_ptr)(void*) ){
|
||||
void wifi_manager_set_callback(message_code_t message_code, void (*func_ptr)(void*) ){
|
||||
if(cb_ptr_arr && message_code < MESSAGE_CODE_COUNT){
|
||||
cb_ptr_arr[message_code] = func_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CODE_RAM_LOCATION wifi_manager( void * pvParameters ){
|
||||
void wifi_manager( void * pvParameters ){
|
||||
queue_message msg;
|
||||
BaseType_t xStatus;
|
||||
EventBits_t uxBits;
|
||||
@@ -912,6 +866,12 @@ void CODE_RAM_LOCATION wifi_manager( void * pvParameters ){
|
||||
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){
|
||||
wifi_manager_generate_ip_info_json( UPDATE_OTA );
|
||||
wifi_manager_unlock_json_buffer();
|
||||
#if RECOVERY_APPLICATION
|
||||
ESP_LOGI(TAG,"Refresh from OTA status: %s - flash percent: %d%% ",
|
||||
ota_get_status(),
|
||||
ota_get_pct_complete());
|
||||
#endif
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -268,71 +268,69 @@ typedef struct{
|
||||
/**
|
||||
* Allocate heap memory for the wifi manager and start the wifi_manager RTOS task
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_start();
|
||||
void wifi_manager_start();
|
||||
|
||||
/**
|
||||
* Frees up all memory allocated by the wifi_manager and kill the task.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_destroy();
|
||||
void wifi_manager_destroy();
|
||||
|
||||
/**
|
||||
* Filters the AP scan list to unique SSIDs
|
||||
*/
|
||||
void CODE_RAM_LOCATION filter_unique( wifi_ap_record_t * aplist, uint16_t * ap_num);
|
||||
void filter_unique( wifi_ap_record_t * aplist, uint16_t * ap_num);
|
||||
|
||||
/**
|
||||
* Main task for the wifi_manager
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager( void * pvParameters );
|
||||
void wifi_manager( void * pvParameters );
|
||||
|
||||
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_ap_list_json();
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_ip_info_json();
|
||||
char* wifi_manager_get_ap_list_json();
|
||||
char* wifi_manager_get_ip_info_json();
|
||||
|
||||
uint8_t CODE_RAM_LOCATION wifi_manager_get_flag();
|
||||
char * CODE_RAM_LOCATION wifi_manager_alloc_get_config(char * name, size_t * l);
|
||||
char * wifi_manager_alloc_get_config(char * name, size_t * l);
|
||||
|
||||
|
||||
/**
|
||||
* @brief saves the current STA wifi config to flash ram storage.
|
||||
*/
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_sta_config();
|
||||
esp_err_t wifi_manager_save_sta_config();
|
||||
|
||||
/**
|
||||
* @brief saves the current configuration to flash ram storage
|
||||
*/
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_autoexec_config(char * value, char * name, int len);
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_save_autoexec_flag(uint8_t flag);
|
||||
esp_err_t wifi_manager_save_config(char * value, char * name, int len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief fetch a previously STA wifi config in the flash ram storage.
|
||||
* @return true if a previously saved config was found, false otherwise.
|
||||
*/
|
||||
bool CODE_RAM_LOCATION wifi_manager_fetch_wifi_sta_config();
|
||||
bool wifi_manager_fetch_wifi_sta_config();
|
||||
|
||||
wifi_config_t* CODE_RAM_LOCATION wifi_manager_get_wifi_sta_config();
|
||||
wifi_config_t* wifi_manager_get_wifi_sta_config();
|
||||
|
||||
/**
|
||||
* @brief A standard wifi event handler as recommended by Espressif
|
||||
*/
|
||||
esp_err_t CODE_RAM_LOCATION wifi_manager_event_handler(void *ctx, system_event_t *event);
|
||||
esp_err_t wifi_manager_event_handler(void *ctx, system_event_t *event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief requests a connection to an access point that will be process in the main task thread.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_connect_async();
|
||||
void wifi_manager_connect_async();
|
||||
|
||||
/**
|
||||
* @brief requests a wifi scan
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_scan_async();
|
||||
void wifi_manager_scan_async();
|
||||
|
||||
/**
|
||||
* @brief requests to disconnect and forget about the access point.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_disconnect_async();
|
||||
void wifi_manager_disconnect_async();
|
||||
|
||||
/**
|
||||
* @brief Tries to get access to json buffer mutex.
|
||||
@@ -349,65 +347,65 @@ void CODE_RAM_LOCATION wifi_manager_disconnect_async();
|
||||
* @param xTicksToWait The time in ticks to wait for the semaphore to become available.
|
||||
* @return true in success, false otherwise.
|
||||
*/
|
||||
bool CODE_RAM_LOCATION wifi_manager_lock_json_buffer(TickType_t xTicksToWait);
|
||||
bool wifi_manager_lock_json_buffer(TickType_t xTicksToWait);
|
||||
|
||||
/**
|
||||
* @brief Releases the json buffer mutex.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_unlock_json_buffer();
|
||||
void wifi_manager_unlock_json_buffer();
|
||||
|
||||
/**
|
||||
* @brief Generates the connection status json: ssid and IP addresses.
|
||||
* @note This is not thread-safe and should be called only if wifi_manager_lock_json_buffer call is successful.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code);
|
||||
void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code);
|
||||
/**
|
||||
* @brief Clears the connection status json.
|
||||
* @note This is not thread-safe and should be called only if wifi_manager_lock_json_buffer call is successful.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_clear_ip_info_json();
|
||||
void wifi_manager_clear_ip_info_json();
|
||||
|
||||
/**
|
||||
* @brief Generates the list of access points after a wifi scan.
|
||||
* @note This is not thread-safe and should be called only if wifi_manager_lock_json_buffer call is successful.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_generate_acess_points_json();
|
||||
void wifi_manager_generate_acess_points_json();
|
||||
|
||||
/**
|
||||
* @brief Clear the list of access points.
|
||||
* @note This is not thread-safe and should be called only if wifi_manager_lock_json_buffer call is successful.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_clear_access_points_json();
|
||||
void wifi_manager_clear_access_points_json();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Start the mDNS service
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_initialise_mdns();
|
||||
void wifi_manager_initialise_mdns();
|
||||
|
||||
|
||||
bool CODE_RAM_LOCATION wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait);
|
||||
void CODE_RAM_LOCATION wifi_manager_unlock_sta_ip_string();
|
||||
bool wifi_manager_lock_sta_ip_string(TickType_t xTicksToWait);
|
||||
void wifi_manager_unlock_sta_ip_string();
|
||||
|
||||
/**
|
||||
* @brief gets the string representation of the STA IP address, e.g.: "192.168.1.69"
|
||||
*/
|
||||
char* CODE_RAM_LOCATION wifi_manager_get_sta_ip_string();
|
||||
char* wifi_manager_get_sta_ip_string();
|
||||
|
||||
/**
|
||||
* @brief thread safe char representation of the STA IP update
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_safe_update_sta_ip_string(uint32_t ip);
|
||||
void wifi_manager_safe_update_sta_ip_string(uint32_t ip);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Register a callback to a custom function when specific event message_code happens.
|
||||
*/
|
||||
void CODE_RAM_LOCATION wifi_manager_set_callback(message_code_t message_code, void (*func_ptr)(void*) );
|
||||
void wifi_manager_set_callback(message_code_t message_code, void (*func_ptr)(void*) );
|
||||
|
||||
|
||||
BaseType_t CODE_RAM_LOCATION wifi_manager_send_message(message_code_t code, void *param);
|
||||
BaseType_t CODE_RAM_LOCATION wifi_manager_send_message_to_front(message_code_t code, void *param);
|
||||
BaseType_t wifi_manager_send_message(message_code_t code, void *param);
|
||||
BaseType_t wifi_manager_send_message_to_front(message_code_t code, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user