Moin Miteinander
Ich bin gerade dabei ein RFID Zugangskontrolle zu Programmieren.
Der bereich mit RFID Karte auslesen und die Daten an den Server Schicken
sowie die Prüfung klappt so weit.
Mein Problem aktuell ist
ich möchte noch 2 Taster bzw Input Signal in das Programm einbinden.
Nach langen probieren hab ich raus gefunden das der void loop teil
nur aktiv bzw aktiviert wird wenn eine karte ausgelesen wird.
Aber warum ist das so ? bzw wie kann ich das ändern
hab schon das Internet durchsucht ob jemand das gleiche Problem hat wie ich.
Würde mich sehr freuen wenn mir jemand bei meinen Problem helfen kann
MfG
Stefan
//// ESP
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <string.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
////ESP
// NFC module
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#define PN532_SCK D1
#define PN532_MOSI D2
#define PN532_MISO D3
#define PN532_SS D0
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
#define PN532_IRQ (2)
#define PN532_RESET (3) // Not connected by default on the NFC Shield
extern uint8_t BigFont[];
String ID = "";
// NFC module ENDE
String id = "046F6952B25681";
#define Button D6 //GPIO2
int buttonState = 0 ;
void setup() {
//gpio.mode(ledPin,gpio.OUTPUT)
pinMode(D5, OUTPUT);
pinMode(Button, INPUT) ;
USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFiMulti.addAP("WH3", "**********");
////// NFC
Serial.println("Hello!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.print("Waiting for an ISO14443A card");
}
/////// NFC ENDE
void loop() {
delay(1000);
USE_SERIAL.print("TEst");
buttonState = digitalRead (buttonState) ;
if ( buttonState == HIGH ) {
Serial.println("TAster");
HTTPClient http;
USE_SERIAL.print("[HTTP] begin--tesr\n");
http.begin("http://192.168.178.63/alm.php"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
}
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
ID = "";
for (uint8_t i=0; i < uidLength; i++)
{
char tmp[3];
sprintf(tmp,"%02X",uid[i]);
ID += tmp;
//ID = ID + String(uid[i],HEX);
// Serial.print(":");Serial.print(uid[i], HEX);
}
Serial.print(ID);
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
http.begin("http://xxx.xxxxx.de/id.php?ID="+(ID)); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
if (payload.indexOf("true") == (payload.length() - 4) ){
USE_SERIAL.println("tür auf");
digitalWrite(D5, 1);
delay(1000); // wait for a second
digitalWrite(D5, 0);
}else {
USE_SERIAL.println("nop");
}
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
Serial.println("");
// Wait 1 second before continuing
delay(1000);
}
else
{
// PN532 probably timed out waiting for a card
//Serial.println("Timed out waiting for a card");
}
}