2

I try to create an Android app that sends a key to an Arduino NFC Shield. I am able to send the key from the mobile and turn on the LED on the Arduino. But I don't know how to make the NFC shield send back to the Android device a response: valid key or not.

I get the message on Arduino, I am able to turn on the LED when the key is correct. The problem is that I need the NFC Shield to send back a message to the mobile phone, so that the app knows everything worked as expected or not.

I use NFC Shield PN532 (with Adafruit_PN532) in SPI mode.

success = nfc.inListPassiveTarget();
if(success) {

    Serial.println("Found something!");
    uint8_t selectApdu[] = { 
      0x00, /* CLA */
      0xA4, /* INS */
      0x04, /* P1  */
      0x00, /* P2  */
      0x05, /* Length of AID  */
      0xF2, 0x22, 0x22, 0x22, 0x22};

    uint8_t response[255];
    uint8_t responseLength = sizeof(response);

    success = nfc.inDataExchange(selectApdu, 
          sizeof(selectApdu), response, &responseLength);

    if(success) {            
        if(validKey(response, responseLength)){
          Serial.println("Acces GRANTED.");
          accesGranted();
        }else{
          Serial.println("Acces DENIED!!!!!!!!!!!!!!!!\n");
        }            
    }
    else{
        Serial.println("Failed sending SELECT AID"); 
    }
}
Macpp
  • 33
  • 9
  • 1
    Possible duplicate of [Can't exchange data between Android phone and Arduino with NFC module, using HCE](https://stackoverflow.com/questions/22643294/cant-exchange-data-between-android-phone-and-arduino-with-nfc-module-using-hce) – theantomc Jun 22 '19 at 13:42
  • You need to set responseLength manually, check the post that I linked – theantomc Jun 22 '19 at 13:43
  • @theantomc No, it`s not duplicate. I recieve the string on the Arduino. I want to send a confirmation back to Android. – Macpp Jun 22 '19 at 13:53
  • Ah ok. You want in the same moment send and after receiving the string on the Arduino send the response on the Android app? All by NFC? – theantomc Jun 22 '19 at 15:25
  • @theantomc yes. The Android app needs to know the string was received and was correct. – Macpp Jun 22 '19 at 16:01

0 Answers0