Conso machine

This commit is contained in:
marc 2025-05-18 09:38:00 +02:00
parent a12fd1df9d
commit ef4e4af237
7 changed files with 104 additions and 19 deletions

View File

@ -1,9 +1,9 @@
set(EXTRA_COMPONENT_DIRS ../components) 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") 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() endif()
function (make_font fontSize) function (make_font fontSize)

View File

@ -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); msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); 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); //msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
//ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); //ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);

View File

@ -90,6 +90,9 @@ static void draw_temp(char * tempHumid){
} }
} }
lv_obj_t* myChart;
lv_chart_series_t * ser;
void drawIhm(void *xIHMEventQueue){ void drawIhm(void *xIHMEventQueue){
init_display(); init_display();
@ -137,7 +140,18 @@ void drawIhm(void *xIHMEventQueue){
draw_temp((char *)xReceivedEvent.pvData); draw_temp((char *)xReceivedEvent.pvData);
ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- end"); ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- end");
break; 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: default:
ESP_LOGE(TAG, "Evt inconnu"); ESP_LOGE(TAG, "Evt inconnu");
break; break;
@ -163,7 +177,7 @@ static void event_handler(lv_event_t *e)
break; break;
case LV_EVENT_CLICKED: case LV_EVENT_CLICKED:
ESP_LOGI(TAG, "%s was clicked\n", evtData); 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; break;
case LV_EVENT_LONG_PRESSED: case LV_EVENT_LONG_PRESSED:
LV_LOG_USER("%s was long pressed\n", evtData); 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_lbvValue;
static lv_style_t style_btn; 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) void draw_tabSettings(lv_obj_t * parent)
{ {
lv_obj_t *btnGrp = lv_obj_create(parent); lv_obj_t *btnGrp = lv_obj_create(parent);
@ -982,6 +1043,7 @@ void draw_ihm()
draw_tabMeteo(tabMeteo); draw_tabMeteo(tabMeteo);
draw_tabCuve(tabCuve); draw_tabCuve(tabCuve);
draw_tabSettings(tabSettings); draw_tabSettings(tabSettings);
draw_tabMinuteur(tabMinuteur);
lv_obj_set_flex_flow(tabVolets, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(tabVolets, LV_FLEX_FLOW_ROW);

View File

@ -36,7 +36,8 @@ typedef enum eIHMEvent_t{
IHM_EVT_TIME_SETTED, IHM_EVT_TIME_SETTED,
IHM_EVT_OTA_STARTED, IHM_EVT_OTA_STARTED,
IHM_EVT_OTA_PROGRESS, IHM_EVT_OTA_PROGRESS,
IHM_EVT_HUMID_TEMP IHM_EVT_HUMID_TEMP,
IHM_EVT_PUISSANCE_EMISE
} eIHMEvent_t; } eIHMEvent_t;
typedef struct IP_TASK_COMMANDS typedef struct IP_TASK_COMMANDS

View File

@ -22,6 +22,7 @@ void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup);
#define topicHauteurCuve "house/cuve/hauteur" #define topicHauteurCuve "house/cuve/hauteur"
#define topicTempInt "house/temp/287DCF1E00008020" #define topicTempInt "house/temp/287DCF1E00008020"
#define topicHauteurCuveEvol "house/cuve/hauteurEvol" #define topicHauteurCuveEvol "house/cuve/hauteurEvol"
#define topicConsoElec "energy/puissance_5mn"
#define topicdomoticCommand "domotic/cmd" #define topicdomoticCommand "domotic/cmd"
#define topicTest "test" #define topicTest "test"

View File

@ -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, "\nMQTT_EVENT_DATA");
ESP_LOGD(TAG, "TOPIC=%.*s\n", event->topic_len, event->topic); ESP_LOGD(TAG, "TOPIC=%.*s\n", event->topic_len, event->topic);
ESP_LOGD(TAG, "DATA=%.*s\n", event->data_len, event->data); 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)){ if(lvgl_port_lock(50)){
// on retransforme en float pour ne garder que la partie entiere de la température // 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(); 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)){ if(lvgl_port_lock(0)){
// on retransforme en float pour ne garder que la partie entiere de la température // 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(); lvgl_port_unlock();
} }
} }
else if (strncmp(event->topic, topicHauteurCuveEvol, 22) == 0) else if (strncmp(event->topic, topicHauteurCuveEvol, event->topic_len) == 0)
{ {
/* float datas[4] = {}; /* float datas[4] = {};
splitIt(event->data, event->data_len, datas); 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); // 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); float temp = strtof(event->data, NULL);
char buff[5]; char buff[5];
sprintf(buff,"%.0f",temp); sprintf(buff,"%.0f",temp);
lv_subject_copy_string(&hauteurCuveSubj, buff); lv_subject_copy_string(&hauteurCuveSubj, buff);
lvgl_port_unlock(); 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"); 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){ if(strncmp(event->data,"restart",7)==0){
ESP_LOGI(TAG," Commande 'restart' recue"); ESP_LOGI(TAG," Commande 'restart' recue");
esp_restart(); esp_restart();
@ -155,7 +161,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
} }
else 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)){ if (lvgl_port_lock(50)){
lv_subject_set_int(&mqttStatus,3); lv_subject_set_int(&mqttStatus,3);
@ -190,6 +196,16 @@ void send_event(domo_events evt, void* pDatas){
}; };
xQueueSendToFront(ihm_queue,&m,5); xQueueSendToFront(ihm_queue,&m,5);
break; 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, .eEventType = IHM_EVT_OTA_STARTED,
.pvData = NULL .pvData = NULL
}; };
xQueueSendToBack(ihm_queue,&m,5); //xQueueSendToBack(ihm_queue,&m,5);
esp_task_wdt_config_t cfgWdt = { esp_task_wdt_config_t cfgWdt = {
.idle_core_mask = 0, .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); //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.eEventType=IHM_EVT_OTA_PROGRESS;
m.pvData=(void*)percent; m.pvData=(void*)percent;
xQueueSendToBack(ihm_queue,&m,5); //xQueueSendToBack(ihm_queue,&m,5);
vTaskDelay(10/portTICK_PERIOD_MS); vTaskDelay(10/portTICK_PERIOD_MS);
} }
if (esp_https_ota_is_complete_data_received(https_ota_handle) != true) { 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. * and hence timings for overall OTA operation.
*/ */
esp_wifi_set_ps(WIFI_PS_NONE); 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(weather_data_retreived);
on_weather_data_retrieval_start(weather_data_retreived_start); 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); mqtt_app_start(mqtt_cb, domotic_event_group);
start_wifi_logger(); //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 } //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_init_int(&mqttStatus,-1);
lv_subject_add_observer_obj(&mqttStatus, mqttStatus_obs_cb, NULL, NULL); lv_subject_add_observer_obj(&mqttStatus, mqttStatus_obs_cb, NULL, NULL);

View File

@ -2,6 +2,8 @@
#define WIFI_CONNECTED_BIT BIT0 #define WIFI_CONNECTED_BIT BIT0
typedef enum domo_events{ typedef enum domo_events{
EVT_WIFI_CONNECTED, EVT_WIFI_CONNECTED,
EVT_TIME_SETTED EVT_TIME_SETTED,
EVT_BTN_VOLET,
EVT_PUISSANCE_RECUE
} domo_events; } domo_events;
void send_event(domo_events evt, void* pDatas); void send_event(domo_events evt, void* pDatas);