diff --git a/.vscode/settings.json b/.vscode/settings.json index 1020cdc..d20075a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -100,7 +100,11 @@ "esp-bsp.h": "c", "esp_littlefs.h": "c", "esp_vfs_fat.h": "c", - "esp_http_client.h": "c" + "esp_http_client.h": "c", + "am2302_rmt.h": "c", + "bsp_board_extra.h": "c", + "display.h": "c", + "statemanagement.h": "c" }, "idf.pythonInstallPath": "/usr/local/bin/python" } diff --git a/components/communication/CMakeLists.txt b/components/communication/CMakeLists.txt new file mode 100644 index 0000000..7e08db0 --- /dev/null +++ b/components/communication/CMakeLists.txt @@ -0,0 +1,11 @@ +idf_component_register(SRCS "communication.c" + INCLUDE_DIRS "include" + REQUIRES mqtt esp32_p4_function_ev_board esp_wifi esp32_p4_function_ev_board stateManagement) + + + lvgl_port_create_c_image("images/wifi_ok.png" "images/" "ARGB8888" "NONE") + lvgl_port_create_c_image("images/wifi_ko.png" "images/" "ARGB8888" "NONE") + lvgl_port_create_c_image("images/mqtt_ok.png" "images/" "AUTO" "NONE") + lvgl_port_create_c_image("images/mqtt_ko.png" "images/" "ARGB8888" "NONE") + + lvgl_port_add_images(${COMPONENT_LIB} "images/") diff --git a/main/mqtt.c b/components/communication/communication.c similarity index 60% rename from main/mqtt.c rename to components/communication/communication.c index 4155b40..131d183 100644 --- a/main/mqtt.c +++ b/components/communication/communication.c @@ -1,302 +1,489 @@ -#include "mqtt.h" -#include "esp_log.h" -#include "esp_lvgl_port.h" -#include "mqtt_client.h" - -esp_mqtt_client_handle_t client; -lv_subject_t mqttStatus; - -extern lv_subject_t tempIntSubj; -extern lv_subject_t tempExtSubj; -extern lv_subject_t hauteurCuveSubj; -extern lv_subject_t hauteurCuveEvolSubj; - -static const char *TAG = "domo_mqtt"; - -char *upEvent = "monter"; -char *downEvent = "descendre"; - -char *topicTempExt = "house/temp/282A802600008059"; -char *topicHauteurCuve = "house/cuve/hauteur"; -char *topicTempInt = "house/temp/287DCF1E00008020"; -char *topicHauteurCuveEvol = "house/cuve/hauteurEvol"; -char *topicdomoticCommand = "domotic/cmd"; -char *topicTest = "test"; - -LV_IMAGE_DECLARE(mqtt_ok); -LV_IMAGE_DECLARE(mqtt_ko); - -static void mqttStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject); - -static void mqttStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) -{ - ESP_LOGV(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); - if(lvgl_port_lock(0)){ - lv_obj_t * wifiSt = lv_obj_get_child(lv_obj_get_child(lv_layer_top(), 0),3); - if(lv_obj_check_type(wifiSt, &lv_image_class)){ - switch (lv_subject_get_int(subject)) - { - case 0: - lv_image_set_src(wifiSt,&mqtt_ko); - break; - case 1: - lv_image_set_src(wifiSt,&mqtt_ok); - break; - case 2: - lv_color_t color = lv_color_make(255, 0, 0); - lv_obj_set_style_image_recolor_opa(wifiSt, 125, 0); - lv_obj_set_style_image_recolor(wifiSt, color, 0); - vTaskDelay(2000 / portTICK_PERIOD_MS); - - break; - case 3: - lv_obj_set_style_image_recolor_opa(wifiSt, 0, 0); - break; - default: - break; - } - }else{ - ESP_LOGE(TAG, "L'objet recuip en semble pas etre du bon type"); - } - lvgl_port_unlock(); - } - //int32_t prev_v = lv_subject_get_previous_int(subject); - //int32_t cur_v = lv_subject_get_int(subject); - - //lv_obj_t * btn = lv_observer_get_target(observer); -} - -static void log_error_if_nonzero(const char *message, int error_code) -{ - if (error_code != 0) - { - ESP_LOGE(TAG, "Last error %s: 0x%x", message, error_code); - } -} - -void splitIt(char *payload, unsigned int length, float *datas) -{ - char *sep = ","; - char *token; - char *saveptr1; - - token = strtok_r(payload, sep, &saveptr1); - datas[0] = atoff(token); - ESP_LOGE(TAG,"%f",datas[0]); - - token = strtok_r(NULL, sep, &saveptr1); - datas[1] = atoff(token); - ESP_LOGE(TAG,"%f",datas[1]); - - token = strtok_r(NULL, sep, &saveptr1); - datas[2] = atoff(token); - ESP_LOGE(TAG,"%f",datas[2]); - - token = strtok_r(NULL, sep, &saveptr1); - datas[3] = atoff(token); - ESP_LOGE(TAG,"%f",datas[3]); -} - -/* - * @brief Event handler registered to receive MQTT events - * - * This function is called by the MQTT client event loop. - * - * @param handler_args user data registered to the event. - * @param base Event base for the handler(always MQTT Base in this example). - * @param event_id The id for the received event. - * @param event_data The data for the event, esp_mqtt_event_handle_t. - */ -static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - ESP_LOGV(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id); - esp_mqtt_event_handle_t event = event_data; - esp_mqtt_client_handle_t client = event->client; - int msg_id; - switch ((esp_mqtt_event_id_t)event_id) - { - case MQTT_EVENT_CONNECTED: - if(lvgl_port_lock(50)){ - ESP_LOGV(TAG,"Statut mqttStatus 1"); - lv_subject_set_int(&mqttStatus,1); - lvgl_port_unlock(); - } - ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED"); - //msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0); - //ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicTempExt, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicTempInt, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicHauteurCuve, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicHauteurCuveEvol, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicTest, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0); - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - //msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1); - //ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - - //msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1"); - //ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id); - break; - case MQTT_EVENT_DISCONNECTED: - if(lvgl_port_lock(50)){ - ESP_LOGE(TAG,"Statut mqttStatus 0"); - lv_subject_set_int(&mqttStatus,0); - lvgl_port_unlock(); - } - ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED"); - break; - - case MQTT_EVENT_SUBSCRIBED: - ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id); - //msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0); - //ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); - break; - case MQTT_EVENT_UNSUBSCRIBED: - ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id); - break; - case MQTT_EVENT_PUBLISHED: - ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id); - break; - case MQTT_EVENT_DATA: - lv_subject_set_int(&mqttStatus,2); - ESP_LOGD(TAG, "\nMQTT_EVENT_DATA"); - ESP_LOGD(TAG, "TOPIC=%.*s\n", event->topic_len, event->topic); - ESP_LOGD(TAG, "DATA=%.*s\n", event->data_len, event->data); - if (strncmp(event->topic, topicTempExt, 27) == 0) - { - if(lvgl_port_lock(50)){ - // on retransforme en float pour ne garder que la partie entiere de la température - float temp = strtof(event->data, NULL); - char buff[5]; - sprintf(buff,"%.1f",temp); - lv_subject_copy_string(&tempExtSubj, buff); - lvgl_port_unlock(); - } - } - else if (strncmp(event->topic, topicTempInt, 27) == 0) - { - if(lvgl_port_lock(0)){ - // on retransforme en float pour ne garder que la partie entiere de la température - float temp = strtof(event->data, NULL); - char buff[5]; - sprintf(buff,"%.1f",temp); - lv_subject_copy_string(&tempIntSubj, buff); - lvgl_port_unlock(); - } - } - else if (strncmp(event->topic, topicHauteurCuveEvol, 22) == 0) - { - /* float datas[4] = {}; - splitIt(event->data, event->data_len, datas); - ser1->y_points[0] = 130 - (int)datas[0]; - ser1->y_points[1] = 130 - (int)datas[1]; - ser1->y_points[2] = 130 - (int)datas[2]; - ser1->y_points[3] = 130 - (int)datas[3]; - lvgl_port_lock(0); - lv_chart_refresh(chart); - lvgl_port_unlock(); - */ - - // lv_subject_copy_string(&hauteurCuveEvolSubj, event->data); - } - else if (strncmp(event->topic, topicHauteurCuve, 18) == 0) - { - if (lvgl_port_lock(50)){ - float temp = strtof(event->data, NULL); - char buff[5]; - sprintf(buff,"%.0f",temp); - lv_subject_copy_string(&hauteurCuveSubj, buff); - lvgl_port_unlock(); - } - }else if (strncmp(event->topic, topicTest, 4) == 0){ - ESP_LOGD(TAG,"Msg reecu sur test"); - }else if (strncmp(event->topic, topicdomoticCommand, 11) == 0){ - if(strncmp(event->data,"restart",7)==0){ - ESP_LOGI(TAG," Commande 'restart' recue"); - esp_restart(); - } - } - else - { - ESP_LOGE(TAG, "None match :-( %s", event->topic); - } - if (lvgl_port_lock(50)){ - lv_subject_set_int(&mqttStatus,3); - lvgl_port_unlock(); - } - break; - case MQTT_EVENT_ERROR: - ESP_LOGI(TAG, "MQTT_EVENT_ERROR"); - if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) - { - log_error_if_nonzero("reported from esp-tls", event->error_handle->esp_tls_last_esp_err); - log_error_if_nonzero("reported from tls stack", event->error_handle->esp_tls_stack_err); - log_error_if_nonzero("captured as transport's socket errno", event->error_handle->esp_transport_sock_errno); - ESP_LOGI(TAG, "Last errno string (%s)", strerror(event->error_handle->esp_transport_sock_errno)); - } - break; - default: - ESP_LOGI(TAG, "Other event id:%d", event->event_id); - break; - } -} -void mqtt_app_start(void) -{ - - lv_subject_init_int(&mqttStatus,-1); - lv_subject_add_observer_obj(&mqttStatus, mqttStatus_obs_cb, NULL, NULL); - - - esp_mqtt_client_config_t mqtt_cfg = { - .broker.address.uri = "mqtt://192.168.0.10", - .network.timeout_ms = 1000}; -#if CONFIG_BROKER_URL_FROM_STDIN - char line[128]; - - if (strcmp(mqtt_cfg.broker.address.uri, "FROM_STDIN") == 0) - { - int count = 0; - printf("Please enter url of mqtt broker\n"); - while (count < 128) - { - int c = fgetc(stdin); - if (c == '\n') - { - line[count] = '\0'; - break; - } - else if (c > 0 && c < 127) - { - line[count] = c; - ++count; - } - vTaskDelay(10 / portTICK_PERIOD_MS); - } - mqtt_cfg.broker.address.uri = line; - printf("Broker url: %s\n", line); - } - else - { - ESP_LOGE(TAG, "Configuration mismatch: wrong broker url"); - abort(); - } -#endif /* CONFIG_BROKER_URL_FROM_STDIN */ - - client = esp_mqtt_client_init(&mqtt_cfg); - /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - esp_mqtt_client_start(client); -} - +#include "communication.h" +#include "esp_log.h" +#include "esp_lvgl_port.h" +#include "mqtt_client.h" +#include "bsp/esp-bsp.h" +#include "stateManagement.h" + +esp_mqtt_client_handle_t client; +lv_subject_t mqttStatus; + +extern lv_subject_t tempIntSubj; +extern lv_subject_t tempExtSubj; +extern lv_subject_t hauteurCuveSubj; +extern lv_subject_t hauteurCuveEvolSubj; + +static const char *TAG = "domo_mqtt"; + +char *upEvent = "monter"; +char *downEvent = "descendre"; + +char *topicTempExt = "house/temp/282A802600008059"; +char *topicHauteurCuve = "house/cuve/hauteur"; +char *topicTempInt = "house/temp/287DCF1E00008020"; +char *topicHauteurCuveEvol = "house/cuve/hauteurEvol"; +char *topicdomoticCommand = "domotic/cmd"; +char *topicTest = "test"; + +LV_IMAGE_DECLARE(mqtt_ok); +LV_IMAGE_DECLARE(mqtt_ko); + +static void mqttStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject); + +static void mqttStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) +{ + ESP_LOGV(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); + if(lvgl_port_lock(0)){ + lv_obj_t * wifiSt = lv_obj_get_child(lv_obj_get_child(lv_layer_top(), 0),3); + if(lv_obj_check_type(wifiSt, &lv_image_class)){ + switch (lv_subject_get_int(subject)) + { + case 0: + lv_image_set_src(wifiSt,&mqtt_ko); + break; + case 1: + lv_image_set_src(wifiSt,&mqtt_ok); + break; + case 2: + lv_color_t color = lv_color_make(255, 0, 0); + lv_obj_set_style_image_recolor_opa(wifiSt, 125, 0); + lv_obj_set_style_image_recolor(wifiSt, color, 0); + vTaskDelay(2000 / portTICK_PERIOD_MS); + + break; + case 3: + lv_obj_set_style_image_recolor_opa(wifiSt, 0, 0); + break; + default: + break; + } + }else{ + ESP_LOGE(TAG, "L'objet recuip en semble pas etre du bon type"); + } + lvgl_port_unlock(); + } + //int32_t prev_v = lv_subject_get_previous_int(subject); + //int32_t cur_v = lv_subject_get_int(subject); + + //lv_obj_t * btn = lv_observer_get_target(observer); +} + +static void log_error_if_nonzero(const char *message, int error_code) +{ + if (error_code != 0) + { + ESP_LOGE(TAG, "Last error %s: 0x%x", message, error_code); + } +} + +void splitIt(char *payload, unsigned int length, float *datas) +{ + char *sep = ","; + char *token; + char *saveptr1; + + token = strtok_r(payload, sep, &saveptr1); + datas[0] = atoff(token); + ESP_LOGE(TAG,"%f",datas[0]); + + token = strtok_r(NULL, sep, &saveptr1); + datas[1] = atoff(token); + ESP_LOGE(TAG,"%f",datas[1]); + + token = strtok_r(NULL, sep, &saveptr1); + datas[2] = atoff(token); + ESP_LOGE(TAG,"%f",datas[2]); + + token = strtok_r(NULL, sep, &saveptr1); + datas[3] = atoff(token); + ESP_LOGE(TAG,"%f",datas[3]); +} + +/* + * @brief Event handler registered to receive MQTT events + * + * This function is called by the MQTT client event loop. + * + * @param handler_args user data registered to the event. + * @param base Event base for the handler(always MQTT Base in this example). + * @param event_id The id for the received event. + * @param event_data The data for the event, esp_mqtt_event_handle_t. + */ +static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) +{ + ESP_LOGV(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id); + esp_mqtt_event_handle_t event = event_data; + esp_mqtt_client_handle_t client = event->client; + int msg_id; + switch ((esp_mqtt_event_id_t)event_id) + { + case MQTT_EVENT_CONNECTED: + if(lvgl_port_lock(50)){ + ESP_LOGV(TAG,"Statut mqttStatus 1"); + lv_subject_set_int(&mqttStatus,1); + lvgl_port_unlock(); + } + ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED"); + //msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0); + //ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicTempExt, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicTempInt, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicHauteurCuve, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicHauteurCuveEvol, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicTest, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0); + ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + //msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1); + //ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); + + //msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1"); + //ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id); + break; + case MQTT_EVENT_DISCONNECTED: + if(lvgl_port_lock(50)){ + ESP_LOGE(TAG,"Statut mqttStatus 0"); + lv_subject_set_int(&mqttStatus,0); + lvgl_port_unlock(); + } + ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED"); + break; + + case MQTT_EVENT_SUBSCRIBED: + ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id); + //msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0); + //ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); + break; + case MQTT_EVENT_UNSUBSCRIBED: + ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id); + break; + case MQTT_EVENT_PUBLISHED: + ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id); + break; + case MQTT_EVENT_DATA: + lv_subject_set_int(&mqttStatus,2); + ESP_LOGD(TAG, "\nMQTT_EVENT_DATA"); + ESP_LOGD(TAG, "TOPIC=%.*s\n", event->topic_len, event->topic); + ESP_LOGD(TAG, "DATA=%.*s\n", event->data_len, event->data); + if (strncmp(event->topic, topicTempExt, 27) == 0) + { + if(lvgl_port_lock(50)){ + // on retransforme en float pour ne garder que la partie entiere de la température + float temp = strtof(event->data, NULL); + char buff[5]; + sprintf(buff,"%.1f",temp); + lv_subject_copy_string(&tempExtSubj, buff); + lvgl_port_unlock(); + } + } + else if (strncmp(event->topic, topicTempInt, 27) == 0) + { + if(lvgl_port_lock(0)){ + // on retransforme en float pour ne garder que la partie entiere de la température + float temp = strtof(event->data, NULL); + char buff[5]; + sprintf(buff,"%.1f",temp); + lv_subject_copy_string(&tempIntSubj, buff); + lvgl_port_unlock(); + } + } + else if (strncmp(event->topic, topicHauteurCuveEvol, 22) == 0) + { + /* float datas[4] = {}; + splitIt(event->data, event->data_len, datas); + ser1->y_points[0] = 130 - (int)datas[0]; + ser1->y_points[1] = 130 - (int)datas[1]; + ser1->y_points[2] = 130 - (int)datas[2]; + ser1->y_points[3] = 130 - (int)datas[3]; + lvgl_port_lock(0); + lv_chart_refresh(chart); + lvgl_port_unlock(); + */ + + // lv_subject_copy_string(&hauteurCuveEvolSubj, event->data); + } + else if (strncmp(event->topic, topicHauteurCuve, 18) == 0) + { + if (lvgl_port_lock(50)){ + float temp = strtof(event->data, NULL); + char buff[5]; + sprintf(buff,"%.0f",temp); + lv_subject_copy_string(&hauteurCuveSubj, buff); + lvgl_port_unlock(); + } + }else if (strncmp(event->topic, topicTest, 4) == 0){ + ESP_LOGD(TAG,"Msg reecu sur test"); + }else if (strncmp(event->topic, topicdomoticCommand, 11) == 0){ + if(strncmp(event->data,"restart",7)==0){ + ESP_LOGI(TAG," Commande 'restart' recue"); + esp_restart(); + } + } + else + { + ESP_LOGE(TAG, "None match :-( %s", event->topic); + } + if (lvgl_port_lock(50)){ + lv_subject_set_int(&mqttStatus,3); + lvgl_port_unlock(); + } + break; + case MQTT_EVENT_ERROR: + ESP_LOGI(TAG, "MQTT_EVENT_ERROR"); + if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) + { + log_error_if_nonzero("reported from esp-tls", event->error_handle->esp_tls_last_esp_err); + log_error_if_nonzero("reported from tls stack", event->error_handle->esp_tls_stack_err); + log_error_if_nonzero("captured as transport's socket errno", event->error_handle->esp_transport_sock_errno); + ESP_LOGI(TAG, "Last errno string (%s)", strerror(event->error_handle->esp_transport_sock_errno)); + } + break; + default: + ESP_LOGI(TAG, "Other event id:%d", event->event_id); + break; + } +} +void mqtt_app_start(void) +{ + + lv_subject_init_int(&mqttStatus,-1); + lv_subject_add_observer_obj(&mqttStatus, mqttStatus_obs_cb, NULL, NULL); + + + esp_mqtt_client_config_t mqtt_cfg = { + .broker.address.uri = "mqtt://192.168.0.10", + .network.timeout_ms = 1000}; +#if CONFIG_BROKER_URL_FROM_STDIN + char line[128]; + + if (strcmp(mqtt_cfg.broker.address.uri, "FROM_STDIN") == 0) + { + int count = 0; + printf("Please enter url of mqtt broker\n"); + while (count < 128) + { + int c = fgetc(stdin); + if (c == '\n') + { + line[count] = '\0'; + break; + } + else if (c > 0 && c < 127) + { + line[count] = c; + ++count; + } + vTaskDelay(10 / portTICK_PERIOD_MS); + } + mqtt_cfg.broker.address.uri = line; + printf("Broker url: %s\n", line); + } + else + { + ESP_LOGE(TAG, "Configuration mismatch: wrong broker url"); + abort(); + } +#endif /* CONFIG_BROKER_URL_FROM_STDIN */ + + client = esp_mqtt_client_init(&mqtt_cfg); + /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ + esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); + esp_mqtt_client_start(client); +} + +#include "esp_wifi.h" +#include "esp_log.h" +#include "esp_lvgl_port.h" + +/* FreeRTOS event group to signal when we are connected*/ +static EventGroupHandle_t s_wifi_event_group; + +/* The event group allows multiple bits for each event, but we only care about two events: + * - we are connected to the AP with an IP + * - we failed to connect after the maximum amount of retries */ +#define WIFI_CONNECTED_BIT BIT0 +#define WIFI_FAIL_BIT BIT1 + +#define EXAMPLE_ESP_WIFI_SSID "wifimms3" +#define EXAMPLE_ESP_WIFI_PASS "mmswifi0611" +#define EXAMPLE_ESP_MAXIMUM_RETRY 5 + +#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH +#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID +#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK + +static int s_retry_num = 0; + +static lv_subject_t wifiStatus; +LV_IMAGE_DECLARE(wifi_ok); +LV_IMAGE_DECLARE(wifi_ko); + +static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject); + + +static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) +{ + ESP_LOGE(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); + bsp_display_lock(0); + lv_obj_t * wifiSt = lv_obj_get_child(lv_obj_get_child(lv_layer_top(), 0),2); + if(lv_obj_check_type(wifiSt, &lv_image_class)){ + switch (lv_subject_get_int(subject)) + { + case 0: + lv_image_set_src(wifiSt,&wifi_ko); + break; + case 1: + lv_image_set_src(wifiSt,&wifi_ok); + break; + default: + break; + } + }else{ + ESP_LOGE(TAG, "L'objet recuip en semble pas etre du bon type"); + } + bsp_display_unlock(); + //int32_t prev_v = lv_subject_get_previous_int(subject); + //int32_t cur_v = lv_subject_get_int(subject); + + //lv_obj_t * btn = lv_observer_get_target(observer); +} + +static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) +{ + if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) + { + esp_wifi_connect(); + } + else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) + { + if(lvgl_port_lock(0)){ + ESP_LOGE(TAG,"Statut Wifi 0"); + lv_subject_set_int(&wifiStatus,0); + lvgl_port_unlock(); + } + if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) + { + esp_wifi_connect(); + s_retry_num++; + ESP_LOGI(TAG, "retry to connect to the AP"); + } + else + { + xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); + } + ESP_LOGI(TAG, "connect to the AP fail"); + } + else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) + { + if(lvgl_port_lock(0)){ + ESP_LOGE(TAG,"Statut Wifi 1"); + lv_subject_set_int(&wifiStatus,1); + lvgl_port_unlock(); + } + ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; + ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); + s_retry_num = 0; + xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); + mainState.wifi_init=true; + } +} +void wifi_init_sta(void) +{ + s_wifi_event_group = xEventGroupCreate(); + + ESP_ERROR_CHECK(esp_netif_init()); + + ESP_ERROR_CHECK(esp_event_loop_create_default()); + esp_netif_create_default_wifi_sta(); + + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + + esp_event_handler_instance_t instance_any_id; + esp_event_handler_instance_t instance_got_ip; + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + ESP_EVENT_ANY_ID, + &wifi_event_handler, + NULL, + &instance_any_id)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, + IP_EVENT_STA_GOT_IP, + &wifi_event_handler, + NULL, + &instance_got_ip)); + + wifi_config_t wifi_config = { + .sta = { + .ssid = EXAMPLE_ESP_WIFI_SSID, + .password = EXAMPLE_ESP_WIFI_PASS, + /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (pasword len => 8). + * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value + * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to + * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards. + */ + .threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD, + .sae_pwe_h2e = ESP_WIFI_SAE_MODE, + .sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER, + }, + }; + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); + ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); + ESP_ERROR_CHECK(esp_wifi_start()); + + ESP_LOGI(TAG, "wifi_init_sta finished."); + lv_subject_init_int(&wifiStatus,0); + lv_subject_add_observer_obj(&wifiStatus, wifiStatus_obs_cb, NULL, NULL); + + + /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum + * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ + EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, + WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, + pdFALSE, + pdFALSE, + portMAX_DELAY); + + /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually + * happened. */ + if (bits & WIFI_CONNECTED_BIT) + { + ESP_LOGI(TAG, "connected to ap SSID:%s", EXAMPLE_ESP_WIFI_SSID); + if(lvgl_port_lock(0)){ + ESP_LOGE(TAG,"Statut Wifi 1"); + lv_subject_set_int(&wifiStatus,1); + lvgl_port_unlock(); + } + } + else if (bits & WIFI_FAIL_BIT) + { + ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", + EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); + if(lvgl_port_lock(0)){ + ESP_LOGE(TAG,"Statut Wifi 0"); + lv_subject_set_int(&wifiStatus,0); + lvgl_port_unlock(); + } + } + else + { + ESP_LOGE(TAG, "UNEXPECTED EVENT"); + if(lvgl_port_lock(0)){ + ESP_LOGE(TAG,"Statut Wifi 0"); + lv_subject_set_int(&wifiStatus,0); + lvgl_port_unlock(); + } + + } +} + diff --git a/components/communication/images/mqtt_ko.c b/components/communication/images/mqtt_ko.c new file mode 100644 index 0000000..5be5ac8 --- /dev/null +++ b/components/communication/images/mqtt_ko.c @@ -0,0 +1,51 @@ + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) +#include "lvgl.h" +#elif defined(LV_BUILD_TEST) +#include "../lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_MQTT_KO +#define LV_ATTRIBUTE_MQTT_KO +#endif + +static const +LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_MQTT_KO +uint8_t mqtt_ko_map[] = { + + 0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x39,0x39,0x39,0xff,0xaa,0xa9,0xaa,0xff,0xed,0xed,0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0xf1,0xf1,0xff,0x83,0x83,0x83,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xe8, + 0xb5,0xb3,0xb5,0xfd,0xaa,0xaa,0xaa,0xff,0x8d,0x8d,0x8d,0xff,0x3f,0x3d,0x3f,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x27,0x21,0x27,0xff,0xb6,0xb6,0xb6,0xff,0xfa,0xfa,0xfa,0xff,0xf9,0xf9,0xf9,0xff,0xc3,0xc3,0xc3,0xff,0x4d,0x4d,0x4d,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdd,0xdd,0xdd,0xff,0x9d,0x9c,0x9d,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x6d,0x6d,0x6d,0xff,0xbd,0xbd,0xbd,0xff,0xb5,0xb5,0xb5,0xff,0x5f,0x5f,0x5f,0xff,0x01,0x01,0x01,0xff,0x00,0x00,0x00,0xff, + 0xe7,0xe7,0xe7,0xff,0xee,0xee,0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xec,0xec,0xec,0xff,0x81,0x7f,0x81,0xfe,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x23,0x22,0x23,0xff,0x16,0x16,0x16,0xff,0x01,0x01,0x01,0xff,0x17,0x17,0x17,0xff,0x6a,0x68,0x6a,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x3e,0x3c,0x3e,0xff,0x98,0x97,0x98,0xff,0xd9,0xd8,0xd9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfc,0xfc,0xff,0xad,0xac,0xad,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x05,0x05,0x05,0xff,0xd2,0xd2,0xd2,0xff,0xf5,0xf4,0xf5,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x72,0x71,0x72,0xff,0xe2,0xe2,0xe2,0xff,0xc4,0xc4,0xc4,0xff,0x7f,0x7f,0x7f,0xff,0x09,0x09,0x09,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x3b,0x3b,0x3b,0xff,0xf7,0xf7,0xf7,0xff,0xff,0xff,0xff,0xff, + 0xe7,0xe7,0xe7,0xff,0xcf,0xce,0xcf,0xfe,0xa9,0xa9,0xa9,0xff,0x4f,0x4f,0x4f,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x10,0x09,0x10,0xff,0x6a,0x6a,0x6a,0xff,0x38,0x38,0x38,0xff,0x00,0x00,0x00,0xff,0x04,0x04,0x04,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xa7,0xa6,0xa7,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf5,0xf5,0xf5,0xff,0x94,0x94,0x94,0xff,0x1e,0x1e,0x1e,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x12,0x12,0x12,0xff,0xc2,0xc2,0xc2,0xff,0x8d,0x8c,0x8d,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xe4,0xe3,0xe4,0xfe, + 0xc5,0xc3,0xc5,0xfe,0xd5,0xd5,0xd5,0xff,0xf0,0xef,0xf0,0xff,0xc7,0xc7,0xc7,0xff,0xb6,0xb6,0xb6,0xff,0x5a,0x5a,0x5a,0xff,0x01,0x01,0x01,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xaf,0xae,0xaf,0xff,0xfd,0xfd,0xfd,0xff,0xed,0xec,0xed,0xff,0x20,0x17,0x20,0xfe,0x00,0x00,0x00,0xff,0x92,0x90,0x92,0xfe, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x19,0x19,0x19,0xff,0x66,0x65,0x66,0xff,0x30,0x30,0x30,0xff,0x03,0x03,0x03,0xff,0x02,0x02,0x02,0xff,0x05,0x05,0x05,0xff,0x00,0x00,0x00,0xff,0x69,0x67,0x69,0xff,0xfb,0xfb,0xfb,0xff,0xff,0xff,0xff,0xff,0xa5,0xa4,0xa5,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x02,0x02,0x02,0xff,0x04,0x04,0x04,0xff,0x4a,0x4a,0x4a,0xff,0xa3,0xa2,0xa3,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xcb,0xcb,0xcb,0xff,0xff,0xff,0xff,0xff,0xe7,0xe6,0xe7,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x63,0x63,0x63,0xff,0xe6,0xe6,0xe6,0xff,0xfb,0xfa,0xfb,0xff,0x51,0x50,0x51,0xff,0x00,0x00,0x00,0xff,0x7c,0x7c,0x7c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x5d,0x5b,0x5d,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x16,0x09,0x16,0xfe,0xf3,0xf2,0xf3,0xff,0xff,0xff,0xff,0xff,0xb7,0xb6,0xb7,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xf6,0xf6,0xf6,0xff,0xff,0xff,0xff,0xff,0xa0,0x9f,0xa0,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xc6,0xc5,0xc6,0xff,0xff,0xff,0xff,0xff,0xda,0xd9,0xda,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xe1,0xe1,0xe1,0xff,0xff,0xff,0xff,0xff,0xbc,0xbb,0xbc,0xfe,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xec,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xaa,0xaa,0xaa,0xff,0xff,0xff,0xff,0xff,0xe7,0xe7,0xe7,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xcb,0xcb,0xcb,0xff,0xff,0xff,0xff,0xff,0xcb,0xcb,0xcb,0xff,0x00,0x00,0x00,0xe0, + +}; + +const lv_image_dsc_t mqtt_ko = { + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.cf = LV_COLOR_FORMAT_ARGB8888, + .header.flags = 0, + .header.w = 15, + .header.h = 15, + .header.stride = 60, + .data_size = sizeof(mqtt_ko_map), + .data = mqtt_ko_map, +}; + diff --git a/main/images/mqtt_ko.png b/components/communication/images/mqtt_ko.png similarity index 100% rename from main/images/mqtt_ko.png rename to components/communication/images/mqtt_ko.png diff --git a/components/communication/images/mqtt_ok.c b/components/communication/images/mqtt_ok.c new file mode 100644 index 0000000..d122976 --- /dev/null +++ b/components/communication/images/mqtt_ok.c @@ -0,0 +1,116 @@ + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) +#include "lvgl.h" +#elif defined(LV_BUILD_TEST) +#include "../lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_MQTT_OK +#define LV_ATTRIBUTE_MQTT_OK +#endif + +static const +LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_MQTT_OK +uint8_t mqtt_ok_map[] = { + + 0x66,0x00,0x66,0xe0,0xc1,0xb3,0xc1,0xfd,0x99,0x7f,0x99,0xfe,0xe7,0xe3,0xe7,0xfe, + 0x6a,0x17,0x6a,0xfe,0x68,0x0a,0x68,0xfe,0xd6,0xce,0xd6,0xfe,0xe8,0xe3,0xe8,0xfe, + 0xa5,0x90,0xa5,0xfe,0xce,0xc3,0xce,0xfe,0xcf,0xc5,0xcf,0xfe,0xf5,0xf3,0xf5,0xfe, + 0x66,0x00,0x66,0xe1,0xc6,0xbb,0xc6,0xfe,0xff,0xff,0xff,0xff,0x66,0x00,0x66,0xff, + 0xd3,0xcb,0xd3,0xff,0xb8,0xaa,0xb8,0xff,0xfb,0xfa,0xfb,0xff,0x72,0x38,0x72,0xff, + 0xc2,0xb6,0xc2,0xff,0xb8,0xa9,0xb8,0xff,0x72,0x39,0x72,0xff,0x74,0x3c,0x74,0xff, + 0xeb,0xe7,0xeb,0xff,0xfc,0xfb,0xfc,0xff,0xea,0xe7,0xea,0xff,0x9f,0x87,0x9f,0xff, + 0xf7,0xf5,0xf7,0xff,0x9d,0x85,0x9d,0xff,0xfe,0xfe,0xfe,0xff,0xfc,0xfc,0xfc,0xff, + 0xf3,0xf1,0xf3,0xff,0xb5,0xa6,0xb5,0xff,0xef,0xed,0xef,0xff,0xe6,0xe2,0xe6,0xff, + 0xee,0xeb,0xee,0xff,0xf2,0xf0,0xf2,0xff,0xdc,0xd6,0xdc,0xff,0xc5,0xb9,0xc5,0xff, + 0xfa,0xf8,0xfa,0xff,0x74,0x3d,0x74,0xff,0x9e,0x86,0x9e,0xff,0x86,0x61,0x86,0xff, + 0xe2,0xdd,0xe2,0xff,0x8e,0x6f,0x8e,0xff,0xa3,0x8d,0xa3,0xff,0x6c,0x21,0x6c,0xff, + 0xae,0x9c,0xae,0xff,0xb4,0xa4,0xb4,0xff,0xfe,0xfd,0xfe,0xff,0xde,0xd8,0xde,0xff, + 0x83,0x5b,0x83,0xff,0x7c,0x4f,0x7c,0xff,0xee,0xec,0xee,0xff,0xaa,0x97,0xaa,0xff, + 0xf0,0xee,0xf0,0xff,0xc9,0xbe,0xc9,0xff,0xa4,0x8f,0xa4,0xff,0xea,0xe6,0xea,0xff, + 0xc5,0xba,0xc5,0xff,0x90,0x71,0x90,0xff,0xfb,0xfb,0xfb,0xff,0xc9,0xbf,0xc9,0xff, + 0x68,0x10,0x68,0xff,0x7f,0x53,0x7f,0xff,0xef,0xec,0xef,0xff,0xe8,0xe4,0xe8,0xff, + 0xcb,0xc1,0xcb,0xff,0xe3,0xde,0xe3,0xff,0xb0,0x9f,0xb0,0xff,0x7d,0x50,0x7d,0xff, + 0x8a,0x68,0x8a,0xff,0xdf,0xd9,0xdf,0xff,0xe5,0xe1,0xe5,0xff,0xf7,0xf6,0xf7,0xff, + 0x96,0x7c,0x96,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00, + + 0x00,0x0f,0x0f,0x0f,0x0f,0x16,0x11,0x22,0x0e,0x0e,0x20,0x1d,0x0f,0x0f,0x00, + 0x01,0x11,0x2e,0x29,0x0f,0x0f,0x0f,0x2f,0x14,0x12,0x0e,0x1f,0x15,0x0f,0x0f, + 0x0e,0x0e,0x0e,0x0e,0x2c,0x30,0x0f,0x0f,0x0f,0x2d,0x25,0x0e,0x0e,0x11,0x0f, + 0x1a,0x38,0x0e,0x0e,0x0e,0x0e,0x36,0x02,0x0f,0x0f,0x17,0x23,0x0e,0x1e,0x1b, + 0x0f,0x0f,0x17,0x37,0x33,0x0e,0x0e,0x0e,0x3c,0x0f,0x0f,0x13,0x24,0x0e,0x1c, + 0x0f,0x0f,0x0f,0x0f,0x0f,0x3d,0x18,0x0e,0x0e,0x10,0x0f,0x0f,0x2b,0x12,0x0e, + 0x18,0x06,0x15,0x35,0x0f,0x0f,0x40,0x10,0x0e,0x0e,0x39,0x0f,0x0f,0x21,0x0e, + 0x0e,0x0e,0x0e,0x12,0x3f,0x16,0x0f,0x0f,0x10,0x0e,0x0e,0x3a,0x0f,0x0f,0x07, + 0x09,0x26,0x28,0x0e,0x0e,0x03,0x41,0x0f,0x0f,0x45,0x0e,0x42,0x04,0x0f,0x08, + 0x0f,0x0f,0x13,0x27,0x32,0x0e,0x43,0x13,0x0f,0x48,0x19,0x0e,0x31,0x0f,0x0f, + 0x0f,0x0f,0x0f,0x0f,0x2a,0x3e,0x0e,0x44,0x0f,0x0f,0x10,0x0e,0x3b,0x0f,0x0f, + 0x0f,0x0f,0x0f,0x0f,0x0f,0x14,0x0e,0x19,0x47,0x0f,0x4c,0x0e,0x0e,0x34,0x0f, + 0x0f,0x0f,0x0f,0x0f,0x0f,0x05,0x0b,0x0e,0x14,0x0f,0x0f,0x4b,0x0e,0x46,0x0f, + 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0a,0x0e,0x49,0x0f,0x0f,0x4a,0x0e,0x0d,0x0f, + 0x00,0x0f,0x0f,0x0f,0x0f,0x0f,0x11,0x0e,0x1a,0x0f,0x0f,0x10,0x0e,0x10,0x0c, + +}; + +const lv_image_dsc_t mqtt_ok = { + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.cf = LV_COLOR_FORMAT_I8, + .header.flags = 0, + .header.w = 15, + .header.h = 15, + .header.stride = 15, + .data_size = sizeof(mqtt_ok_map), + .data = mqtt_ok_map, +}; + diff --git a/main/images/mqtt_ok.png b/components/communication/images/mqtt_ok.png similarity index 100% rename from main/images/mqtt_ok.png rename to components/communication/images/mqtt_ok.png diff --git a/components/communication/images/wifi_ko.c b/components/communication/images/wifi_ko.c new file mode 100644 index 0000000..41929a3 --- /dev/null +++ b/components/communication/images/wifi_ko.c @@ -0,0 +1,49 @@ + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) +#include "lvgl.h" +#elif defined(LV_BUILD_TEST) +#include "../lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_WIFI_KO +#define LV_ATTRIBUTE_WIFI_KO +#endif + +static const +LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_WIFI_KO +uint8_t wifi_ko_map[] = { + + 0xfe,0xfe,0xfe,0xff,0xfc,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0xf5,0xf5,0xf5,0xff,0xa5,0xa5,0xa5,0xff,0x4d,0x4d,0x4d,0xff,0x1a,0x1a,0x1a,0xff,0x00,0x00,0x00,0xff,0x79,0x79,0x79,0xff,0xff,0xff,0xff,0xff,0x5a,0x5a,0x5a,0xff,0x30,0x30,0x30,0xff,0xff,0xff,0xff,0xff,0x78,0x78,0x78,0xff,0x10,0x10,0x10,0xff, + 0xfd,0xfd,0xfd,0xff,0xff,0xff,0xff,0xff,0xa0,0xa0,0xa0,0xff,0x18,0x18,0x18,0xff,0x00,0x00,0x00,0xff,0x06,0x06,0x06,0xff,0x2e,0x2e,0x2e,0xff,0x3d,0x3d,0x3d,0xff,0xa5,0xa5,0xa5,0xff,0xff,0xff,0xff,0xff,0x89,0x89,0x89,0xff,0x00,0x00,0x00,0xff,0x2b,0x2b,0x2b,0xff,0x03,0x03,0x03,0xff,0x3c,0x3c,0x3c,0xff, + 0xf6,0xf6,0xf6,0xff,0x57,0x57,0x57,0xff,0x00,0x00,0x00,0xff,0x23,0x23,0x23,0xff,0xa5,0xa5,0xa5,0xff,0xfa,0xfa,0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0x4b,0x4b,0x4b,0xff,0x00,0x00,0x00,0xff,0x1a,0x1a,0x1a,0xff,0xe0,0xe0,0xe0,0xff, + 0x3a,0x3a,0x3a,0xff,0x00,0x00,0x00,0xff,0x77,0x77,0x77,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xbb,0xbb,0xbb,0xff,0x68,0x68,0x68,0xff,0x36,0x36,0x36,0xff,0x9e,0x9e,0x9e,0xff,0xff,0xff,0xff,0xff,0x80,0x80,0x80,0xff,0x00,0x00,0x00,0xff,0x2d,0x2d,0x2d,0xff,0x03,0x03,0x03,0xff,0x32,0x32,0x32,0xff, + 0x60,0x60,0x60,0xff,0x8f,0x8f,0x8f,0xff,0xff,0xff,0xff,0xff,0xc4,0xc4,0xc4,0xff,0x23,0x23,0x23,0xff,0x00,0x00,0x00,0xff,0x05,0x05,0x05,0xff,0x00,0x00,0x00,0xff,0x84,0x84,0x84,0xff,0xff,0xff,0xff,0xff,0x6a,0x6a,0x6a,0xff,0x46,0x46,0x46,0xff,0xff,0xff,0xff,0xff,0x88,0x88,0x88,0xff,0x27,0x27,0x27,0xff, + 0xfc,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0xab,0xab,0xab,0xff,0x00,0x00,0x00,0xff,0x10,0x10,0x10,0xff,0x96,0x96,0x96,0xff,0xf7,0xf7,0xf7,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xfe,0xfe,0xfe,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xf8,0xf8,0xf8,0xff,0xff,0xff,0xff,0xff,0x8d,0x8d,0x8d,0xff,0x29,0x29,0x29,0xff,0xe6,0xe6,0xe6,0xff,0xff,0xff,0xff,0xff,0xba,0xba,0xba,0xff,0x7d,0x7d,0x7d,0xff,0x83,0x83,0x83,0xff,0xc7,0xc7,0xc7,0xff,0xff,0xff,0xff,0xff,0xfd,0xfd,0xfd,0xff,0xfd,0xfd,0xfd,0xff,0xfd,0xfd,0xfd,0xff,0xfe,0xfe,0xfe,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xfd,0xfd,0xff,0xff,0xff,0xff,0xff,0xd4,0xd4,0xd4,0xff,0x24,0x24,0x24,0xff,0x00,0x00,0x00,0xff,0x02,0x02,0x02,0xff,0x01,0x01,0x01,0xff,0x00,0x00,0x00,0xff,0x4d,0x4d,0x4d,0xff,0xef,0xef,0xef,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0x3c,0x3c,0x3c,0xff,0x01,0x01,0x01,0xff,0x9a,0x9a,0x9a,0xff,0xf0,0xf0,0xf0,0xff,0xe5,0xe5,0xe5,0xff,0x74,0x74,0x74,0xff,0x00,0x00,0x00,0xff,0x83,0x83,0x83,0xff,0xff,0xff,0xff,0xff,0xfb,0xfb,0xfb,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xca,0xca,0xca,0xff,0xd2,0xd2,0xd2,0xff,0xff,0xff,0xff,0xff,0xc2,0xc2,0xc2,0xff,0xd4,0xd4,0xd4,0xff,0xff,0xff,0xff,0xff,0xc3,0xc3,0xc3,0xff,0xe3,0xe3,0xe3,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0x83,0x83,0x83,0xff,0x00,0x00,0x00,0xff,0x02,0x02,0x02,0xff,0xbc,0xbc,0xbc,0xff,0xff,0xff,0xff,0xff,0xfc,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf9,0xf9,0xf9,0xff,0xff,0xff,0xff,0xff,0x54,0x54,0x54,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x94,0x94,0x94,0xff,0xff,0xff,0xff,0xff,0xfa,0xfa,0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xfd,0xfd,0xff,0xff,0xff,0xff,0xff,0xca,0xca,0xca,0xff,0x1e,0x1e,0x1e,0xff,0x40,0x40,0x40,0xff,0xee,0xee,0xee,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + +}; + +const lv_image_dsc_t wifi_ko = { + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.cf = LV_COLOR_FORMAT_ARGB8888, + .header.flags = 0, + .header.w = 15, + .header.h = 13, + .header.stride = 60, + .data_size = sizeof(wifi_ko_map), + .data = wifi_ko_map, +}; + diff --git a/main/images/wifi_ko.png b/components/communication/images/wifi_ko.png similarity index 100% rename from main/images/wifi_ko.png rename to components/communication/images/wifi_ko.png diff --git a/main/images/wifi_ko_orig.png b/components/communication/images/wifi_ko_orig.png similarity index 100% rename from main/images/wifi_ko_orig.png rename to components/communication/images/wifi_ko_orig.png diff --git a/main/images/wifi_ko_orig.png:Zone.Identifier b/components/communication/images/wifi_ko_orig.png:Zone.Identifier similarity index 100% rename from main/images/wifi_ko_orig.png:Zone.Identifier rename to components/communication/images/wifi_ko_orig.png:Zone.Identifier diff --git a/components/communication/images/wifi_ok.c b/components/communication/images/wifi_ok.c new file mode 100644 index 0000000..feb8269 --- /dev/null +++ b/components/communication/images/wifi_ok.c @@ -0,0 +1,48 @@ + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) +#include "lvgl.h" +#elif defined(LV_BUILD_TEST) +#include "../lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_WIFI_OK +#define LV_ATTRIBUTE_WIFI_OK +#endif + +static const +LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_WIFI_OK +uint8_t wifi_ok_map[] = { + + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0xe5,0x00,0x00,0x00,0xf2,0x00,0x00,0x00,0xe6,0x00,0x00,0x00,0xbb,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x86,0x00,0x00,0x00,0xf9,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xe6,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0xa9,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x8c,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x29,0x00,0x00,0x00,0xd5,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xa2,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x9d,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xda,0x00,0x00,0x00,0x2f, + 0x00,0x00,0x00,0xf9,0x00,0x00,0x00,0xf3,0x00,0x00,0x00,0x3d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2f,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0xdb,0x00,0x00,0x00,0xed,0x00,0x00,0x00,0xdc,0x00,0x00,0x00,0x9e,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x00,0x00,0x00,0xee,0x00,0x00,0x00,0xfb, + 0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa1,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0xbc,0x00,0x00,0x00,0xa1,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0xf9,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xa7,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x57, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xab,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x7b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xaf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0xdb,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x43,0x00,0x00,0x00,0x45,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x05, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd3,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xc5,0x00,0x00,0x00,0x96,0x00,0x00,0x00,0xc2,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xda,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0xa8,0x00,0x00,0x00,0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4d,0x00,0x00,0x00,0xa4,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0xe6,0x00,0x00,0x00,0x8b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0xfb,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x8e,0x00,0x00,0x00,0xf5,0x00,0x00,0x00,0x96,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +}; + +const lv_image_dsc_t wifi_ok = { + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.cf = LV_COLOR_FORMAT_ARGB8888, + .header.flags = 0, + .header.w = 15, + .header.h = 12, + .header.stride = 60, + .data_size = sizeof(wifi_ok_map), + .data = wifi_ok_map, +}; + diff --git a/main/images/wifi_ok.png b/components/communication/images/wifi_ok.png similarity index 100% rename from main/images/wifi_ok.png rename to components/communication/images/wifi_ok.png diff --git a/main/images/wifi_ok_orig.png b/components/communication/images/wifi_ok_orig.png similarity index 100% rename from main/images/wifi_ok_orig.png rename to components/communication/images/wifi_ok_orig.png diff --git a/main/mqtt.h b/components/communication/include/communication.h similarity index 51% rename from main/mqtt.h rename to components/communication/include/communication.h index 5e813fa..aa115e7 100644 --- a/main/mqtt.h +++ b/components/communication/include/communication.h @@ -1,3 +1,2 @@ -#pragma once - -void mqtt_app_start(void); +void mqtt_app_start(void); +void wifi_init_sta(void); \ No newline at end of file diff --git a/components/image_downloader/image_downloader.c b/components/image_downloader/image_downloader.c index f7672f9..bf7ac53 100644 --- a/components/image_downloader/image_downloader.c +++ b/components/image_downloader/image_downloader.c @@ -42,9 +42,9 @@ static const char *TAG = "ImgDwn"; #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) -#define IMGDWN_WIDTH_STR "500" +#define IMGDWN_WIDTH_STR "800" #define IMGDWN_WIDTH 620 -#define IMGDWN_HEIGHT_STR "300" +#define IMGDWN_HEIGHT_STR "600" #define IMGDWN_HEIGHT 460 #define IMGDWN_URL2 ("http://vps-edf71efa.vps.ovh.net:3000/render/d-solo/7BtRMrv4k/temperatures?orgId=1&var-emplacement=entree_ECS&var-emplacement=entree_reseauSol&panelId=4&width=650&height=460&scale=1&tz=Europe%2FParis/") #define IMGDWN_URL ("http://vps-edf71efa.vps.ovh.net:3000/render/d-solo/bOcPeysGz/hauteur-cuve?orgId=1&from=now-2d&refresh=1m&panelId=4&width=" IMGDWN_WIDTH_STR "&height=" IMGDWN_HEIGHT_STR "&scale=1&tz=Europe%2FParis") // 650 460 diff --git a/components/meteofrance/CMakeLists.txt b/components/meteofrance/CMakeLists.txt index 40575ad..2463fdc 100644 --- a/components/meteofrance/CMakeLists.txt +++ b/components/meteofrance/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "meteofrance.c" INCLUDE_DIRS "include" - REQUIRES json esp_http_client esp-tls) + REQUIRES json esp_http_client esp-tls stateManagement) diff --git a/components/meteofrance/include/meteofrance.h b/components/meteofrance/include/meteofrance.h index 39c6a2f..dcae367 100644 --- a/components/meteofrance/include/meteofrance.h +++ b/components/meteofrance/include/meteofrance.h @@ -1,6 +1,7 @@ #pragma once #include "time.h" #include "stdbool.h" +#include "stateManagement.h" /*struct node { struct node *next; diff --git a/components/meteofrance/meteofrance.c b/components/meteofrance/meteofrance.c index a3a49fb..873e7cb 100644 --- a/components/meteofrance/meteofrance.c +++ b/components/meteofrance/meteofrance.c @@ -22,6 +22,7 @@ #include "cJSON.h" #include "esp_http_client.h" #include "esp_tls.h" +#include "stateManagement.h" static const char *TAG = "MeteoFrance"; @@ -318,6 +319,12 @@ static void http_request_task(void *pvParameter) { while (1) { + if(!mainState.wifi_init){ + //On attend le wifi + ESP_LOGI(TAG, "Pas de wifi on attend 5 secondes"); + vTaskDelay(10000 / portTICK_PERIOD_MS); + + }else{ ESP_LOGV(TAG, "Début recup méteo --------------------------"); weather.data_retreived_cb_start(NULL); char *local_response_buffer = heap_caps_malloc((MAX_HTTP_OUTPUT_BUFFER + 1) * (sizeof(char)), MALLOC_CAP_SPIRAM); @@ -369,6 +376,7 @@ static void http_request_task(void *pvParameter) ESP_LOGI(TAG, "Données non valides on attend avant de retenter"); vTaskDelay(30000 / portTICK_PERIOD_MS); } + } } } @@ -385,6 +393,7 @@ void on_weather_data_retrieval_start(weather_data_callback data_retreived_cb_sta void initialise_weather_data_retrieval(unsigned long retreival_period) { + weather.retreival_period = retreival_period; // http_client_on_process_chunk(&http_client, process_chunk); diff --git a/components/stateManagement/CMakeLists.txt b/components/stateManagement/CMakeLists.txt new file mode 100644 index 0000000..dde2ced --- /dev/null +++ b/components/stateManagement/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "stateManagement.c" + INCLUDE_DIRS "include") diff --git a/components/stateManagement/include/stateManagement.h b/components/stateManagement/include/stateManagement.h new file mode 100644 index 0000000..61e5c13 --- /dev/null +++ b/components/stateManagement/include/stateManagement.h @@ -0,0 +1,9 @@ +#pragma once +#include "stdbool.h" +struct state +{ + bool display_init; + bool wifi_init; +}; + +extern struct state mainState; diff --git a/components/stateManagement/stateManagement.c b/components/stateManagement/stateManagement.c new file mode 100644 index 0000000..7cd4f0e --- /dev/null +++ b/components/stateManagement/stateManagement.c @@ -0,0 +1,7 @@ +#include +#include "stateManagement.h" + +void func(void) +{ + +} diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e5184e0..39c1c1e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,7 +2,7 @@ set(EXTRA_COMPONENT_DIRS ../components) idf_component_register(SRC_DIRS . fonts INCLUDE_DIRS "." - REQUIRES heap esp_wifi nvs_flash mqtt meteofrance esp_netif image_downloader fatfs sdmmc vfs littlefs wifi_logger protocol_examples_common app_update esp_https_ota bsp_extra esp32_p4_function_ev_board + REQUIRES heap nvs_flash meteofrance communication esp_netif image_downloader fatfs sdmmc vfs littlefs wifi_logger protocol_examples_common app_update esp_https_ota bsp_extra esp32_p4_function_ev_board EMBED_TXTFILES ${project_dir}/main/ca_cert.pem) @@ -11,11 +11,6 @@ set_source_files_properties( "-DLV_LVGL_H_INCLUDE_SIMPLE;-Wno-format;-DLV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(montserrat_medium_12) LV_FONT_DECLARE(montserrat_medium_18) LV_FONT_DECLARE(montserrat_medium_24)" ) -lvgl_port_create_c_image("images/wifi_ok.png" "images/" "ARGB8888" "NONE") -lvgl_port_create_c_image("images/wifi_ko.png" "images/" "ARGB8888" "NONE") -lvgl_port_create_c_image("images/mqtt_ok.png" "images/" "AUTO" "NONE") -lvgl_port_create_c_image("images/mqtt_ko.png" "images/" "ARGB8888" "NONE") - lvgl_port_add_images(${COMPONENT_LIB} "images/") littlefs_create_partition_image(littlefs images_meteo FLASH_IN_PROJECT) \ No newline at end of file diff --git a/main/fatfs.c b/main/fatfs.c deleted file mode 100644 index 7040681..0000000 --- a/main/fatfs.c +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @file lv_fs_fatfs.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "ff.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - diff --git a/main/fatfs.h b/main/fatfs.h deleted file mode 100644 index f8ed143..0000000 --- a/main/fatfs.h +++ /dev/null @@ -1,2 +0,0 @@ -void my_fatfs_init(void); -#pragma once diff --git a/main/ihm.c b/main/ihm.c index b23e7bb..f42a190 100644 --- a/main/ihm.c +++ b/main/ihm.c @@ -7,6 +7,7 @@ #include "esp_log.h" #include "string.h" #include "meteofrance.h" +#include "main.h" extern char *upEvent; @@ -77,9 +78,7 @@ static void event_handler(lv_event_t *e) } } -void app_main_display() -{ - +void init_display(){ bsp_display_cfg_t cfg = { .lvgl_port_cfg = ESP_LVGL_PORT_INIT_CONFIG(), .buffer_size = BSP_LCD_DRAW_BUFF_SIZE, @@ -90,13 +89,38 @@ void app_main_display() .sw_rotate = false, } }; - /*lv_display_t *dsp =*/ bsp_display_start_with_config(&cfg); + ESP_LOGE(TAG,"On demarre le display"); + lv_display_t *dsp = bsp_display_start_with_config(&cfg); //bsp_display_rotate(dsp,LV_DISP_ROTATION_180); bsp_display_backlight_on(); + mainState.display_init=true; +} + + +void app_main_display() +{ lv_subject_init_int(&meteoStatus, -1); + + struct meteodailyforecast_data d; + struct dailyforecast_prev p; + lv_strcpy(p.desc, ""); + d.previsions = p; + lv_subject_init_pointer(&forecastD1Subj, &d); + lv_subject_init_pointer(&forecastD2Subj, &d); + lv_subject_init_pointer(&forecastD3Subj, &d); + + struct meteoforecast_data d1; + struct forecast_prev p1; + lv_strcpy(p1.desc, ""); + + d1.previsions = p1; + lv_subject_init_pointer(&forecastH1Subj, &d1); + lv_subject_init_pointer(&forecastH2Subj, &d1); + lv_subject_init_pointer(&forecastH3Subj, &d1); + on_weather_data_retrieval(weather_data_retreived); on_weather_data_retrieval_start(weather_data_retreived_start); initialise_weather_data_retrieval(600000); @@ -284,7 +308,9 @@ void showMeteoIcon(const char *icon, lv_obj_t *desc_icon, int childNr) char *str1 = "A:/littlefs/"; char *result = malloc(strlen(str1) + strlen(icon) + 6); sprintf(result, "%s%s.png", str1, icon); + ESP_LOGE(TAG,"On affiche l'image %s", result); lv_image_set_src(img, result); + free(result); } /* ------------------------------------------------------------ */ /* Fragment meteo journaliere (date,icone, min et max) */ @@ -917,24 +943,7 @@ void draw_ihm() lv_subject_init_string(&hauteurCuveSubj, hauteurCuveStr, NULL, 9, "--"); lv_subject_init_string(&hauteurCuveEvolSubj, hauteurCuveEvolStr, NULL, 9, "--"); - struct meteodailyforecast_data d; - struct dailyforecast_prev p; - lv_strcpy(p.desc, ""); - d.previsions = p; - lv_subject_init_pointer(&forecastD1Subj, &d); - lv_subject_init_pointer(&forecastD2Subj, &d); - lv_subject_init_pointer(&forecastD3Subj, &d); - - struct meteoforecast_data d1; - struct forecast_prev p1; - lv_strcpy(p1.desc, ""); - - d1.previsions = p1; - lv_subject_init_pointer(&forecastH1Subj, &d1); - lv_subject_init_pointer(&forecastH2Subj, &d1); - lv_subject_init_pointer(&forecastH3Subj, &d1); - - // keys.clear(); + // keys.clear(); lv_obj_clean(lv_scr_act()); //Create a Tab view object diff --git a/main/ihm.h b/main/ihm.h index 77b9588..a61fb61 100644 --- a/main/ihm.h +++ b/main/ihm.h @@ -3,7 +3,8 @@ #include "esp_lvgl_port.h" #include "bsp/esp-bsp.h" -void app_main_display(void); +void app_main_display(); +void init_display(); bool display_lock(const char *TAG); diff --git a/main/images/wifi_ok_orig.png:Zone.Identifier b/main/images/wifi_ok_orig.png:Zone.Identifier deleted file mode 100644 index 30c4775..0000000 --- a/main/images/wifi_ok_orig.png:Zone.Identifier +++ /dev/null @@ -1,4 +0,0 @@ -[ZoneTransfer] -ZoneId=3 -ReferrerUrl=https://www.flaticon.com/packs/system-and-calendar -HostUrl=https://www.flaticon.com/download/icon/10179079?icon_id=10179079&author=4014&team=4014&keyword=Wifi&pack=packs%2Fsystem-and-calendar&style=1369&format=png&color=%23000000&colored=1&size=512&selection=1&premium=0&type=standard diff --git a/main/images_meteo/p3bisj.png b/main/images_meteo/p3bisj.png new file mode 100644 index 0000000..233c5e6 Binary files /dev/null and b/main/images_meteo/p3bisj.png differ diff --git a/main/images_meteo/p6bisj.png:Zone.Identifier b/main/images_meteo/p6bisj.png:Zone.Identifier deleted file mode 100644 index e69de29..0000000 diff --git a/main/main.c b/main/main.c index c59b0fa..2e3b259 100644 --- a/main/main.c +++ b/main/main.c @@ -27,9 +27,8 @@ #include "wifi_logger.h" #include "obtain_time.h" #include "image_downloader.h" -#include "wifi.h" -#include "mqtt.h" - +#include "communication.h" +#include "stateManagement.h" #include "am2302_rmt.h" @@ -52,6 +51,12 @@ static const char *TAG = "domoTic"; extern esp_mqtt_client_handle_t client; + +struct state mainState={ + .wifi_init=false, + .display_init=false +}; + void mount_sd_card() { // Options for mounting the filesystem. @@ -246,11 +251,17 @@ void readTempHumid(void *pvParameter) } +void alloc_fail(size_t size, uint32_t caps, const char * function_name){ + ESP_LOGE(TAG,"fail alloc %u in %" PRIu32 " in %s", size,caps,function_name); + +} void app_main(void) { printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); printf("Free heap size: %" PRIu32 " bytes\n", esp_get_free_heap_size()); + heap_caps_print_heap_info(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + heap_caps_register_failed_alloc_callback(alloc_fail); printf("1- Free heap after buffers allocation: %d\n", xPortGetFreeHeapSize()); @@ -278,9 +289,43 @@ void app_main(void) printf("6 - Free heap after buffers allocation: %d\n", xPortGetFreeHeapSize()); + ESP_LOGI(TAG, "Initializing LittleFS"); + + esp_vfs_littlefs_conf_t conflfs = { + .base_path = "/littlefs", + .partition_label = "littlefs", + .format_if_mount_failed = true, + .dont_mount = false, + }; + // Use settings defined above to initialize and mount LittleFS filesystem. + // Note: esp_vfs_littlefs_register is an all-in-one convenience function. + esp_err_t retlfs = esp_vfs_littlefs_register(&conflfs); + + if (retlfs != ESP_OK){ + if (retlfs == ESP_FAIL){ + ESP_LOGE(TAG, "Failed to mount or format filesystem"); + }else if (retlfs == ESP_ERR_NOT_FOUND){ + ESP_LOGE(TAG, "Failed to find LittleFS partition"); + }else{ + ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(retlfs)); + } + return; + } + + size_t total = 0, used = 0; + retlfs = esp_littlefs_info(conflfs.partition_label, &total, &used); + if (retlfs != ESP_OK) + { + ESP_LOGE(TAG, "Failed to get LittleFS partition information (%s)", esp_err_to_name(retlfs)); + } + else + { + ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used); + } // On affiche au plus tot l'ecran de démarrage - // ESP_ERROR_CHECK(esp_lcd_panel_mirror(lcd_panel,true,true)); + // ESP_ERROR_CHECK(esp_lcd_panel_mirror(lcd_panel,true,true)); + init_display(); display_lock("app_main"); app_main_display(); display_unlock("app_main"); @@ -359,42 +404,7 @@ void app_main(void) mqtt_app_start(); - ESP_LOGI(TAG, "Initializing LittleFS"); - - esp_vfs_littlefs_conf_t conflfs = { - .base_path = "/littlefs", - .partition_label = "littlefs", - .format_if_mount_failed = true, - .dont_mount = false, - }; - - // Use settings defined above to initialize and mount LittleFS filesystem. - // Note: esp_vfs_littlefs_register is an all-in-one convenience function. - ret = esp_vfs_littlefs_register(&conflfs); - - if (ret != ESP_OK){ - if (ret == ESP_FAIL){ - ESP_LOGE(TAG, "Failed to mount or format filesystem"); - }else if (ret == ESP_ERR_NOT_FOUND){ - ESP_LOGE(TAG, "Failed to find LittleFS partition"); - }else{ - ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret)); - } - return; - } - - size_t total = 0, used = 0; - ret = esp_littlefs_info(conflfs.partition_label, &total, &used); - if (ret != ESP_OK) - { - ESP_LOGE(TAG, "Failed to get LittleFS partition information (%s)", esp_err_to_name(ret)); - } - else - { - ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used); - } - - + // Configuration de la sonde Temp/Humid. am2302_config_t am2302_config = { .gpio_num = AM2302_GPIO, diff --git a/main/wifi.c b/main/wifi.c deleted file mode 100644 index 4da8f0d..0000000 --- a/main/wifi.c +++ /dev/null @@ -1,184 +0,0 @@ -#include "wifi.h" -#include "esp_wifi.h" -#include "esp_log.h" -#include "esp_lvgl_port.h" - -/* FreeRTOS event group to signal when we are connected*/ -static EventGroupHandle_t s_wifi_event_group; - -/* The event group allows multiple bits for each event, but we only care about two events: - * - we are connected to the AP with an IP - * - we failed to connect after the maximum amount of retries */ -#define WIFI_CONNECTED_BIT BIT0 -#define WIFI_FAIL_BIT BIT1 - -#define EXAMPLE_ESP_WIFI_SSID "wifimms3" -#define EXAMPLE_ESP_WIFI_PASS "mmswifi0611" -#define EXAMPLE_ESP_MAXIMUM_RETRY 5 - -#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH -#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID -#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK - -static const char *TAG = "wifi"; - -static int s_retry_num = 0; - -static lv_subject_t wifiStatus; -LV_IMAGE_DECLARE(wifi_ok); -LV_IMAGE_DECLARE(wifi_ko); - -static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject); - - -static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) -{ - ESP_LOGE(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); - lv_obj_t * wifiSt = lv_obj_get_child(lv_obj_get_child(lv_layer_top(), 0),2); - if(lv_obj_check_type(wifiSt, &lv_image_class)){ - switch (lv_subject_get_int(subject)) - { - case 0: - lv_image_set_src(wifiSt,&wifi_ko); - break; - case 1: - lv_image_set_src(wifiSt,&wifi_ok); - break; - default: - break; - } - }else{ - ESP_LOGE(TAG, "L'objet recuip en semble pas etre du bon type"); - } - //int32_t prev_v = lv_subject_get_previous_int(subject); - //int32_t cur_v = lv_subject_get_int(subject); - - //lv_obj_t * btn = lv_observer_get_target(observer); -} - -static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) -{ - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) - { - esp_wifi_connect(); - } - else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) - { - if(lvgl_port_lock(0)){ - ESP_LOGE(TAG,"Statut Wifi 0"); - lv_subject_set_int(&wifiStatus,0); - lvgl_port_unlock(); - } - if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) - { - esp_wifi_connect(); - s_retry_num++; - ESP_LOGI(TAG, "retry to connect to the AP"); - } - else - { - xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); - } - ESP_LOGI(TAG, "connect to the AP fail"); - } - else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) - { - if(lvgl_port_lock(0)){ - ESP_LOGE(TAG,"Statut Wifi 1"); - lv_subject_set_int(&wifiStatus,1); - lvgl_port_unlock(); - } - ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; - ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); - s_retry_num = 0; - xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); - } -} -void wifi_init_sta(void) -{ - s_wifi_event_group = xEventGroupCreate(); - - ESP_ERROR_CHECK(esp_netif_init()); - - ESP_ERROR_CHECK(esp_event_loop_create_default()); - esp_netif_create_default_wifi_sta(); - - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - - esp_event_handler_instance_t instance_any_id; - esp_event_handler_instance_t instance_got_ip; - ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, - ESP_EVENT_ANY_ID, - &wifi_event_handler, - NULL, - &instance_any_id)); - ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, - IP_EVENT_STA_GOT_IP, - &wifi_event_handler, - NULL, - &instance_got_ip)); - - wifi_config_t wifi_config = { - .sta = { - .ssid = EXAMPLE_ESP_WIFI_SSID, - .password = EXAMPLE_ESP_WIFI_PASS, - /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (pasword len => 8). - * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value - * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to - * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards. - */ - .threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD, - .sae_pwe_h2e = ESP_WIFI_SAE_MODE, - .sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER, - }, - }; - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); - ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); - ESP_ERROR_CHECK(esp_wifi_start()); - - ESP_LOGI(TAG, "wifi_init_sta finished."); - lv_subject_init_int(&wifiStatus,0); - lv_subject_add_observer_obj(&wifiStatus, wifiStatus_obs_cb, NULL, NULL); - - - /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum - * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ - EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, - WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, - pdFALSE, - pdFALSE, - portMAX_DELAY); - - /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually - * happened. */ - if (bits & WIFI_CONNECTED_BIT) - { - ESP_LOGI(TAG, "connected to ap SSID:%s", EXAMPLE_ESP_WIFI_SSID); - if(lvgl_port_lock(0)){ - ESP_LOGE(TAG,"Statut Wifi 1"); - lv_subject_set_int(&wifiStatus,1); - lvgl_port_unlock(); - } - } - else if (bits & WIFI_FAIL_BIT) - { - ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", - EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); - if(lvgl_port_lock(0)){ - ESP_LOGE(TAG,"Statut Wifi 0"); - lv_subject_set_int(&wifiStatus,0); - lvgl_port_unlock(); - } - } - else - { - ESP_LOGE(TAG, "UNEXPECTED EVENT"); - if(lvgl_port_lock(0)){ - ESP_LOGE(TAG,"Statut Wifi 0"); - lv_subject_set_int(&wifiStatus,0); - lvgl_port_unlock(); - } - - } -} diff --git a/main/wifi.h b/main/wifi.h deleted file mode 100644 index d992b86..0000000 --- a/main/wifi.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -void wifi_init_sta(void); \ No newline at end of file diff --git a/sdkconfig b/sdkconfig index 1dcd0a9..14c670f 100644 --- a/sdkconfig +++ b/sdkconfig @@ -1236,10 +1236,12 @@ CONFIG_SPIRAM_FLASH_LOAD_TO_PSRAM=y CONFIG_SPIRAM_BOOT_INIT=y # CONFIG_SPIRAM_IGNORE_NOTFOUND is not set # CONFIG_SPIRAM_USE_MEMMAP is not set -CONFIG_SPIRAM_USE_CAPS_ALLOC=y -# CONFIG_SPIRAM_USE_MALLOC is not set +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +CONFIG_SPIRAM_USE_MALLOC=y CONFIG_SPIRAM_MEMTEST=y -# CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384 +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768 # CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set # CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set # end of PSRAM config @@ -1367,8 +1369,9 @@ CONFIG_ESP_TIMER_IMPL_SYSTIMER=y # CONFIG_ESP_HOST_WIFI_ENABLED is not set CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32 -CONFIG_ESP_WIFI_TX_BUFFER_TYPE=1 -CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=32 +CONFIG_ESP_WIFI_TX_BUFFER_TYPE=0 +CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=16 +CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=32 CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0 CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5 CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y @@ -1680,6 +1683,7 @@ CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4 CONFIG_LWIP_TCP_OVERSIZE_MSS=y # CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set # CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set +# CONFIG_LWIP_WND_SCALE is not set CONFIG_LWIP_TCP_RTO_TIME=1500 # end of TCP @@ -2393,10 +2397,10 @@ CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y # CONFIG_WIFI_RMT_STATIC_RX_BUFFER_NUM=10 CONFIG_WIFI_RMT_DYNAMIC_RX_BUFFER_NUM=32 -# CONFIG_WIFI_RMT_STATIC_TX_BUFFER is not set -CONFIG_WIFI_RMT_DYNAMIC_TX_BUFFER=y -CONFIG_WIFI_RMT_TX_BUFFER_TYPE=1 -CONFIG_WIFI_RMT_DYNAMIC_TX_BUFFER_NUM=32 +CONFIG_WIFI_RMT_STATIC_TX_BUFFER=y +CONFIG_WIFI_RMT_TX_BUFFER_TYPE=0 +CONFIG_WIFI_RMT_STATIC_TX_BUFFER_NUM=16 +CONFIG_WIFI_RMT_CACHE_TX_BUFFER_NUM=32 CONFIG_WIFI_RMT_STATIC_RX_MGMT_BUFFER=y # CONFIG_WIFI_RMT_DYNAMIC_RX_MGMT_BUFFER is not set CONFIG_WIFI_RMT_DYNAMIC_RX_MGMT_BUF=0 @@ -2406,6 +2410,7 @@ CONFIG_WIFI_RMT_AMPDU_TX_ENABLED=y CONFIG_WIFI_RMT_TX_BA_WIN=6 CONFIG_WIFI_RMT_AMPDU_RX_ENABLED=y CONFIG_WIFI_RMT_RX_BA_WIN=6 +# CONFIG_WIFI_RMT_AMSDU_TX_ENABLED is not set CONFIG_WIFI_RMT_NVS_ENABLED=y CONFIG_WIFI_RMT_SOFTAP_BEACON_MAX_LEN=752 CONFIG_WIFI_RMT_MGMT_SBUF_NUM=32 @@ -2505,8 +2510,8 @@ CONFIG_LV_COLOR_DEPTH=16 # # Memory Settings # -CONFIG_LV_USE_BUILTIN_MALLOC=y -# CONFIG_LV_USE_CLIB_MALLOC is not set +# CONFIG_LV_USE_BUILTIN_MALLOC is not set +CONFIG_LV_USE_CLIB_MALLOC=y # CONFIG_LV_USE_MICROPYTHON_MALLOC is not set # CONFIG_LV_USE_RTTHREAD_MALLOC is not set # CONFIG_LV_USE_CUSTOM_MALLOC is not set @@ -2516,9 +2521,6 @@ CONFIG_LV_USE_BUILTIN_STRING=y # CONFIG_LV_USE_BUILTIN_SPRINTF is not set CONFIG_LV_USE_CLIB_SPRINTF=y # CONFIG_LV_USE_CUSTOM_SPRINTF is not set -CONFIG_LV_MEM_SIZE_KILOBYTES=64 -CONFIG_LV_MEM_POOL_EXPAND_SIZE_KILOBYTES=0 -CONFIG_LV_MEM_ADR=0x0 # end of Memory Settings # @@ -2587,24 +2589,24 @@ CONFIG_LV_USE_DRAW_SW_ASM=0 # CONFIG_LV_USE_LOG=y # CONFIG_LV_LOG_LEVEL_TRACE is not set -# CONFIG_LV_LOG_LEVEL_INFO is not set -CONFIG_LV_LOG_LEVEL_WARN=y +CONFIG_LV_LOG_LEVEL_INFO=y +# CONFIG_LV_LOG_LEVEL_WARN is not set # CONFIG_LV_LOG_LEVEL_ERROR is not set # CONFIG_LV_LOG_LEVEL_USER is not set # CONFIG_LV_LOG_LEVEL_NONE is not set -CONFIG_LV_LOG_LEVEL=2 +CONFIG_LV_LOG_LEVEL=1 CONFIG_LV_LOG_PRINTF=y -CONFIG_LV_LOG_USE_TIMESTAMP=y -CONFIG_LV_LOG_USE_FILE_LINE=y -CONFIG_LV_LOG_TRACE_MEM=y -CONFIG_LV_LOG_TRACE_TIMER=y -CONFIG_LV_LOG_TRACE_INDEV=y -CONFIG_LV_LOG_TRACE_DISP_REFR=y -CONFIG_LV_LOG_TRACE_EVENT=y -CONFIG_LV_LOG_TRACE_OBJ_CREATE=y -CONFIG_LV_LOG_TRACE_LAYOUT=y -CONFIG_LV_LOG_TRACE_ANIM=y -CONFIG_LV_LOG_TRACE_CACHE=y +# CONFIG_LV_LOG_USE_TIMESTAMP is not set +# CONFIG_LV_LOG_USE_FILE_LINE is not set +# CONFIG_LV_LOG_TRACE_MEM is not set +# CONFIG_LV_LOG_TRACE_TIMER is not set +# CONFIG_LV_LOG_TRACE_INDEV is not set +# CONFIG_LV_LOG_TRACE_DISP_REFR is not set +# CONFIG_LV_LOG_TRACE_EVENT is not set +# CONFIG_LV_LOG_TRACE_OBJ_CREATE is not set +# CONFIG_LV_LOG_TRACE_LAYOUT is not set +# CONFIG_LV_LOG_TRACE_ANIM is not set +# CONFIG_LV_LOG_TRACE_CACHE is not set # end of Logging # @@ -2949,8 +2951,9 @@ CONFIG_IPC_TASK_STACK_SIZE=1024 CONFIG_TIMER_TASK_STACK_SIZE=3584 CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 -CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 +CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 +CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 +CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=32 CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y CONFIG_ESP32_WIFI_TX_BA_WIN=6 CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y @@ -3051,8 +3054,9 @@ CONFIG_TO_WIFI_DATA_THROTTLE_HIGH_THRESHOLD=80 CONFIG_TO_WIFI_DATA_THROTTLE_LOW_THRESHOLD=60 CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 -CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 +CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 +CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 +CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=32 CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y CONFIG_ESP32_WIFI_TX_BA_WIN=6 CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y