publication temp int + etat online

This commit is contained in:
Marc Pasteur 2026-03-14 11:51:44 +01:00
parent 67e6d1cfaa
commit 8f60e9c38c
7 changed files with 55 additions and 14 deletions

View File

@ -145,3 +145,11 @@ add_custom_target(ota_latest
> ${OTA_DIR}/latest.json > ${OTA_DIR}/latest.json
DEPENDS ota_push DEPENDS ota_push
) )
add_custom_target(ota_to_mqtt
COMMAND podman run --rm eclipse-mosquitto:alpine
mosquitto_pub
-h 192.168.0.10
-t devices/esp32p4_01/ota/update
-m '{"version":"${FW_VERSION}","url":"https://192.168.0.9:8443/${OTA_BIN_NAME}","sha256":"","force":true}'
)

View File

@ -176,6 +176,10 @@ void send_event(domo_events evt, void* pDatas) {
ihmEvt->eEventType = IHM_EVT_HUMID_TEMP; ihmEvt->eEventType = IHM_EVT_HUMID_TEMP;
ihmEvt->pvData = msg_copy4; ihmEvt->pvData = msg_copy4;
ihmEvt->bNeedToFreeData = true; ihmEvt->bNeedToFreeData = true;
//On envoie les données via mqtt
esp_mqtt_client_publish(client, topicTempInt, pDatas, 0, 0, 0);
break; break;
case EVT_HAUTEUR_CUVE: { case EVT_HAUTEUR_CUVE: {

View File

@ -42,3 +42,12 @@ typedef enum domo_events{
void startEvtManager(); void startEvtManager();
QueueHandle_t getIHMQueueHandle(); QueueHandle_t getIHMQueueHandle();
void send_event(domo_events evt, void *pDatas); void send_event(domo_events evt, void *pDatas);
#define topicTempExt "house/temp/282A802600008059"
#define topicHauteurCuve "house/cuve/hauteur"
#define topicTempInt "house/temp/287DCF1E00008020"
#define topicHauteurCuveEvol "house/cuve/hauteurEvol"
#define topicConsoElec "energy/puissance_5mn"
#define topicEtatMachine "energy/machine_en_route"
#define topicdomoticCommand "domotic/cmd"
#define topicTest "test"

View File

@ -2,6 +2,7 @@
#include "esp_log.h" #include "esp_log.h"
#include "mqtt_client.h" #include "mqtt_client.h"
#include "stateManagement.h" #include "stateManagement.h"
#include "eventsManager.h"
#if CONFIG_IDF_TARGET_ESP32P4 #if CONFIG_IDF_TARGET_ESP32P4
#include "esp_wifi.h" #include "esp_wifi.h"
#endif #endif
@ -183,8 +184,8 @@ void splitIt(char *payload, unsigned int length, float *datas)
mqtt_callback mqttcb; mqtt_callback mqttcb;
void mqtt_publish(const char *topic, const char *datas){ void mqtt_publish(const char *topic, const char *datas, bool retain){
esp_mqtt_client_publish(client, topic, datas, 0, 1, 0); esp_mqtt_client_publish(client, topic, datas, 0, 1, retain);
} }
/* /*
@ -289,7 +290,13 @@ void mqtt_app_start(mqtt_callback callback, EventGroupHandle_t domotic_event_gro
mqttcb=callback; mqttcb=callback;
esp_mqtt_client_config_t mqtt_cfg = { esp_mqtt_client_config_t mqtt_cfg = {
.broker.address.uri = "mqtt://192.168.0.10", .broker.address.uri = "mqtt://192.168.0.10",
.network.timeout_ms = 1000}; .network.timeout_ms = 1000,
.session.keepalive=30,
.session.last_will.topic="esp32p4_domotic/binary_sensor/online/state",
.session.last_will.msg = "offline",
.session.last_will.qos = 1,
.session.last_will.retain = 1
};
#if CONFIG_BROKER_URL_FROM_STDIN #if CONFIG_BROKER_URL_FROM_STDIN
char line[128]; char line[128];

View File

@ -16,14 +16,6 @@ typedef void (*wifi_callback)(wifi_evt evt);
typedef void (*mqtt_callback)(mqtt_evt evt, esp_mqtt_event_handle_t evt_data); typedef void (*mqtt_callback)(mqtt_evt evt, esp_mqtt_event_handle_t evt_data);
void wifi_init_sta(wifi_callback cb); void wifi_init_sta(wifi_callback cb);
void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup); void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup);
void mqtt_publish(const char *topic, const char *datas); void mqtt_publish(const char *topic, const char *datas, bool retain);
#define topicTempExt "house/temp/282A802600008059"
#define topicHauteurCuve "house/cuve/hauteur"
#define topicTempInt "house/temp/287DCF1E00008020"
#define topicHauteurCuveEvol "house/cuve/hauteurEvol"
#define topicConsoElec "energy/puissance_5mn"
#define topicEtatMachine "energy/machine_en_route"
#define topicdomoticCommand "domotic/cmd"
#define topicTest "test"

View File

@ -1011,6 +1011,21 @@ void lightSensorTask(void *pvParameter){
*/ */
} }
static void heartbeat_task(void *arg)
{
const char *topic = "esp32p4_domotic/binary_sensor/online/state";
while (1) {
mqtt_publish(
topic,
"online",
true);
vTaskDelay(pdMS_TO_TICKS(30000)); // 30 s
}
}
#define BUILD_TIME __DATE__ " " __TIME__
//#include "audio.h" //#include "audio.h"
void app_main(void) void app_main(void)
{ {
@ -1076,6 +1091,12 @@ void app_main(void)
#endif #endif
esp_ota_mark_app_valid_cancel_rollback(); esp_ota_mark_app_valid_cancel_rollback();
esp_app_desc_t *appDesc = esp_app_get_description();
char buff[300];
snprintf(buff,300,"%s %s %s", BUILD_TIME, appDesc->version, appDesc->idf_ver);
mqtt_publish("esp32p4_domotic/sensor/firmware/state",buff, true);
xTaskCreate(heartbeat_task, "heartbeat_task", 4096, NULL, 5, NULL);
start_webserver(); start_webserver();
} }

View File

@ -1 +1 @@
0.0.3 0.0.5