mirror of
https://github.com/gunner47/GyverLamp.git
synced 2025-08-08 09:20:59 +03:00
Исправлена ошибка обработки входящих MQTT команд
This commit is contained in:
@@ -137,6 +137,7 @@ char* MqttManager::mqttServer = NULL;
|
|||||||
char* MqttManager::mqttUser = NULL;
|
char* MqttManager::mqttUser = NULL;
|
||||||
char* MqttManager::mqttPassword = NULL;
|
char* MqttManager::mqttPassword = NULL;
|
||||||
char* MqttManager::clientId = NULL;
|
char* MqttManager::clientId = NULL;
|
||||||
|
char* MqttManager::lampInputBuffer = NULL;
|
||||||
char* MqttManager::topicInput = NULL;
|
char* MqttManager::topicInput = NULL;
|
||||||
char* MqttManager::topicOutput = NULL;
|
char* MqttManager::topicOutput = NULL;
|
||||||
bool MqttManager::needToPublish = false;
|
bool MqttManager::needToPublish = false;
|
||||||
@@ -307,7 +308,7 @@ void setup()
|
|||||||
// MQTT
|
// MQTT
|
||||||
#if (USE_MQTT && ESP_MODE == 1)
|
#if (USE_MQTT && ESP_MODE == 1)
|
||||||
mqttClient = new AsyncMqttClient();
|
mqttClient = new AsyncMqttClient();
|
||||||
MqttManager::setupMqtt(mqttClient, &sendCurrent); // создание экземпляров объектов для работы с MQTT, их инициализация и подключение к MQTT брокеру
|
MqttManager::setupMqtt(mqttClient, inputBuffer, &sendCurrent); // создание экземпляров объектов для работы с MQTT, их инициализация и подключение к MQTT брокеру
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ class MqttManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static uint32_t mqttLastConnectingAttempt;
|
static uint32_t mqttLastConnectingAttempt;
|
||||||
static void setupMqtt(AsyncMqttClient* mqttClient, SendCurrentDelegate sendCurrentDelegate);
|
static void setupMqtt(AsyncMqttClient* mqttClient, char* lampInputBuffer, SendCurrentDelegate sendCurrentDelegate);
|
||||||
static void mqttConnect();
|
static void mqttConnect();
|
||||||
static void onMqttConnect(bool sessionPresent);
|
static void onMqttConnect(bool sessionPresent);
|
||||||
static void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
static void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
||||||
@@ -84,6 +84,7 @@ class MqttManager
|
|||||||
static char* topicInput; // TopicBase + '/' + MqttClientIdPrefix + ESP.getChipId + '/' + TopicCmnd
|
static char* topicInput; // TopicBase + '/' + MqttClientIdPrefix + ESP.getChipId + '/' + TopicCmnd
|
||||||
static char* topicOutput; // TopicBase + '/' + MqttClientIdPrefix + ESP.getChipId + '/' + TopicState
|
static char* topicOutput; // TopicBase + '/' + MqttClientIdPrefix + ESP.getChipId + '/' + TopicState
|
||||||
static char* clientId;
|
static char* clientId;
|
||||||
|
static char* lampInputBuffer; // ссылка на inputBuffer для записи в него пришедшей MQTT команды и последующей её обработки лампой
|
||||||
static AsyncMqttClient* mqttClient;
|
static AsyncMqttClient* mqttClient;
|
||||||
static const uint8_t qos = 0U; // MQTT quality of service
|
static const uint8_t qos = 0U; // MQTT quality of service
|
||||||
static const uint32_t connectionTimeout = MQTT_RECONNECT_TIME * 1000U; // период времени для проверки (пере)подключения к MQTT брокеру, 10 секунд
|
static const uint32_t connectionTimeout = MQTT_RECONNECT_TIME * 1000U; // период времени для проверки (пере)подключения к MQTT брокеру, 10 секунд
|
||||||
@@ -94,13 +95,14 @@ class MqttManager
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void MqttManager::setupMqtt(AsyncMqttClient* mqttClient, SendCurrentDelegate sendCurrentDelegate)
|
void MqttManager::setupMqtt(AsyncMqttClient* mqttClient, char* lampInputBuffer, SendCurrentDelegate sendCurrentDelegate)
|
||||||
{
|
{
|
||||||
allocStr_P(&MqttManager::mqttServer, MqttServer);
|
allocStr_P(&MqttManager::mqttServer, MqttServer);
|
||||||
allocStr_P(&MqttManager::mqttUser, MqttUser);
|
allocStr_P(&MqttManager::mqttUser, MqttUser);
|
||||||
allocStr_P(&MqttManager::mqttPassword, MqttPassword);
|
allocStr_P(&MqttManager::mqttPassword, MqttPassword);
|
||||||
|
|
||||||
MqttManager::mqttClient = mqttClient;
|
MqttManager::mqttClient = mqttClient;
|
||||||
|
MqttManager::lampInputBuffer = lampInputBuffer;
|
||||||
MqttManager::sendCurrentDelegate = sendCurrentDelegate;
|
MqttManager::sendCurrentDelegate = sendCurrentDelegate;
|
||||||
MqttManager::mqttClient->setServer(MqttManager::mqttServer, MqttPort);
|
MqttManager::mqttClient->setServer(MqttManager::mqttServer, MqttPort);
|
||||||
|
|
||||||
@@ -195,8 +197,9 @@ void MqttManager::onMqttMessage(char* topic, char* payload, AsyncMqttClientMessa
|
|||||||
{
|
{
|
||||||
if (payload != NULL) // сохраняем пришедшее MQTT сообщение для дальнейшей обработки
|
if (payload != NULL) // сохраняем пришедшее MQTT сообщение для дальнейшей обработки
|
||||||
{
|
{
|
||||||
strncpy(mqttBuffer, payload, len);
|
strncpy(lampInputBuffer, payload, len);
|
||||||
mqttBuffer[len] = '\0';
|
lampInputBuffer[len] = '\0';
|
||||||
|
needToPublish = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GENERAL_DEBUG
|
#ifdef GENERAL_DEBUG
|
||||||
@@ -219,7 +222,7 @@ void MqttManager::onMqttMessage(char* topic, char* payload, AsyncMqttClientMessa
|
|||||||
LOG.println(total);
|
LOG.println(total);
|
||||||
*/
|
*/
|
||||||
LOG.print(F(", значение \""));
|
LOG.print(F(", значение \""));
|
||||||
LOG.print(mqttBuffer);
|
LOG.print(lampInputBuffer);
|
||||||
LOG.println("\"");
|
LOG.println("\"");
|
||||||
LOG.println();
|
LOG.println();
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user