remise cuve

This commit is contained in:
marc 2025-05-18 21:35:24 +02:00
parent c690ac01e1
commit de8d9ede17
7 changed files with 194 additions and 96 deletions

View File

@ -84,6 +84,12 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
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, topicdomoticCommand, 0); 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, topicdomoticCommand, 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_subscribe(client, topicEtatMachine, 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); msg_id = esp_mqtt_client_subscribe(client, topicConsoElec, 0);

View File

@ -92,8 +92,10 @@ static void draw_temp(char * tempHumid){
lv_obj_t* myChart; lv_obj_t* myChart;
lv_chart_series_t * ser; lv_chart_series_t * ser;
lv_obj_t *lblHauteurCuve;
void drawIhm(void *xIHMEventQueue){ void drawIhm(void *xIHMEventQueueParam) {
QueueHandle_t xIHMEventQueue = (QueueHandle_t)xIHMEventQueueParam;
init_display(); init_display();
@ -103,66 +105,78 @@ void drawIhm(void *xIHMEventQueue){
display_lock("app_main"); display_lock("app_main");
app_main_display(); app_main_display();
display_unlock("app_main"); display_unlock("app_main");
vTaskDelay(pdMS_TO_TICKS(2000)); vTaskDelay(pdMS_TO_TICKS(2000));
// Show LVGL objects
if (display_lock("draw_ihm")) { if (display_lock("draw_ihm")) {
draw_ihm(); draw_ihm();
display_unlock("draw_ihm"); display_unlock("draw_ihm");
} }
while (1) { while (1) {
xIPStackEvent_t xReceivedEvent; xIHMEvent_t *xReceivedEvent = NULL;
// On cree une queue qui va permettre de recevoir les informations a afficher
xQueueReceive(xIHMEventQueue,&xReceivedEvent, portMAX_DELAY ); if (xQueueReceive(xIHMEventQueue, &xReceivedEvent, portMAX_DELAY) == pdTRUE && xReceivedEvent) {
switch (xReceivedEvent.eEventType) ESP_LOGE(TAG,"Evt IHM Recu");
{ switch (xReceivedEvent->eEventType) {
case IHM_EVT_WIFI_STATUS: case IHM_EVT_WIFI_STATUS:
ESP_LOGV(TAG, "evt wifi -- begin"); lv_subject_set_int(&wifiStatus, *(bool *)xReceivedEvent->pvData);
lv_subject_set_int(&wifiStatus, (int)xReceivedEvent.pvData);
ESP_LOGV(TAG, "evt wifi -- end");
break; break;
case IHM_EVT_TIME_SETTED: case IHM_EVT_TIME_SETTED:
ESP_LOGV(TAG, "evt timesetted -- begin"); draw_time(xReceivedEvent->pvData);
draw_time(xReceivedEvent.pvData);
ESP_LOGV(TAG, "evt timesetted -- end");
break; break;
case IHM_EVT_OTA_STARTED: case IHM_EVT_OTA_STARTED:
ESP_LOGV(TAG, "evt OTA_STARTED -- begin");
app_ota_display(); app_ota_display();
ESP_LOGV(TAG, "evt OTA_STARTED -- end");
break; break;
case IHM_EVT_OTA_PROGRESS: case IHM_EVT_OTA_PROGRESS:
//ESP_LOGE(TAG, "evt OTA_PROGRESS -- begin"); setOTAProgress((int)xReceivedEvent->pvData);
setOTAProgress((int)xReceivedEvent.pvData);
//ESP_LOGE(TAG, "evt OTA_PROGRESS -- end");
break; break;
case IHM_EVT_HUMID_TEMP: case IHM_EVT_HUMID_TEMP:
ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- begin"); draw_temp((char *)xReceivedEvent->pvData);
draw_temp((char *)xReceivedEvent.pvData);
ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- end");
break; break;
case IHM_EVT_PUISSANCE_EMISE: case IHM_EVT_PUISSANCE_EMISE:
case IHM_EVT_ETAT_MACHINE:
if (display_lock("updateChart")) { if (display_lock("updateChart")) {
ESP_LOGE(TAG,"On a recu %i",(int)xReceivedEvent.pvData); int val = (int)xReceivedEvent->pvData;
if((int)xReceivedEvent.pvData==0){ if (val == 0) {
lv_chart_set_next_value(myChart, ser, LV_CHART_POINT_NONE); lv_chart_set_next_value(myChart, ser, LV_CHART_POINT_NONE);
} else { } else {
lv_chart_set_next_value(myChart,ser,(int)xReceivedEvent.pvData); lv_chart_set_next_value(myChart, ser, val);
} }
//lv_chart_refresh(myChart);
display_unlock("updateChart"); display_unlock("updateChart");
} }
break; break;
case IHM_EVT_HAUTEUR_CUVE:
if (display_lock("updateCuve")) {
float hauteur = *(float *)xReceivedEvent->pvData;
lv_label_set_text_fmt(lblHauteurCuve, "%.2f cm", hauteur);
display_unlock("updateCuve");
}
break;
default: default:
ESP_LOGE(TAG, "Evt inconnu"); ESP_LOGE(TAG, "Evt inconnu");
break; break;
};
ESP_LOGV(TAG,"IHM delay");
vTaskDelay(100/portTICK_PERIOD_MS);
} }
ESP_LOGE(TAG,"Evt IHM Traité on nettoie la memoire");
// Nettoyage mémoire sécurisé
if (xReceivedEvent->bNeedToFreeData && xReceivedEvent->pvData) {
free(xReceivedEvent->pvData);
}
free(xReceivedEvent);
ESP_LOGE(TAG,"Evt IHM Traité !");
} }
vTaskDelay(pdMS_TO_TICKS(100));
}
}
static void event_handler(lv_event_t *e) static void event_handler(lv_event_t *e)
{ {
@ -695,13 +709,16 @@ static void draw_event_cb(lv_event_t * e)
} }
} }
lv_obj_t* lblEtatMachine;
void draw_tabMinuteur(lv_obj_t * parent) void draw_tabMinuteur(lv_obj_t * parent)
{ {
lblEtatMachine = lv_label_create(parent);
lv_label_set_text(lblEtatMachine,"Machine: ");
myChart = lv_chart_create(parent); myChart = lv_chart_create(parent);
lv_chart_set_type(myChart, LV_CHART_TYPE_BAR); lv_chart_set_type(myChart, LV_CHART_TYPE_BAR);
lv_chart_set_point_count(myChart, 30); lv_chart_set_point_count(myChart, 30);
lv_obj_set_style_pad_column(myChart, 2, 0); lv_obj_set_style_pad_column(myChart, 2, 0);
lv_obj_set_size(myChart, 600, 500); lv_obj_set_size(myChart, 600, 400);
lv_chart_set_range(myChart, LV_CHART_AXIS_PRIMARY_Y, 0, 1500); lv_chart_set_range(myChart, LV_CHART_AXIS_PRIMARY_Y, 0, 1500);
lv_obj_center(myChart); lv_obj_center(myChart);
@ -811,6 +828,7 @@ void draw_tabHome(lv_obj_t* parent){
lv_label_bind_text(lblTempExt, &tempExtSubj, "%s °C"); lv_label_bind_text(lblTempExt, &tempExtSubj, "%s °C");
//Create a container with COLUMN flex direction //Create a container with COLUMN flex direction
/*
lv_obj_t *cont_tempInt = lv_obj_create(cont_colTemp); lv_obj_t *cont_tempInt = lv_obj_create(cont_colTemp);
lv_obj_add_style(cont_tempInt, &style_container, 0); lv_obj_add_style(cont_tempInt, &style_container, 0);
// lv_obj_set_height(cont_tempInt,50); // lv_obj_set_height(cont_tempInt,50);
@ -821,13 +839,14 @@ void draw_tabHome(lv_obj_t* parent){
lv_obj_add_style(lblTempInt, &style_lbvValue, 0); lv_obj_add_style(lblTempInt, &style_lbvValue, 0);
lv_label_set_text(lblTempInt, ""); lv_label_set_text(lblTempInt, "");
lv_label_bind_text(lblTempInt, &tempIntSubj, "%s °C"); lv_label_bind_text(lblTempInt, &tempIntSubj, "%s °C");
*/
//Create a container with COLUMN flex direction //Create a container with COLUMN flex direction
lv_obj_t *cont_tempInt2 = lv_obj_create(cont_colTemp); lv_obj_t *cont_tempInt2 = lv_obj_create(cont_colTemp);
lv_obj_add_style(cont_tempInt2, &style_container, 0); lv_obj_add_style(cont_tempInt2, &style_container, 0);
// lv_obj_set_height(cont_tempInt,50); // lv_obj_set_height(cont_tempInt,50);
lv_obj_set_flex_flow(cont_tempInt2, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(cont_tempInt2, LV_FLEX_FLOW_ROW);
lblInt = lv_label_create(cont_tempInt2); lv_obj_t * lblInt = lv_label_create(cont_tempInt2);
lv_label_set_text(lblInt, "int."); lv_label_set_text(lblInt, "int.");
lblTempInt2 = lv_label_create(cont_tempInt2); lblTempInt2 = lv_label_create(cont_tempInt2);
lv_obj_add_style(lblTempInt2, &style_lbvValue, 0); lv_obj_add_style(lblTempInt2, &style_lbvValue, 0);
@ -844,9 +863,9 @@ void draw_tabHome(lv_obj_t* parent){
lv_obj_t *lblHauteurEau = lv_label_create(cont_Cuve); lv_obj_t *lblHauteurEau = lv_label_create(cont_Cuve);
lv_label_set_text(lblHauteurEau, "Cuve: "); lv_label_set_text(lblHauteurEau, "Cuve: ");
lv_obj_t *lblHauteurCuve = lv_label_create(cont_Cuve); lblHauteurCuve = lv_label_create(cont_Cuve);
lv_obj_add_style(lblHauteurCuve, &style_lbvValue, 0); lv_obj_add_style(lblHauteurCuve, &style_lbvValue, 0);
lv_label_bind_text(lblHauteurCuve, &hauteurCuveSubj, "%s cm"); //lv_label_bind_text(lblHauteurCuve, &hauteurCuveSubj, "%s cm");
lv_obj_t *btnUp = lv_button_create(cont_colVolets); lv_obj_t *btnUp = lv_button_create(cont_colVolets);
lv_obj_add_style(btnUp, &style_btn, 0); lv_obj_add_style(btnUp, &style_btn, 0);

View File

@ -37,14 +37,17 @@ typedef enum eIHMEvent_t{
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 IHM_EVT_PUISSANCE_EMISE,
IHM_EVT_ETAT_MACHINE,
IHM_EVT_HAUTEUR_CUVE,
} eIHMEvent_t; } eIHMEvent_t;
typedef struct IP_TASK_COMMANDS typedef struct IHM_EVENT
{ {
eIHMEvent_t eEventType; /* Tells the receiving task what the event is. */ eIHMEvent_t eEventType; /* Tells the receiving task what the event is. */
void *pvData; /* Holds or points to any data associated with the event. */ void *pvData; /* Holds or points to any data associated with the event. */
} xIPStackEvent_t; bool bNeedToFreeData; // ← Important !
} xIHMEvent_t;
void drawIhm(void *pvParameter); void drawIhm(void *pvParameter);

View File

@ -23,6 +23,7 @@ void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup);
#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 topicConsoElec "energy/puissance_5mn"
#define topicEtatMachine "energy/machine_en_route"
#define topicdomoticCommand "domotic/cmd" #define topicdomoticCommand "domotic/cmd"
#define topicTest "test" #define topicTest "test"

View File

@ -121,9 +121,9 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
lvgl_port_unlock(); lvgl_port_unlock();
} }
} }
else if (strncmp(event->topic, topicHauteurCuveEvol, event->topic_len) == 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);
ser1->y_points[0] = 130 - (int)datas[0]; ser1->y_points[0] = 130 - (int)datas[0];
ser1->y_points[1] = 130 - (int)datas[1]; ser1->y_points[1] = 130 - (int)datas[1];
@ -132,12 +132,16 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
lvgl_port_lock(0); lvgl_port_lock(0);
lv_chart_refresh(chart); lv_chart_refresh(chart);
lvgl_port_unlock(); lvgl_port_unlock();
*/
// lv_subject_copy_string(&hauteurCuveEvolSubj, event->data); // lv_subject_copy_string(&hauteurCuveEvolSubj, event->data);
} }*/
else if (strncmp(event->topic, topicHauteurCuve, event->topic_len) == 0) else if (strncmp(event->topic, topicHauteurCuve, event->topic_len) == 0)
{ {
float f = strtof(event->data, NULL);
ESP_LOGE(TAG,"%f recu mqtt", f);
send_event(EVT_HAUTEUR_CUVE,&f);
/*
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];
@ -145,6 +149,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
lv_subject_copy_string(&hauteurCuveSubj, buff); lv_subject_copy_string(&hauteurCuveSubj, buff);
lvgl_port_unlock(); lvgl_port_unlock();
} }
*/
}else if (strncmp(event->topic, topicTest, event->topic_len) == 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, topicConsoElec, event->topic_len) == 0){ }else if (strncmp(event->topic, topicConsoElec, event->topic_len) == 0){
@ -153,6 +158,12 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
send_event(EVT_PUISSANCE_RECUE,(int*)atoi(datas)); send_event(EVT_PUISSANCE_RECUE,(int*)atoi(datas));
}else if (strncmp(event->topic, topicEtatMachine, event->topic_len) == 0){
char* datas = malloc(event->data_len+1);
strncpy(datas, event->data, event->data_len);
send_event(EVT_ETAT_MACHINE,(int*)atoi(datas));
}else if (strncmp(event->topic, topicdomoticCommand, event->topic_len) == 0){ }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");
@ -177,35 +188,91 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
void send_event(domo_events evt, void* pDatas) { void send_event(domo_events evt, void* pDatas) {
ESP_LOGE(TAG,"On est dans l'event handler %i", evt); ESP_LOGE(TAG,"On est dans l'event handler %i", evt);
xIHMEvent_t *ihmEvt = malloc(sizeof(xIHMEvent_t));
if (!ihmEvt) {
ESP_LOGE(TAG, "malloc failed for event struct");
return;
}
switch (evt) { switch (evt) {
case EVT_WIFI_CONNECTED: case EVT_WIFI_CONNECTED: {
xEventGroupSetBits(domotic_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(domotic_event_group, WIFI_CONNECTED_BIT);
ESP_LOGI(TAG, "connected to ap SSID"); ESP_LOGI(TAG, "connected to AP SSID");
xIPStackEvent_t evt = {
.eEventType = IHM_EVT_WIFI_STATUS, bool *wifiStatus = malloc(sizeof(bool));
.pvData = (void *)true if (!wifiStatus) {
}; ESP_LOGE(TAG, "malloc failed for wifiStatus");
if(xQueueSendToFront( ihm_queue, ( void * ) &evt, ( TickType_t ) 10 ) != pdPASS){ free(ihmEvt);
ESP_LOGE(TAG, "La queue est pleine"); return;
}; }
*wifiStatus = true;
ihmEvt->eEventType = IHM_EVT_WIFI_STATUS;
ihmEvt->pvData = wifiStatus;
ihmEvt->bNeedToFreeData = true;
break; break;
}
case EVT_TIME_SETTED: case EVT_TIME_SETTED:
xIPStackEvent_t m = { const char *msg = (const char *)pDatas;
.eEventType = IHM_EVT_TIME_SETTED, char *msg_copy = malloc(strlen(msg) + 1);
.pvData = pDatas if (!msg_copy) {
}; ESP_LOGE(TAG, "malloc failed for message string");
xQueueSendToFront(ihm_queue,&m,5); free(ihmEvt);
return;
}
strcpy(msg_copy, msg);
ihmEvt->eEventType = IHM_EVT_TIME_SETTED;
ihmEvt->pvData = msg_copy;
ihmEvt->bNeedToFreeData = true;
break; break;
case EVT_BTN_VOLET: case EVT_BTN_VOLET:
esp_mqtt_client_publish(client, "volets", pDatas, 0, 0, 0); esp_mqtt_client_publish(client, "volets", pDatas, 0, 0, 0);
break; free(ihmEvt); // rien à envoyer à l'IHM
return;
case EVT_PUISSANCE_RECUE: case EVT_PUISSANCE_RECUE:
xIPStackEvent_t m1 = { ihmEvt->eEventType = IHM_EVT_PUISSANCE_EMISE;
.eEventType = IHM_EVT_PUISSANCE_EMISE, ihmEvt->pvData = pDatas;
.pvData = pDatas ihmEvt->bNeedToFreeData = false;
};
xQueueSendToFront(ihm_queue,&m1,5);
break; break;
case EVT_ETAT_MACHINE:
ihmEvt->eEventType = IHM_EVT_ETAT_MACHINE;
ihmEvt->pvData = pDatas;
ihmEvt->bNeedToFreeData = false;
break;
case EVT_HAUTEUR_CUVE: {
float *data = malloc(sizeof(float));
if (!data) {
ESP_LOGE(TAG, "malloc failed for hauteur_cuve");
free(ihmEvt);
return;
}
*data = *(float *)pDatas;
ESP_LOGE(TAG, "EVENT_HANDLER -> On a recu %f", *data);
ihmEvt->eEventType = IHM_EVT_HAUTEUR_CUVE;
ihmEvt->pvData = data;
ihmEvt->bNeedToFreeData = true;
break;
}
default:
ESP_LOGE(TAG, "Unhandled event type");
free(ihmEvt);
return;
}
ESP_LOGE(TAG, "Envoi d'un evt %i a l'IHM", ihmEvt->eEventType);
if (xQueueSendToFront(ihm_queue, &ihmEvt, pdMS_TO_TICKS(10)) != pdPASS) {
ESP_LOGE(TAG, "La queue est pleine");
if (ihmEvt->bNeedToFreeData && ihmEvt->pvData) {
free(ihmEvt->pvData);
}
free(ihmEvt);
} }
} }
@ -412,7 +479,7 @@ void simple_ota_example_task(void *pvParameter)
ESP_LOGE(TAG, "image header verification failed"); ESP_LOGE(TAG, "image header verification failed");
goto ota_end; goto ota_end;
} }
xIPStackEvent_t m = { xIHMEvent_t m = {
.eEventType = IHM_EVT_OTA_STARTED, .eEventType = IHM_EVT_OTA_STARTED,
.pvData = NULL .pvData = NULL
}; };
@ -477,11 +544,11 @@ void readTempHumid(void *pvParameter)
char buff[40]; char buff[40];
ESP_LOGI(TAG, "Temperature: %.1f °C, Humidity: %.1f %%", temperature, humidity); ESP_LOGI(TAG, "Temperature: %.1f °C, Humidity: %.1f %%", temperature, humidity);
sprintf(buff,"%.1f °C, %.1f %%", temperature, humidity); sprintf(buff,"%.1f °C, %.1f %%", temperature, humidity);
xIPStackEvent_t m = { xIHMEvent_t m = {
.eEventType = IHM_EVT_HUMID_TEMP, .eEventType = IHM_EVT_HUMID_TEMP,
.pvData = buff .pvData = buff
}; };
xQueueSendToFront(ihm_queue,&m,5); //xQueueSendToFront(ihm_queue,&m,5);
vTaskDelay(60000 / portTICK_PERIOD_MS); vTaskDelay(60000 / portTICK_PERIOD_MS);
} }
@ -788,7 +855,7 @@ void app_main(void)
{ {
domotic_event_group = xEventGroupCreate(); domotic_event_group = xEventGroupCreate();
ihm_queue = xQueueCreate(10,sizeof(xIPStackEvent_t)); ihm_queue = xQueueCreate(10,sizeof(xIHMEvent_t *));
//init_display(); //init_display();
const esp_timer_create_args_t periodic_timer_args = { const esp_timer_create_args_t periodic_timer_args = {
.callback = &presence_timer_callback, .callback = &presence_timer_callback,

View File

@ -4,6 +4,8 @@ typedef enum domo_events{
EVT_WIFI_CONNECTED, EVT_WIFI_CONNECTED,
EVT_TIME_SETTED, EVT_TIME_SETTED,
EVT_BTN_VOLET, EVT_BTN_VOLET,
EVT_PUISSANCE_RECUE EVT_PUISSANCE_RECUE,
EVT_ETAT_MACHINE,
EVT_HAUTEUR_CUVE
} domo_events; } domo_events;
void send_event(domo_events evt, void* pDatas); void send_event(domo_events evt, void* pDatas);

View File

@ -515,7 +515,7 @@ CONFIG_IDF_TOOLCHAIN_GCC=y
CONFIG_IDF_TARGET_ARCH_RISCV=y CONFIG_IDF_TARGET_ARCH_RISCV=y
CONFIG_IDF_TARGET_ARCH="riscv" CONFIG_IDF_TARGET_ARCH="riscv"
CONFIG_IDF_TARGET="esp32p4" CONFIG_IDF_TARGET="esp32p4"
CONFIG_IDF_INIT_VERSION="$IDF_INIT_VERSION" CONFIG_IDF_INIT_VERSION="5.5.0"
CONFIG_IDF_TARGET_ESP32P4=y CONFIG_IDF_TARGET_ESP32P4=y
CONFIG_IDF_FIRMWARE_CHIP_ID=0x0012 CONFIG_IDF_FIRMWARE_CHIP_ID=0x0012