-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2P_Send.ino
42 lines (33 loc) · 1016 Bytes
/
P2P_Send.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Sends a NDEF Message to a Peer
// Requires SPI. Tested with Seeed Studio NFC Shield v2
#include "SPI.h"
#include "PN532_SPI.h"
#include "snep.h"
#include "NdefMessage.h"
PN532_SPI pn532spi(SPI, 10);
SNEP nfc(pn532spi);
uint8_t ndefBuf[128];
void setup() {
Serial.begin(9600);
Serial.println("NFC Peer to Peer Example - Send Message");
}
void loop() {
Serial.println("Send a message to Peer");
NdefMessage message = NdefMessage();
message.addUriRecord("http://shop.oreilly.com/product/mobile/0636920021193.do");
//message.addUriRecord("http://arduino.cc");
//message.addUriRecord("https://github.com/don/NDEF");
int messageSize = message.getEncodedSize();
if (messageSize > sizeof(ndefBuf)) {
Serial.println("ndefBuf is too small");
while (1) {
}
}
message.encode(ndefBuf);
if (0 >= nfc.write(ndefBuf, messageSize)) {
Serial.println("Failed");
} else {
Serial.println("Success");
}
delay(3000);
}