implement send lock action via mqtt

This commit is contained in:
technyon
2022-03-25 21:39:47 +01:00
parent 66e0239589
commit a202deef23
5 changed files with 58 additions and 7 deletions

View File

@@ -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;
}