Hallo liebes Forum,
ich habe einen Nano 33 IOT an welchem ein RFID Reader angeschlossen ist und mit der MFRC522 Bibliothek funktionert.
Leider hört der Reader manchmal einfach auf Karten zu lesen (manchmal nach ner halben Stunde manchmal von Beginn an) ich kann das Problem nicht ganz einordnen.
Die Loop an sich in der das Programm läuft funktioniert noch nur passiert absolut nichts wenn man eine Karte auf den Reader legt (egal welche).
Vielleicht habt ihr ja eine Idee wie ich das Problem eingrenzen/reproduzieren könnte oder woran es liegen kann.
Anbei ist mein Programm Code.
Viele Grüße Alex
#include <SPI.h>
#include <WiFiNINA.h>
#include "arduino_secrets.h"
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
#define button 5
boolean buttonState;
boolean oldState;
MFRC522 mfrc522(SS_PIN, RST_PIN);
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
char str[56] = "";
char mID[3] ="00"; // 00 = Mastercontroller
char Ausgabe[17] ="";
boolean LED = false;
WiFiClient client;
WiFiSSLClient sclient;
IPAddress server(192,168,0,110);
int status = WL_IDLE_STATUS; // the WiFi radio's status
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(button,INPUT_PULLUP);
buttonState = digitalRead(button);
oldState = buttonState; //damit der Shelly nicht ausgeschaltet wird wenn der Arduino neu startet
SPI.begin();
mfrc522.PCD_Init();
mfrc522.PCD_DumpVersionToSerial(); //Details des Lesegerätes ausgeben
Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
// wait for serial port to connect. Needed for native USB port only
pinMode(6, OUTPUT);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.println("You're connected to the network");
printCurrentNet();
printWiFiData();
}
void loop() {
digitalWrite(6, LOW);
buttonState = digitalRead(button);
if (buttonState != oldState){
httpRequestClear();
oldState = buttonState;
}
while (client.available()) {
char c = client.read();
// Serial.write(c);
}
Seruial.println(mfrc.ui
//Suche nach neuen Karten
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
//Informationsabruf des RFID-Gerätes
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
array_to_string(mfrc522.uid.uidByte, 7, str); //Insert (byte array, length, char array for output)
Serial.println(str);
for(int i = 0; i <14; i++){
Ausgabe[i] = str[i];
}
Ausgabe[14] = mID[0];
Ausgabe[15] = mID[1];
Serial.println(Ausgabe);
httpRequest();
}
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the Nina module
;
client.stop();
// if there's a successful connection:
if (client.connect(server, 5005)) {
Serial.println("connecting...");
client.print(Ausgabe);
digitalWrite(6, HIGH);
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
}
void httpRequestClear() {
// close any connection before send a new request.
// This will free the socket on the Nina module
;
client.stop();
// if there's a successful connection:
if (client.connect(server, 5005)) {
Serial.println("connecting...");
client.print("0000000000000000");
digitalWrite(6, HIGH);
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
}
void printWiFiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP address : ");
Serial.println(ip);
Serial.print("Subnet mask: ");
Serial.println((IPAddress)WiFi.subnetMask());
Serial.print("Gateway IP : ");
Serial.println((IPAddress)WiFi.gatewayIP());
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
void array_to_string(byte array[], unsigned int len, char buffer[]){
for (unsigned int i = 0; i < len; i++){
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '\0';
}