implement send lock action via mqtt
This commit is contained in:
17
Network.cpp
17
Network.cpp
@@ -54,7 +54,7 @@ bool Network::reconnect()
|
||||
Serial.println("connected");
|
||||
|
||||
// ... and resubscribe
|
||||
_mqttClient.subscribe("nuki/cmd");
|
||||
_mqttClient.subscribe(mqtt_topc_lockstate_setpoint);
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(_mqttClient.state());
|
||||
@@ -118,9 +118,17 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
||||
|
||||
value[l] = 0;
|
||||
|
||||
if(strcmp(topic, "nuki/cmd") == 0)
|
||||
if(strcmp(topic, mqtt_topc_lockstate_setpoint) == 0)
|
||||
{
|
||||
if(strcmp(value, "") == 0) return;
|
||||
|
||||
Serial.print("lockstate setpoint received: ");
|
||||
Serial.println(value);
|
||||
if(_lockActionReceivedCallback != NULL)
|
||||
{
|
||||
_lockActionReceivedCallback(value);
|
||||
}
|
||||
_mqttClient.publish(mqtt_topc_lockstate_setpoint, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,3 +136,8 @@ void Network::publishKeyTurnerState(const char* state)
|
||||
{
|
||||
_mqttClient.publish(mqtt_topc_lockstate, state);
|
||||
}
|
||||
|
||||
void Network::setLockActionReceived(void (*lockActionReceivedCallback)(const char *))
|
||||
{
|
||||
_lockActionReceivedCallback = lockActionReceivedCallback;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user