This post shows steps to setup Wi-Fi Simple Configuration with NFC adapter on Raspberry Pi using nfcpy[1]. The goal is to enable “tap-to-connect” a NFC enabled phone with a Wi-Fi access point [2].
Prerequisites (parentheses indicate my environment)
- Raspberry Pi board (Raspberry Pi 3 B+) running Raspbian Stretch (June 2018)
- NFC USB adapter (Identiv SCL3711)
- NFC enabled phone (Samsung Galaxy S7)
Steps
1. Installation
1-1. Install nfcpy.
pip install -U nfcpy
1-2. Verify installation by running the module.
python -m nfc
The output should be like this:
$ python -m nfc No handlers could be found for logger "nfc.llcp.sec" This is the 0.13.5 version of nfcpy run in Python 2.7.13 on Linux-4.14.50-v7+-armv7l-with-debian-9.4 I'm now searching your system for contactless devices ** found usb:04e6:5591 at usb:001:004 but access is denied -- the device is owned by 'root' but you are 'pi' -- also members of the 'root' group would be permitted -- you could use 'sudo' but this is not recommended -- better assign the device to the 'plugdev' group sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"04e6\", ATTRS{idProduct}==\"5591\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules' sudo udevadm control -R # then re-attach device I'm not trying serial devices because you haven't told me -- add the option '--search-tty' to have me looking -- but beware that this may break other serial devs Sorry, but I couldn't find any contactless device
1-3. As the output suggests, copy line 11 above and execute it.
sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"04e6\", ATTRS{idProduct}==\"5591\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
1-4. Reboot the system.
sudo reboot
1-5. After reboot, run the module again.
python -m nfc
This time, the output should be like this:
$ python -m nfc No handlers could be found for logger "nfc.llcp.sec" This is the 0.13.5 version of nfcpy run in Python 2.7.13 on Linux-4.14.50-v7+-armv7l-with-debian-9.4 I'm now searching your system for contactless devices ** found SCM Micro SCL3711-NFC&RW PN533v2.7 at usb:001:004 I'm not trying serial devices because you haven't told me -- add the option '--search-tty' to have me looking -- but beware that this may break other serial devs
2. Setting up Wi-Fi Simple Configuration
2-1. Download example code [3].
git clone https://github.com/nfcpy/nfcpy.git
2-2. Create NDEF data [4] for Configuration token [5].
./nfcpy/examples/ndeftool.py make wificfg NETWORK_NAME --key PASSWORD -o cfg_token
Note: Replace “NETWORK_NAME” and “PASSWORD” based on your environment.
2-3. Write NDEF data to NFC adapter [6].
./nfcpy/examples/tagtool.py emulate -l cfg_token tt3
3. Test
3-1. Enable NFC on the phone.
3-2. Move the phone close to the NFC adapter.
3-3. Allow to connect if the phone asks for permission.
References
[1] Python module for near field communication – nfcpy
[2] WPS adds NFC “tap-to-connect” for simple set up – Wi-Fi Alliance
[3] nfcpy – GitHub
[4] NFC Data Exchange Format – nfcpy
[5] make wificfg – nfcpy
[6] emulate – nfcpy