Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding reboot-over-MQTT option for fingerprint-mqtt-led-touch.ino #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion fingerprint-mqtt/fingerprint-mqtt-led-touch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define MODE_LEARNING "/fingerprint/mode/learning"
#define MODE_READING "/fingerprint/mode/reading"
#define MODE_DELETE "/fingerprint/mode/delete"
#define MODE_REBOOT "/fingerprint/mode/reboot"
#define AVAILABILITY_TOPIC "/fingerprint/available"
#define mqtt_username "MQTT Username"
#define mqtt_password "MQTT Password"
Expand Down Expand Up @@ -108,7 +109,8 @@ void loop() {
client.publish(STATE_TOPIC, mqttBuffer, mqttMessageSize);

while (fingerState == HIGH) { // Disable sensor while no finger
fingerState = digitalRead(D3);
fingerState = digitalRead(D3);
client.loop(); // So that MQTT messags are processed
delay(100);
}
} else if (sensorOn == false) { // Disable sensor regardless of finger presence
Expand Down Expand Up @@ -413,6 +415,7 @@ void reconnect() {
client.subscribe(MODE_LEARNING); //Subscribe to Learning Mode Topic
client.subscribe(MODE_READING);
client.subscribe(MODE_DELETE);
client.subscribe(MODE_REBOOT);
client.subscribe(SENSOR_ENABLED_TOPIC);
} else {
Serial.print("failed, rc=");
Expand Down Expand Up @@ -487,4 +490,16 @@ void callback(char* topic, byte* payload, unsigned int length) {
Serial.println("Turning sensor off");
}
}

if (strcmp(topic, MODE_REBOOT) == 0) {
Serial.println("Got MQTT reboot command");
mqttMessage["mode"] = "reboot";
mqttMessage["state"] = "Rebooting!";
size_t mqttMessageSize = serializeJson(mqttMessage, mqttBuffer);
client.publish(STATE_TOPIC, mqttBuffer, mqttMessageSize);
Serial.println("Rebooting!");
WiFi.disconnect(); // Drop current connection
delay(1000);
ESP.restart();
}
}