@Ralla66 Vielen Dank für Deine Mühe!!
Ich habe mir erlaubt, Deinen Sketch ein wenig zu überarbeiten. Er läuft jetzt bei mir mit allen mqtt-Versionen ohne Verbindungsabbrüche. (Habe ihn 'mal angehängt)
Grüße
Wolfgang
/***************************************************
Fingerprint am Wemos D1 mini per MQTT nach IO Broker
/
#include <Adafruit_Fingerprint.h>
//#include <WiFiClient.h>
#include <ESP8266WiFi.h> // Aus Wifi Mqtt
#include <PubSubClient.h> // Aus Wifi Mqtt
#include <SoftwareSerial.h>
#include <NTPClient.h>
/
Pinbelegung Fingerprint Sensor ist GND,Rx,TX,Vcc
Am Wemos Rx ist D6 also GPIO 12
Am Wemos Tx ist D5 also GPIO 14
*****************************************************/
SoftwareSerial mySerial(14, 12, false, 128);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
// Eigene Daten eintragen
const char* ssid = ""; // Netzwerknahme
const char* password = ""; // PW Netzwerk
const char* mqttServer = ""; // Broker PI
const int mqttPort = 1883; // Broker PI Port
const char* mqttUser = ""; // Broker PI Name
const char* mqttPassword = ""; // Broker PI Password
// Ab hier nix mehr machen
char* mqttio = "12345"; // Broker PI Wert
char* confidence = "67890"; // Broker PI Wert
WiFiClient espClientfp;
PubSubClient client(espClientfp);
int cnt=300;
void setup()
{
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
finger.getTemplateCount();
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
Serial.println("Waiting for valid finger...");
Serial.begin(115200); // Baud Wemos nach IDE Serieller Monitor
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
Serial.print("=> ESP8266 IP Adresse: ");
Serial.println(WiFi.localIP());
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
}
void reconnect(){
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP8266Clientfp", mqttUser, mqttPassword)) {
Serial.println("connected");
} else {
Serial.print("failed with state ");
Serial.print(client.state());
delay(5000);
}
}
client.subscribe("print/Confidence");
client.subscribe("print/FingerprintNr1");
client.publish("print/FingerprintNr1","Print verbunden");
client.publish("print/Confidence","Genauigkeit verbunden");
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
Serial.println("-----------------------");
}
void loop() { // run over and over again
if (!client.connected()) {
reconnect();
}
if(cnt==0){
Serial.println("Reset...");
ESP.restart();
}
cnt--;
delay(1000);
Serial.println(cnt);
client.loop();
getFingerprintIDez();
delay(50); //don't ned to run this at full speed.
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
}
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
sprintf(mqttio,"%d",finger.fingerID);
sprintf(confidence,"%d",finger.confidence);
client.subscribe("print/Confidence");
client.publish("print/Confidence", confidence);
client.subscribe("print/FingerprintNr1");
client.publish("print/FingerprintNr1", mqttio);
Serial.print("Erkannter Fingerabdruck Nr. "); Serial.print(mqttio);
Serial.print(" mit einer Genauigkeit von "); Serial.println(confidence);
return finger.fingerID;
client.loop();
}