Last active
December 19, 2015 06:39
-
-
Save don/5912937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * P2P NDEF Push | |
| * requires http://www.seeedstudio.com/depot/nfc-shield-v20-p-1370.html | |
| * and https://github.com/Seeed-Shield/NFC_Shield_DEV | |
| * simplified example based on examples/nfc_ndef_push_url | |
| */ | |
| #include <PN532.h> | |
| #include <NFCLinkLayer.h> | |
| #include <SNEP.h> | |
| #include <NdefMessage.h> | |
| #define SCK 13 | |
| #define MOSI 11 | |
| #define SS 10 | |
| #define MISO 12 | |
| PN532 nfc(SCK, MISO, MOSI, SS); | |
| NFCLinkLayer linkLayer(&nfc); | |
| SNEP snep(&linkLayer); | |
| NdefMessage m; | |
| void setup(void) { | |
| Serial.begin(115200); | |
| Serial.println(F("Push NDEF Message")); | |
| m = NdefMessage(); | |
| m.addTextRecord("yo!"); | |
| m.addUriRecord("http://arduino.cc"); | |
| m.addMimeMediaRecord("text/json", "{\"greeting\": \"hello\"}"); | |
| nfcBegin(); | |
| } | |
| void loop(void) | |
| { | |
| Serial.println(F("\n---------------- LOOP ----------------------\n")); | |
| byte encoded[m.getEncodedSize()]; | |
| m.encode(encoded); | |
| uint32_t txResult = GEN_ERROR; | |
| if (IS_ERROR(nfc.configurePeerAsTarget(SNEP_SERVER))) { | |
| extern uint8_t pn532_packetbuffer[]; | |
| while (!nfc.isReady()) { | |
| } | |
| nfc.readspicommand(PN532_TGINITASTARGET, (PN532_CMD_RESPONSE *)pn532_packetbuffer); | |
| } | |
| do { | |
| txResult = snep.pushPayload(encoded, sizeof(encoded)); | |
| Serial.print(F("Result: 0x")); | |
| Serial.println(txResult, HEX); | |
| delay(3000); | |
| } while(0); | |
| } | |
| void nfcBegin() { | |
| // this code should be in nfc.being() | |
| nfc.initializeReader(); | |
| 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); | |
| Serial.print("Supports "); | |
| Serial.println(versiondata & 0xFF, HEX); | |
| nfc.SAMConfig(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment