fix on mqtt date received handlers
This commit is contained in:
17
Network.cpp
17
Network.cpp
@@ -280,11 +280,7 @@ bool Network::reconnect()
|
|||||||
_device->mqttClient()->publish(it.first.c_str(), MQTT_QOS_LEVEL, true, it.second.c_str());
|
_device->mqttClient()->publish(it.first.c_str(), MQTT_QOS_LEVEL, true, it.second.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i=0; i<10; i++)
|
delay(1000);
|
||||||
{
|
|
||||||
// _device->mqttClient()->poll();
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
_mqttConnectionState = 2;
|
_mqttConnectionState = 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -292,7 +288,6 @@ bool Network::reconnect()
|
|||||||
Log->print(F("MQTT connect failed, rc="));
|
Log->print(F("MQTT connect failed, rc="));
|
||||||
// Log->println(_device->mqttClient()->connectError());
|
// Log->println(_device->mqttClient()->connectError());
|
||||||
_device->printError();
|
_device->printError();
|
||||||
// _device->mqttClient()->stop();
|
|
||||||
_mqttConnectionState = 0;
|
_mqttConnectionState = 0;
|
||||||
_nextReconnect = millis() + 5000;
|
_nextReconnect = millis() + 5000;
|
||||||
}
|
}
|
||||||
@@ -345,7 +340,15 @@ void Network::registerMqttReceiver(MqttReceiver* receiver)
|
|||||||
|
|
||||||
void Network::onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
void Network::onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
||||||
{
|
{
|
||||||
_inst->onMqttDataReceived(properties, topic, payload, len, index, total);
|
uint8_t value[50] = {0};
|
||||||
|
size_t l = min(len, sizeof(value)-1);
|
||||||
|
|
||||||
|
for(int i=0; i<l; i++)
|
||||||
|
{
|
||||||
|
value[i] = payload[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
_inst->onMqttDataReceived(properties, topic, value, len, index, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
void Network::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
||||||
|
|||||||
@@ -73,13 +73,7 @@ void NetworkLock::initialize()
|
|||||||
|
|
||||||
void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
||||||
{
|
{
|
||||||
char value[50] = {0};
|
char* value = (char*)payload;
|
||||||
size_t l = min(length, sizeof(value)-1);
|
|
||||||
|
|
||||||
for(int i=0; i<l; i++)
|
|
||||||
{
|
|
||||||
value[i] = payload[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool processActions = _network->mqttConnectionState() >= 2;
|
bool processActions = _network->mqttConnectionState() >= 2;
|
||||||
|
|
||||||
|
|||||||
@@ -58,19 +58,14 @@ void NetworkOpener::update()
|
|||||||
|
|
||||||
void NetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
void NetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
||||||
{
|
{
|
||||||
char value[50] = {0};
|
char* value = (char*)payload;
|
||||||
size_t l = min(length, sizeof(value)-1);
|
|
||||||
|
|
||||||
for(int i=0; i<l; i++)
|
|
||||||
{
|
|
||||||
value[i] = payload[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool processActions = _network->mqttConnectionState() >= 2;
|
bool processActions = _network->mqttConnectionState() >= 2;
|
||||||
|
|
||||||
if(processActions && comparePrefixedPath(topic, mqtt_topic_lock_action))
|
if(processActions && comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||||
{
|
{
|
||||||
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return;
|
Serial.println(value);
|
||||||
|
if(strcmp((char*)payload, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return;
|
||||||
|
|
||||||
Log->print(F("Opener lock action received: "));
|
Log->print(F("Opener lock action received: "));
|
||||||
Log->println(value);
|
Log->println(value);
|
||||||
@@ -489,5 +484,6 @@ bool NetworkOpener::comparePrefixedPath(const char *fullPath, const char *subPat
|
|||||||
{
|
{
|
||||||
char prefixedPath[500];
|
char prefixedPath[500];
|
||||||
buildMqttPath(subPath, prefixedPath);
|
buildMqttPath(subPath, prefixedPath);
|
||||||
|
|
||||||
return strcmp(fullPath, prefixedPath) == 0;
|
return strcmp(fullPath, prefixedPath) == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user