JXCT Soil Sensor 7-in-1 v3.4.9 (June 2025)
Professional IoT soil monitoring system with ESP32, Modbus RTU, MQTT, and advanced compensation algorithms
|
Взаимодействие с MQTT-брокером и Home Assistant. Подробнее...
#include <Arduino.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include "modbus_sensor.h"
#include "wifi_manager.h"
#include <WiFiClient.h>
#include "jxct_device_info.h"
#include "jxct_config_vars.h"
#include "jxct_format_utils.h"
#include "logger.h"
#include "debug.h"
#include "jxct_constants.h"
#include <NTPClient.h>
#include "ota_manager.h"
Классы | |
struct | HomeAssistantConfigCache |
struct | DNSCache |
Функции | |
PubSubClient | mqttClient (espClient) |
const char * | getMqttLastError () |
void | mqttCallback (char *topic, byte *payload, unsigned int length) |
void | publishHomeAssistantConfig () |
void | invalidateHAConfigCache () |
IPAddress | getCachedIP (const char *hostname) |
const char * | getClientId () |
const char * | getMqttClientName () |
const char * | getStatusTopic () |
const char * | getCommandTopic () |
static const char * | getOtaStatusTopic () |
static const char * | getOtaCommandTopic () |
void | publishAvailability (bool online) |
void | setupMQTT () |
bool | connectMQTT () |
void | handleMQTT () |
bool | shouldPublishMqtt () |
void | publishSensorData () |
void | removeHomeAssistantConfig () |
void | handleMqttCommand (const String &cmd) |
Переменные | |
NTPClient * | timeClient |
WiFiClient | espClient |
bool | mqttConnected = false |
static char | mqttLastErrorBuffer [128] = "" |
static char | clientIdBuffer [32] = "" |
static char | statusTopicBuffer [128] = "" |
static char | commandTopicBuffer [128] = "" |
static char | otaStatusTopicBuffer [128] = "" |
static char | otaCommandTopicBuffer [128] = "" |
static struct HomeAssistantConfigCache | haConfigCache = {"", "", "", "", "", "", "", false, "", ""} |
static char | pubTopicCache [7][128] = {"", "", "", "", "", "", ""} |
static bool | pubTopicCacheValid = false |
static char | cachedSensorJson [256] = "" |
static unsigned long | lastCachedSensorTime = 0 |
static bool | sensorJsonCacheValid = false |
struct DNSCache | dnsCacheMqtt = {"", IPAddress(0, 0, 0, 0), 0, false} |
Взаимодействие с MQTT-брокером и Home Assistant.
Реализация подключения, публикации данных, обработки команд и интеграции с Home Assistant через discovery.
См. определение в файле mqtt_client.cpp
bool connectMQTT | ( | ) |
См. определение в файле mqtt_client.cpp строка 191
Перекрестные ссылки config, DEBUG_PRINTF, DEBUG_PRINTLN, ERROR_PRINTLN, getCommandTopic(), getMqttClientName(), getOtaCommandTopic(), getStatusTopic(), INFO_PRINTLN, mqttClient, mqttLastErrorBuffer, publishAvailability() и publishHomeAssistantConfig().
Используется в handleMQTT().
IPAddress getCachedIP | ( | const char * | hostname | ) |
См. определение в файле mqtt_client.cpp строка 752
Перекрестные ссылки DEBUG_PRINTF, DNS_CACHE_TTL и dnsCacheMqtt.
Используется в setupMQTT().
const char * getClientId | ( | ) |
См. определение в файле mqtt_client.cpp строка 81
Перекрестные ссылки clientIdBuffer.
Используется в getMqttClientName().
const char * getCommandTopic | ( | ) |
См. определение в файле mqtt_client.cpp строка 117
Перекрестные ссылки commandTopicBuffer и config.
Используется в connectMQTT() и mqttCallback().
const char * getMqttClientName | ( | ) |
См. определение в файле mqtt_client.cpp строка 94
Перекрестные ссылки config и getClientId().
Используется в connectMQTT().
const char * getMqttLastError | ( | ) |
См. определение в файле mqtt_client.cpp строка 28
Перекрестные ссылки mqttLastErrorBuffer.
Используется в sendHealthJson() и sendServiceStatusJson().
|
static |
См. определение в файле mqtt_client.cpp строка 134
Перекрестные ссылки config и otaCommandTopicBuffer.
Используется в connectMQTT() и mqttCallback().
|
static |
См. определение в файле mqtt_client.cpp строка 127
Перекрестные ссылки config и otaStatusTopicBuffer.
Используется в handleMQTT().
const char * getStatusTopic | ( | ) |
См. определение в файле mqtt_client.cpp строка 107
Перекрестные ссылки config и statusTopicBuffer.
Используется в connectMQTT() и publishAvailability().
void handleMQTT | ( | ) |
См. определение в файле mqtt_client.cpp строка 311
Перекрестные ссылки config, connectMQTT(), getOtaStatus(), getOtaStatusTopic(), logMQTT(), logSuccess(), logWarn() и mqttClient.
Используется в loop().
void handleMqttCommand | ( | const String & | cmd | ) |
См. определение в файле mqtt_client.cpp строка 674
Перекрестные ссылки config, DEBUG_PRINT, DEBUG_PRINTLN, handleOTA(), publishAvailability(), publishHomeAssistantConfig(), publishSensorData(), removeHomeAssistantConfig(), resetConfig(), saveConfig() и triggerOtaCheck().
Используется в mqttCallback().
void invalidateHAConfigCache | ( | ) |
См. определение в файле mqtt_client.cpp строка 734
Перекрестные ссылки haConfigCache, INFO_PRINTLN и mqttLastErrorBuffer.
Используется в saveConfig().
void mqttCallback | ( | char * | topic, |
byte * | payload, | ||
unsigned int | length ) |
См. определение в файле mqtt_client.cpp строка 722
Перекрестные ссылки DEBUG_PRINTF, getCommandTopic(), getOtaCommandTopic() и handleMqttCommand().
Используется в setupMQTT().
void publishAvailability | ( | bool | online | ) |
См. определение в файле mqtt_client.cpp строка 141
Перекрестные ссылки DEBUG_PRINTF, getStatusTopic() и mqttClient.
Используется в connectMQTT() и handleMqttCommand().
void publishHomeAssistantConfig | ( | ) |
См. определение в файле mqtt_client.cpp строка 521
Перекрестные ссылки config, DEBUG_PRINTLN, DEVICE_MANUFACTURER, DEVICE_MODEL, DEVICE_SW_VERSION, getDeviceId(), haConfigCache, INFO_PRINTLN, mqttClient, mqttLastErrorBuffer, pubTopicCache и pubTopicCacheValid.
Используется в connectMQTT() и handleMqttCommand().
void publishSensorData | ( | ) |
См. определение в файле mqtt_client.cpp строка 440
Перекрестные ссылки cachedSensorJson, config, DEBUG_PRINTLN, lastCachedSensorTime, mqttClient, mqttLastErrorBuffer, sensorData, sensorJsonCacheValid, shouldPublishMqtt() и timeClient.
Используется в handleMqttCommand() и loop().
void removeHomeAssistantConfig | ( | ) |
См. определение в файле mqtt_client.cpp строка 658
Перекрестные ссылки getDeviceId(), INFO_PRINTLN, mqttClient и mqttLastErrorBuffer.
Используется в handleMqttCommand().
void setupMQTT | ( | ) |
См. определение в файле mqtt_client.cpp строка 149
Перекрестные ссылки config, DEBUG_PRINTF, DEBUG_PRINTLN, ERROR_PRINTF, ERROR_PRINTLN, getCachedIP(), INFO_PRINTLN, mqttCallback(), mqttClient и mqttLastErrorBuffer.
Используется в setup().
bool shouldPublishMqtt | ( | ) |
См. определение в файле mqtt_client.cpp строка 364
Перекрестные ссылки config, DEBUG_PRINTF, DEBUG_PRINTLN и sensorData.
Используется в publishSensorData().
|
static |
См. определение в файле mqtt_client.cpp строка 61
Используется в publishSensorData().
|
static |
См. определение в файле mqtt_client.cpp строка 34
Используется в getClientId().
|
static |
См. определение в файле mqtt_client.cpp строка 36
Используется в getCommandTopic().
struct DNSCache dnsCacheMqtt = {"", IPAddress(0, 0, 0, 0), 0, false} |
Используется в getCachedIP().
WiFiClient espClient |
См. определение в файле mqtt_client.cpp строка 22
Используется в mqttClient() и setup().
|
static |
Используется в invalidateHAConfigCache() и publishHomeAssistantConfig().
|
static |
См. определение в файле mqtt_client.cpp строка 62
Используется в publishSensorData().
bool mqttConnected = false |
См. определение в файле mqtt_client.cpp строка 24
|
static |
См. определение в файле mqtt_client.cpp строка 27
Используется в connectMQTT(), getMqttLastError(), invalidateHAConfigCache(), publishHomeAssistantConfig(), publishSensorData(), removeHomeAssistantConfig() и setupMQTT().
|
static |
См. определение в файле mqtt_client.cpp строка 38
Используется в getOtaCommandTopic().
|
static |
См. определение в файле mqtt_client.cpp строка 37
Используется в getOtaStatusTopic().
|
static |
См. определение в файле mqtt_client.cpp строка 57
Используется в publishHomeAssistantConfig().
|
static |
См. определение в файле mqtt_client.cpp строка 58
Используется в publishHomeAssistantConfig().
|
static |
См. определение в файле mqtt_client.cpp строка 63
Используется в publishSensorData().
|
static |
См. определение в файле mqtt_client.cpp строка 35
Используется в getStatusTopic().