![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
NFC With peripherals
Dependencies: EthernetInterface_NFC HTTPClient_NFC LibPN532_NFC mbed-rtos mbed
Fork of NFC_Secure_Access by
Diff: main.cpp
- Revision:
- 2:881a9a0da73f
- Parent:
- 1:6e04ab90909f
- Child:
- 3:17dd24c1b0c3
diff -r 6e04ab90909f -r 881a9a0da73f main.cpp --- a/main.cpp Sun Apr 22 23:33:45 2018 +0000 +++ b/main.cpp Thu Apr 26 18:40:34 2018 +0000 @@ -7,25 +7,27 @@ #include "EthernetInterface.h" #include "HTTPClient.h" +DigitalOut Buzzer (D8); + char* thingSpeakUrl = "http://api.thingspeak.com/update"; char* thingSpeakKey = "7QKJFB65MJBCNM3L"; EthernetInterface eth; TCPSocketConnection sock; DigitalOut ledBrd (LED1); // arducleo onboard led Serial pc(USBTX, USBRX); - + // ----------------------------------------- HSU //HardwareSerial pn532_hsu (PC_10, PC_11); //PN532_HSU pn532_if (pn532_hsu); - + // ----------------------------------------- SPI SPI pn532_spi (D11, D12, D13); PN532_SPI pn532_if (pn532_spi, D10); - + // ----------------------------------------- I2C //I2C pn532_i2c (I2C_SDA, I2C_SCL); //PN532_I2C pn532_if (pn532_i2c); - + PN532 nfc(pn532_if); void setup(void) { @@ -47,10 +49,10 @@ (versiondata>>16) & 0xFF, (versiondata>>8) & 0xFF); nfc.setPassiveActivationRetries(0xFF); - + // configure board to read RFID tags //nfc.SAMConfig(); - + pc.printf ("\n\rWaiting for an ISO14443A card\n"); } void loop(void) @@ -59,7 +61,7 @@ uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; uint8_t uidLength; success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); - + if (success) { pc.printf("\n\rFound a card!\n\r"); pc.printf("UID Length: %d bytes\n\r", uidLength); @@ -75,7 +77,7 @@ // the following line and this text should be read back in a minute //memcpy(data, (const uint8_t[]){ 'a', 'n', 'i', 'k'}, sizeof data); //success = nfc.mifareclassic_WriteDataBlock (4, data); - + // Try to read the contents of block 4 success = nfc.mifareclassic_ReadDataBlock(4, data); if (success) { @@ -93,6 +95,9 @@ strcat(str, "Aniket's Card Accessed"); value = 1; } else { + Buzzer=1; + wait(0.2); + Buzzer=0; pc.printf("\n\rNo access for this card\n\r"); strcat(str,"Invalid Card Accessed"); value = 404; @@ -110,21 +115,20 @@ wait_ms (5000); } } - - + + /*============================================================================== * \brief main entry */ int main() { - + eth.init(); //Use DHCP eth.connect(); printf("\n\rEthernet connected, and IP Address is %s\n\r", eth.getIPAddress()); setup(); - + while (1) loop (); eth.disconnect(); -} - +} \ No newline at end of file