mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
Major refactoring. OTA Works now (yes, yes... really works! )
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user