Корректировка для сборки проекта ESP32

This commit is contained in:
kkira
2026-06-18 22:10:51 +03:00
parent 9f863206db
commit 5603d3990f
6 changed files with 63 additions and 28 deletions

View File

@@ -1,12 +1,31 @@
#include "mqtt_client.hpp"
#include "mqtt_client.h"
#include "esp_log.h"
static esp_mqtt_client_handle_t mqttClient;
static void mqtt_event_handler(void*, esp_event_base_t, int32_t event_id, void*)
{
switch(event_id)
{
case MQTT_EVENT_CONNECTED:
ESP_LOGI("MQTT", "Connected");
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGW("MQTT", "Disconnected");
break;
default:
break;
}
}
void MQTTClient::Init()
{
esp_mqtt_client_config_t cfg = {
esp_mqtt_client_config_t cfg =
{
.broker =
{
.address =
@@ -16,7 +35,10 @@ void MQTTClient::Init()
}
};
mqttClient = esp_mqtt_client_init(&cfg);
mqttClient =
esp_mqtt_client_init(&cfg);
esp_mqtt_client_register_event(mqttClient, MQTT_EVENT_ANY, mqtt_event_handler, nullptr);
esp_mqtt_client_start(mqttClient);
}
@@ -25,14 +47,7 @@ void MQTTClient::PublishCO2(uint16_t ppm)
{
char msg[32];
sprintf(msg,"%u",ppm);
sprintf(msg, "%u", ppm);
esp_mqtt_client_publish(
mqttClient,
"student/co2",
msg,
0,
1,
0
);
esp_mqtt_client_publish(mqttClient, "student/co2", msg, 0, 1, 0);
}