Skip to content

Commit

Permalink
fix: wifi password and vcard payload prints
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 17, 2023
1 parent 8d1c3f7 commit 767085e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
50 changes: 35 additions & 15 deletions examples/NDEFReceive/NDEFReceive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
#define PN7150_VEN (13)
#define PN7150_ADDR (0x28)

#define PRINTF Serial.print

void print_buf(const char *prefix, const uint8_t *data, size_t size) {
PRINTF(prefix);
for (size_t loop = 0; loop < size; loop++) {
PRINTF(data[loop], HEX);
PRINTF(" ");
}
PRINTF("\n");
}

// Function prototypes
void displayDeviceInfo();
void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize);
void customNdefCallback();
void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize);

// Create a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
Expand All @@ -18,7 +29,7 @@ void setup() {
Serial.println("Detect NFC tags with PN7150");

// Register a callback function to be called when an NDEF message is received
// RW_NDEF_RegisterPullCallback((void *)*ndefCallback);
RW_NDEF_RegisterPullCallback((void *)*ndefCallback);
nfc.setSendMsgCallback(customNdefCallback);

Serial.println("Initializing...");
Expand Down Expand Up @@ -150,6 +161,10 @@ void displayDeviceInfo() {
}
}

void customNdefCallback() {
Serial.println("Processing Callback...");
}

void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
unsigned char *pNdefRecord = pNdefMessage;
NdefRecord_t NdefRecord;
Expand All @@ -172,15 +187,14 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
Serial.print("vCard:");
// Serial.println(NdefRecord.recordPayload);
Serial.println(reinterpret_cast<const char *>(NdefRecord.recordPayload));
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;
} break;

case WELL_KNOWN_SIMPLE_TEXT: {
save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
Serial.print("Text record: ");
// Serial.println(&NdefRecord.recordPayload[NdefRecord.recordPayload[0]+1]);
Serial.println(reinterpret_cast<const char *>(&NdefRecord.recordPayload[NdefRecord.recordPayload[0] + 1]));
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;
} break;
Expand All @@ -189,7 +203,6 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
Serial.print("URI record: ");
// Serial.println(ndef_helper_UriHead(NdefRecord.recordPayload[0]), &NdefRecord.recordPayload[1]);
Serial.println(reinterpret_cast<const char *>(ndef_helper_UriHead(NdefRecord.recordPayload[0]), &NdefRecord.recordPayload[1]));
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;
} break;
Expand All @@ -204,9 +217,11 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
if (NdefRecord.recordPayload[index] == 0x10) {
if (NdefRecord.recordPayload[index + 1] == 0x45) {
Serial.print("- SSID = ");
for (i = 0; i < NdefRecord.recordPayload[index + 3]; i++)
Serial.print(NdefRecord.recordPayload[index + 4 + i]);
Serial.println("");
Serial.println(reinterpret_cast<const char *>(&NdefRecord.recordPayload[index + 4 + 0]));
// for (i = 0; i < NdefRecord.recordPayload[index + 3]; i++) {
// // Serial.print(NdefRecord.recordPayload[index + 4 + i]);
// Serial.println(reinterpret_cast<const char *>(&NdefRecord.recordPayload[index + 4 + i]));
// }
} else if (NdefRecord.recordPayload[index + 1] == 0x03) {
Serial.print("- Authenticate Type = ");
Serial.println(ndef_helper_WifiAuth(NdefRecord.recordPayload[index + 5]));
Expand All @@ -215,9 +230,11 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
Serial.println(ndef_helper_WifiEnc(NdefRecord.recordPayload[index + 5]));
} else if (NdefRecord.recordPayload[index + 1] == 0x27) {
Serial.print("- Network key = ");
for (i = 0; i < NdefRecord.recordPayload[index + 3]; i++)
Serial.print("#");
Serial.println("");
Serial.println(reinterpret_cast<const char *>(&NdefRecord.recordPayload[index + 4]));
// for (i = 0; i < NdefRecord.recordPayload[index + 3]; i++) {
// Serial.print(reinterpret_cast<const char *>(&NdefRecord.recordPayload[index + 4 + i]));
// }
// Serial.println("");
}
index += 4 + NdefRecord.recordPayload[index + 3];
} else
Expand All @@ -241,6 +258,13 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {
Serial.print("BT Handover payload = ");
// Serial.print(NdefRecord.recordPayload);
// Serial.println(NdefRecord.recordPayloadSize);
print_buf("", NdefRecord.recordPayload, NdefRecord.recordPayloadSize);
// Serial.print(reinterpret_cast<const char *>(&NdefRecord.recordPayload[0]));
unsigned char i;
for (i = 0; i < NdefRecord.recordPayloadSize; i++) {
Serial.print(reinterpret_cast<const char *>(&NdefRecord.recordPayload[i]));
}
Serial.println("");
break;

case MEDIA_HANDOVER_BLE:
Expand All @@ -263,7 +287,3 @@ void ndefCallback(unsigned char *pNdefMessage, unsigned short NdefMessageSize) {

Serial.println("");
}

void customNdefCallback() {
Serial.println("Processing Callback...");
}
12 changes: 11 additions & 1 deletion src/RW_NDEF_MIFARE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ void RW_NDEF_MIFARE_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsi
{
if (pRW_NDEF_PullCb != NULL)
pRW_NDEF_PullCb(NULL, 0);

if (ndefReceivedCallback != NULL) {
ndefReceivedCallback(); // Run custom callback
}

break;
}

Expand Down Expand Up @@ -191,8 +196,13 @@ void RW_NDEF_MIFARE_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsi
memcpy(&RW_NDEF_MIFARE_Ndef.pMessage[RW_NDEF_MIFARE_Ndef.MessagePtr], pRsp + 1, RW_NDEF_MIFARE_Ndef.MessageSize - RW_NDEF_MIFARE_Ndef.MessagePtr);

/* Notify application of the NDEF reception */
if (pRW_NDEF_PullCb != NULL)
if (pRW_NDEF_PullCb != NULL) {
pRW_NDEF_PullCb(RW_NDEF_MIFARE_Ndef.pMessage, RW_NDEF_MIFARE_Ndef.MessageSize);
}

if (ndefReceivedCallback != NULL) {
ndefReceivedCallback(); // Run custom callback
}
}
else
{
Expand Down

0 comments on commit 767085e

Please sign in to comment.