Initial sese-controller application

This commit is contained in:
2026-10-04 11:53:48 +09:00
commit 3299717d3d
22 changed files with 413 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
idf_component_register(SRCS "app_main.c" "sese_product.c" INCLUDE_DIRS "." REQUIRES kesp32-app-base)
+1
View File
@@ -0,0 +1 @@
# Product project Kconfig intentionally empty; reusable settings live in kesp32_app_base.
+18
View File
@@ -0,0 +1,18 @@
#include "esp32_app_base.h"
esp_err_t sese_product_start(void);
void app_main(void)
{
const esp32_app_base_config_t config = {
.service_prefix = "SESE_",
#if CONFIG_IDF_TARGET_ESP32C3
.reset_gpio = 9,
#else
.reset_gpio = 0,
#endif
.reset_active_low = true,
.reset_hold_ms = 5000,
.product_start = sese_product_start,
};
(void)esp32_app_base_start(&config);
}
+4
View File
@@ -0,0 +1,4 @@
dependencies:
idf:
version: '>=6.0.2'
espressif/cjson: ^1.7.19
+16
View File
@@ -0,0 +1,16 @@
#include "esp32_app_base.h"
#include "mqtt_transport.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "esp_app_desc.h"
#include "esp_mac.h"
#include "esp_timer.h"
#include "sdkconfig.h"
static char id[20], status_topic[64], heartbeat_topic[64], ping_topic[64], pong_topic[64];
static void connected(void *ctx) { (void)ctx; mqtt_transport_subscribe(ping_topic, 1); const esp_app_desc_t *a=esp_app_get_description(); char p[160]; snprintf(p,sizeof(p),"{\"online\":true,\"device\":\"%s\",\"version\":\"%s\"}",id,a->version); mqtt_transport_publish(status_topic,p,1,true); }
static void heartbeat(void *ctx) { (void)ctx; time_t now; time(&now); char p[160]; snprintf(p,sizeof(p),"{\"device\":\"%s\",\"timestamp\":%" PRId64 ",\"uptime_seconds\":%" PRId64 "}",id,(int64_t)now,esp_timer_get_time()/1000000LL); mqtt_transport_publish(heartbeat_topic,p,0,false); }
static void message(const char *topic,size_t tl,const char *data,size_t dl,void *ctx) { (void)ctx; if(tl==strlen(ping_topic)&&!memcmp(topic,ping_topic,tl)&&dl==4&&!memcmp(data,"ping",4)){ char p[128]; time_t now; time(&now); snprintf(p,sizeof(p),"{\"response\":\"pong\",\"device\":\"%s\",\"timestamp\":%" PRId64 "}",id,(int64_t)now); mqtt_transport_publish(pong_topic,p,1,false); } }
esp_err_t sese_product_start(void) { uint8_t mac[6]; ESP_ERROR_CHECK(esp_read_mac(mac,ESP_MAC_WIFI_STA)); snprintf(id,sizeof(id),"SESE_%02X%02X%02X",mac[3],mac[4],mac[5]); snprintf(status_topic,sizeof(status_topic),"sese/%s/status",id); snprintf(heartbeat_topic,sizeof(heartbeat_topic),"sese/%s/heartbeat",id); snprintf(ping_topic,sizeof(ping_topic),"sese/%s/command/ping",id); snprintf(pong_topic,sizeof(pong_topic),"sese/%s/response/pong",id); mqtt_transport_config_t c={.broker_uri=CONFIG_SESE_MQTT_BROKER_URI,.client_id=id,.last_will_topic=status_topic,.last_will_payload="{\"online\":false}",.heartbeat_interval_seconds=CONFIG_SESE_MQTT_HEARTBEAT_SECONDS,.on_connected=connected,.on_message=message,.on_heartbeat=heartbeat}; return mqtt_transport_start(&c); }