diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 54f8928..d4ec8da 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,9 +1,9 @@ set(EXTRA_COMPONENT_DIRS ../components) -set(comps heap nvs_flash meteofrance esp_netif image_downloader fatfs protocol_examples_common mqtt esp_wifi) +set(comps heap nvs_flash meteofrance esp_netif image_downloader fatfs protocol_examples_common mqtt ) if(${IDF_TARGET} STREQUAL "esp32p4") - list(APPEND comps bsp_extra esp32_p4_function_ev_board sdmmc vfs littlefs wifi_logger app_update esp_https_ota espcoredump esp_http_server) + list(APPEND comps bsp_extra esp32_p4_function_ev_board sdmmc vfs littlefs wifi_logger app_update esp_https_ota espcoredump esp_http_server esp_wifi) endif() function (make_font fontSize) diff --git a/main/communication.c b/main/communication.c index 872eab0..5f27de1 100644 --- a/main/communication.c +++ b/main/communication.c @@ -86,6 +86,9 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_ 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, topicConsoElec, 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); diff --git a/main/ihm.c b/main/ihm.c index 6ac637e..d684173 100644 --- a/main/ihm.c +++ b/main/ihm.c @@ -90,6 +90,9 @@ static void draw_temp(char * tempHumid){ } } +lv_obj_t* myChart; +lv_chart_series_t * ser; + void drawIhm(void *xIHMEventQueue){ init_display(); @@ -137,7 +140,18 @@ void drawIhm(void *xIHMEventQueue){ draw_temp((char *)xReceivedEvent.pvData); ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- end"); break; - + case IHM_EVT_PUISSANCE_EMISE: + if(display_lock("updateChart")){ + ESP_LOGE(TAG,"On a recu %i",(int)xReceivedEvent.pvData); + if((int)xReceivedEvent.pvData==0){ + lv_chart_set_next_value(myChart,ser,LV_CHART_POINT_NONE); + }else{ + lv_chart_set_next_value(myChart,ser,(int)xReceivedEvent.pvData); + } + //lv_chart_refresh(myChart); + display_unlock("updateChart"); + } + break; default: ESP_LOGE(TAG, "Evt inconnu"); break; @@ -163,7 +177,7 @@ static void event_handler(lv_event_t *e) break; case LV_EVENT_CLICKED: ESP_LOGI(TAG, "%s was clicked\n", evtData); - //esp_mqtt_client_publish(client, "volets", evtData, 0, 0, 0); + send_event(EVT_BTN_VOLET,evtData); break; case LV_EVENT_LONG_PRESSED: LV_LOG_USER("%s was long pressed\n", evtData); @@ -658,6 +672,53 @@ static void log_event_handler(lv_event_t * e) static lv_style_t style_lbvValue; static lv_style_t style_btn; +static void draw_event_cb(lv_event_t * e) +{ + lv_draw_task_t * draw_task = lv_event_get_draw_task(e); + lv_draw_dsc_base_t * base_dsc = lv_draw_task_get_draw_dsc(draw_task); + + if(base_dsc->part != LV_PART_ITEMS) { + return; + } + + lv_draw_fill_dsc_t * fill_dsc = lv_draw_task_get_fill_dsc(draw_task); + if(fill_dsc) { + lv_obj_t * chart = lv_event_get_target(e); + int32_t * y_array = lv_chart_get_y_array(chart, ser); + int32_t v = y_array[(base_dsc->id2+lv_chart_get_x_start_point(myChart,ser))%30]; + //ESP_LOGE(TAG, "Dessin de l'index %li, valeur: %li, start point : %li",base_dsc->id2, v, lv_chart_get_x_start_point(myChart,ser)); + /*for(int i=0;i<20;i++){ + ESP_LOGE(TAG,"Tab %i : %li", i, y_array[i]); + } + */ + fill_dsc->color = lv_color_mix(lv_palette_main(LV_PALETTE_RED), lv_palette_main(LV_PALETTE_BLUE), MIN(v*255/1500,255)); + } +} + +void draw_tabMinuteur(lv_obj_t * parent) +{ + myChart = lv_chart_create(parent); + lv_chart_set_type(myChart, LV_CHART_TYPE_BAR); + lv_chart_set_point_count(myChart, 30); + lv_obj_set_style_pad_column(myChart, 2, 0); + lv_obj_set_size(myChart, 600, 500); + lv_chart_set_range(myChart, LV_CHART_AXIS_PRIMARY_Y, 0, 1500); + lv_obj_center(myChart); + + ser = lv_chart_add_series(myChart, lv_color_hex(0xff0000), LV_CHART_AXIS_PRIMARY_Y); + lv_obj_add_event_cb(myChart, draw_event_cb, LV_EVENT_DRAW_TASK_ADDED, NULL); + lv_obj_add_flag(myChart, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS); + //uint32_t i; + lv_chart_set_update_mode(myChart,LV_CHART_UPDATE_MODE_SHIFT); + /*for(i = 0; i < 60; i++) { + lv_chart_set_next_value(myChart, ser, (int32_t)lv_rand(10, 1500)); + }*/ + /*for(int i=0; i<30; i++){ + ser->y_points[i]=LV_CHART_POINT_NONE; + }*/ + +} + void draw_tabSettings(lv_obj_t * parent) { lv_obj_t *btnGrp = lv_obj_create(parent); @@ -982,6 +1043,7 @@ void draw_ihm() draw_tabMeteo(tabMeteo); draw_tabCuve(tabCuve); draw_tabSettings(tabSettings); + draw_tabMinuteur(tabMinuteur); lv_obj_set_flex_flow(tabVolets, LV_FLEX_FLOW_ROW); diff --git a/main/ihm.h b/main/ihm.h index 71d560e..774d0a6 100644 --- a/main/ihm.h +++ b/main/ihm.h @@ -36,7 +36,8 @@ typedef enum eIHMEvent_t{ IHM_EVT_TIME_SETTED, IHM_EVT_OTA_STARTED, IHM_EVT_OTA_PROGRESS, - IHM_EVT_HUMID_TEMP + IHM_EVT_HUMID_TEMP, + IHM_EVT_PUISSANCE_EMISE } eIHMEvent_t; typedef struct IP_TASK_COMMANDS diff --git a/main/include/communication.h b/main/include/communication.h index 77004f2..84d2f85 100644 --- a/main/include/communication.h +++ b/main/include/communication.h @@ -22,6 +22,7 @@ void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup); #define topicHauteurCuve "house/cuve/hauteur" #define topicTempInt "house/temp/287DCF1E00008020" #define topicHauteurCuveEvol "house/cuve/hauteurEvol" +#define topicConsoElec "energy/puissance_5mn" #define topicdomoticCommand "domotic/cmd" #define topicTest "test" diff --git a/main/main.c b/main/main.c index 9a6b4f1..37adcfa 100644 --- a/main/main.c +++ b/main/main.c @@ -98,7 +98,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){ 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 (strncmp(event->topic, topicTempExt, event->topic_len) == 0) { if(lvgl_port_lock(50)){ // on retransforme en float pour ne garder que la partie entiere de la température @@ -110,7 +110,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){ lvgl_port_unlock(); } } - else if (strncmp(event->topic, topicTempInt, 27) == 0) + else if (strncmp(event->topic, topicTempInt, event->topic_len) == 0) { if(lvgl_port_lock(0)){ // on retransforme en float pour ne garder que la partie entiere de la température @@ -121,7 +121,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){ lvgl_port_unlock(); } } - else if (strncmp(event->topic, topicHauteurCuveEvol, 22) == 0) + else if (strncmp(event->topic, topicHauteurCuveEvol, event->topic_len) == 0) { /* float datas[4] = {}; splitIt(event->data, event->data_len, datas); @@ -136,18 +136,24 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){ // lv_subject_copy_string(&hauteurCuveEvolSubj, event->data); } - else if (strncmp(event->topic, topicHauteurCuve, 18) == 0) + else if (strncmp(event->topic, topicHauteurCuve, event->topic_len) == 0) { - if (lvgl_port_lock(50)){ + 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){ + }else if (strncmp(event->topic, topicTest, event->topic_len) == 0){ ESP_LOGD(TAG,"Msg reecu sur test"); - }else if (strncmp(event->topic, topicdomoticCommand, 11) == 0){ + }else if (strncmp(event->topic, topicConsoElec, event->topic_len) == 0){ + char* datas = malloc(event->data_len+1); + strncpy(datas, event->data, event->data_len); + + send_event(EVT_PUISSANCE_RECUE,(int*)atoi(datas)); + + }else if (strncmp(event->topic, topicdomoticCommand, event->topic_len) == 0){ if(strncmp(event->data,"restart",7)==0){ ESP_LOGI(TAG," Commande 'restart' recue"); esp_restart(); @@ -155,7 +161,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){ } else { - ESP_LOGE(TAG, "None match :-( %s", event->topic); + ESP_LOGE(TAG, "None match :-( %.*s", event->topic_len, event->topic); } if (lvgl_port_lock(50)){ lv_subject_set_int(&mqttStatus,3); @@ -190,6 +196,16 @@ void send_event(domo_events evt, void* pDatas){ }; xQueueSendToFront(ihm_queue,&m,5); break; + case EVT_BTN_VOLET: + esp_mqtt_client_publish(client, "volets", pDatas, 0, 0, 0); + break; + case EVT_PUISSANCE_RECUE: + xIPStackEvent_t m1 = { + .eEventType = IHM_EVT_PUISSANCE_EMISE, + .pvData = pDatas + }; + xQueueSendToFront(ihm_queue,&m1,5); + break; } } @@ -400,7 +416,7 @@ void simple_ota_example_task(void *pvParameter) .eEventType = IHM_EVT_OTA_STARTED, .pvData = NULL }; - xQueueSendToBack(ihm_queue,&m,5); + //xQueueSendToBack(ihm_queue,&m,5); esp_task_wdt_config_t cfgWdt = { .idle_core_mask = 0, @@ -422,7 +438,7 @@ void simple_ota_example_task(void *pvParameter) //ESP_LOGE(TAG, "Image bytes read: %d %i%%", esp_https_ota_get_image_len_read(https_ota_handle),percent); m.eEventType=IHM_EVT_OTA_PROGRESS; m.pvData=(void*)percent; - xQueueSendToBack(ihm_queue,&m,5); + //xQueueSendToBack(ihm_queue,&m,5); vTaskDelay(10/portTICK_PERIOD_MS); } if (esp_https_ota_is_complete_data_received(https_ota_handle) != true) { @@ -859,7 +875,7 @@ void app_main(void) * and hence timings for overall OTA operation. */ esp_wifi_set_ps(WIFI_PS_NONE); - xTaskCreatePinnedToCore(&simple_ota_example_task, "ota_example_task", 8192, NULL, 1, NULL,0); + xTaskCreatePinnedToCore(&simple_ota_example_task, "ota__task", 8192, NULL, 1, NULL,0); on_weather_data_retrieval(weather_data_retreived); on_weather_data_retrieval_start(weather_data_retreived_start); @@ -883,8 +899,8 @@ void app_main(void) mqtt_app_start(mqtt_cb, domotic_event_group); - start_wifi_logger(); - wifi_log_e("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> ERROR } + //start_wifi_logger(); + //wifi_log_e("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> ERROR } lv_subject_init_int(&mqttStatus,-1); lv_subject_add_observer_obj(&mqttStatus, mqttStatus_obs_cb, NULL, NULL); diff --git a/main/main.h b/main/main.h index fdd80bd..f843097 100644 --- a/main/main.h +++ b/main/main.h @@ -2,6 +2,8 @@ #define WIFI_CONNECTED_BIT BIT0 typedef enum domo_events{ EVT_WIFI_CONNECTED, - EVT_TIME_SETTED + EVT_TIME_SETTED, + EVT_BTN_VOLET, + EVT_PUISSANCE_RECUE } domo_events; void send_event(domo_events evt, void* pDatas);