{"id":181,"date":"2016-04-29T21:27:48","date_gmt":"2016-04-29T20:27:48","guid":{"rendered":"http:\/\/eoghan.me.uk\/notes\/?p=181"},"modified":"2017-12-01T18:28:24","modified_gmt":"2017-12-01T18:28:24","slug":"raspberry-pi-nfc","status":"publish","type":"post","link":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/","title":{"rendered":"Raspberry Pi with NFC"},"content":{"rendered":"<p><strong>Note<\/strong>: This NFC project uses a Raspberry Pi 2 Model B, and the proceedure may be different to connect RC522 RFID readers to older Raspberry Pis. This is also a work in progress, and these notes are not yet complete.<\/p>\n<p>A few friends from work and I are taking part in a <a href=\"https:\/\/www.justgiving.com\/Big-Leap-Climbing\">sponsored climb<\/a>, six of us climbing the height of the U.K. three peaks (11,180ft) between us on an indoor climbing wall over six hours. One part of our preparation is working out how we&#8217;re going to keep track of the height we have climbed as we go up and down an 8m wall.<\/p>\n<p>What if each of us had an NFC tag on our wrists which we could tap on an NFC reader at the top of the wall? (Or might be safer to tap when we were safely back on the ground.) A slight complication is that there are two heights of wall we might climb, 8m and 6m &#8211; so we could have two NFC readers to tap, one for each wall height. This sounded like a nice Raspberry Pi project.<\/p>\n<figure id=\"attachment_235\" aria-describedby=\"caption-attachment-235\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-235 size-medium\" src=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800-300x225.jpg\" alt=\"The two RC522 readers wired up to the Pi\" width=\"300\" height=\"225\" srcset=\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800-300x225.jpg 300w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800-768x576.jpg 768w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800-400x300.jpg 400w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-235\" class=\"wp-caption-text\">The two RC522 NFC readers wired up to the Raspberry Pi<\/figcaption><\/figure>\n<figure id=\"attachment_381\" aria-describedby=\"caption-attachment-381\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/on_wall.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-381 size-medium\" src=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/on_wall-225x300.jpg\" alt=\"Attached to the climbing wall\" width=\"225\" height=\"300\" srcset=\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/on_wall-225x300.jpg 225w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/on_wall.jpg 480w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-381\" class=\"wp-caption-text\">The finished contraption duct taped to the climbing wall<\/figcaption><\/figure>\n<p>Looking on the Net, I first found an <a href=\"http:\/\/www.instructables.com\/id\/Attendance-system-using-Raspberry-Pi-and-NFC-Tag-r\/\">Attendance system using Raspberry Pi and NFC Tag reader by Yim<\/a> which seemed a good place to start.<\/p>\n<h2>The plan<\/h2>\n<p>The plan would be something like this:<\/p>\n<ol>\n<li>A Raspberry Pi with two NFC sensors would be set up at the bottom of the climbing walls (somehow safely out of the way of climbers and belayers). One sensor would have a notice on it saying &#8220;8m&#8221;, the other one saying &#8220;6m&#8221;<\/li>\n<li>Each climber would have a wristband with an NFC tag attached to it.<\/li>\n<li>After reaching the top of the wall, and abseiling back down, each climber would tap their wrist tag on the sensor for the height of the wall they had just climbed.<\/li>\n<li>The Raspberry Pi would determine which sensor had been tapped by which tag (i.e. what height wall had been climbed by which climber).<\/li>\n<li>The Pi would sound a buzzer and\/or light up an LED to indicate a successful read.<\/li>\n<li>The Pi would then update a MySQL database on a web host with the wall height and climber ID.<\/li>\n<li>A simple PHP script would read the MySQL database, and display a running total of the height left to climb, so people could follow us live online.<\/li>\n<\/ol>\n<p>This application would only need to read the ID of the tags, so it wouldn&#8217;t read or write data to them &#8211; though that could be an idea for an improvement.<\/p>\n<h3>Bearing in Mind<\/h3>\n<p>I expect I would need to wait a few seconds after a successful read before accepting another reading from the same tag\/climber, so we don&#8217;t accidentally record multiple ascents for the same climber if they leave their tag in contact with the reader for a couple of seconds.<\/p>\n<h3>Updated plan<\/h3>\n<p>The original idea was to update a MySQL DB on an external webserver, so the data was safely off the Pi in case it crashed.<\/p>\n<p>But my web server won&#8217;t allow an external device to write to its MySQL databases unless the external device&#8217;s IP address is registered (see Troubleshooting section below). However, running the Raspberry Pi off the eduroam WiFi network, we can&#8217;t get a static IP address for the Pi, nor can we be sure what the external IP address would be. So even if we did register the IP address it was using on eduroam, we couldn&#8217;t be sure the Pi would continue using that same IP address, and might find my web server blocks it from writing to its MySQL DBs.<\/p>\n<p>So the new plan was to was to install Apache, PHP and MySQL on the Pi, and write to the Pi&#8217;s own DB.<\/p>\n<p>But, because of the same problem knowing the Pi&#8217;s IP address on eduroam, our friends outside wouldn&#8217;t be able to connect to it to view our progress.<\/p>\n<p>So the final plan was to write to the Pi&#8217;s own MySQL DB, use PHP on the Pi to build the web page (drawing on the info in the DB) &#8211; then copy that completed web page onto my web server.<\/p>\n<p>This proved a good system, because the Pi periodically lost it&#8217;s WiFi connection, but the info was still being collected on the Pi, and could be uploaded to the web server when the WiFi connection picked up again.f<\/p>\n<h2>The parts<\/h2>\n<ul>\n<li>Raspberry Pi computer, I used a Pi 2B (<a href=\"http:\/\/uk.rs-online.com\/web\/p\/processor-microcontroller-development-kits\/8968660\/\">Raspberry Pi 3 Model B<\/a>, ~\u00a327)<\/li>\n<li>Micro SDHC card, with Micro SDHD to SD adapter (I got a <a href=\"http:\/\/www.dabs.com\/products\/v7-32gb-micro-sd-card-vamsdh32gcl10r-2e-BDMT.html\">32 GB Micro SDHC card, Class 10<\/a>, ~\u00a38; or <a href=\"https:\/\/www.7dayshop.com\/products\/kingston-micro-sd-sdhc-memory-card-45mb-s-class-10-32gb-WH2-SDC10G2\/32GBSP-10632\">save a couple of quid<\/a> if you&#8217;ve already got an adapter)<\/li>\n<li><a href=\"http:\/\/Raspberry Pi Official Universal Power Supply - 5V 2A\">Power adapter<\/a>, ~\u00a37 (but I&#8217;ve also used an old Samsung phone adapter I got from eBay)<\/li>\n<li>USB Keyboard and mouse.<\/li>\n<li>Mifare RFID Reader and tags (I got a set of <a href=\"http:\/\/www.ebay.co.uk\/itm\/161854168730\">three RFID RC522 readers and tags<\/a> from eBay, ~\u00a310)<\/li>\n<li>Some <a href=\"https:\/\/www.jmprime.co.uk\/product_info.php\/1k-mifare-1356mhz-iso14443a-s50-rfid-silicone-waterproof-wristbands-pack-of-10-p-134\">1k Mifare silicone wristbands<\/a>, \u00a318 for ten.<\/li>\n<li>A couple of long ribbon cables, so the RFID readers could be spread out from the Raspberry Pi.<\/li>\n<li>Display screen (I used an old 15-inch DVI flatscreen)<\/li>\n<li>HDMI to DVI cable (I used a <a href=\"http:\/\/www.dabs.com\/products\/startech-com-0-5m-hdmi-to-dvi-d-cable---m-m-hddvimm50cm-9F5S.html\">0.5m HDMI to DVI-D Cable Male\/Male<\/a>, ~\u00a36.50)<\/li>\n<li><a href=\"http:\/\/www.modmypi.com\/raspberry-pi\/breakout-boards\/adafruit\/adafruit-perma-proto-hat-for-pi-mini-kit-no-eeprom\/\">Perma-Proto HAT<\/a>, ~\u00a35<\/li>\n<\/ul>\n<h2>UART, SPI, I2C?<\/h2>\n<p>Only after buying my RFID readers did I notice posts about the different interfaces they support &#8211; UART, SPI, I2C. There was also a post (by <a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=91&amp;t=70756\">FLYFISH TECHNOLOGIES \u00bb Tue May 06, 2014 11:34 pm<\/a>) saying that different readers were hard wired to use just one of the three interfaces.<\/p>\n<p>My original idea was that as we&#8217;d have three people climbing at any one time, they could have an NFC reader each. Reading <a href=\"http:\/\/electronics.stackexchange.com\/questions\/37814\/usart-uart-rs232-usb-spi-i2c-ttl-etc-what-are-all-of-these-and-how-do-th\">a little about the different interfaces<\/a>, it seemd I2C would be ideal &#8211; but it looks like the readers I bought had SPI interfaces which the Pi only has (easy) support for two readers. Luckily I think I can get away with two readers, shared between climbers, depending on the height of the wall they are climbing.<\/p>\n<h2>Setting up the Raspberry Pi<\/h2>\n<p>When it comes to attaching an RC522 reader to a Raspberry Pi, many people link back to Mario&#8217;s seminal <a href=\"http:\/\/fuenteabierta.teubi.co\/2013\/07\/utilizando-el-lector-nfc-rc522-en-la.html\">Utilizando el lector NFC RC522 en la Raspberry Pi<\/a> (online translators help when my Spanish fails).<\/p>\n<p>Sparkfun&#8217;s <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/raspberry-pi-spi-and-i2c-tutorial\">Raspberry Pi SPI and I2C Tutorial<\/a> provides lots of info about the different protocols.<\/p>\n<p>The set up I went through was:<\/p>\n<ol>\n<li>I start with <a href=\"http:\/\/eoghan.me.uk\/notes\/2016\/04\/27\/setup-raspberry-pi\/\">my standard set up instructions<\/a> (this project didn&#8217;t need the camera module set up).<\/li>\n<li>Enable the SPI interface &#8211; from the &#8216;Raspberry Pi Configuration&#8217; window, click the &#8216;Interfaces&#8217; tab, and set SPI to &#8216;Enabled&#8217;. Click &#8216;Ok&#8217; and reboot.<\/li>\n<li>Check the SPI interface is recognised:\n<pre class=\"lang:sh decode:true \">ls \/dev\/spi*\r\n<\/pre>\n<p>This should return &#8216;\/dev\/spidev0.0 \/dev\/spidev0.1&#8217;<\/li>\n<li>A few forums and online info say the <em>\/boot\/config.txt<\/em> file needs to have the device tree explicity switched on. My tags wouldn&#8217;t scan until I did the following:\n<ol>\n<li>Add the following line to the file:\n<pre class=\"lang:sh decode:true \">device_tree=on\r\n<\/pre>\n<\/li>\n<li>Reboot the Pi.<\/li>\n<\/ol>\n<\/li>\n<li>Install the Pi-SpiDev library:\n<pre class=\"lang:sh decode:true\">sudo apt-get install python-dev\r\n\r\ncd ~\r\ngit clone https:\/\/github.com\/lthiery\/SPI-Py\r\ncd SPI-Py\r\nsudo python setup.py install\r\n<\/pre>\n<\/li>\n<li>Install <a href=\"http:\/\/www.tutorialspoint.com\/python\/python_database_access.htm\">MySQLdb<\/a> to allow the scripts to a MySQL database:\n<pre class=\"lang:sh decode:true \">sudo apt-get install python-mysqldb\r\n<\/pre>\n<\/li>\n<li>Install the <a href=\"https:\/\/pypi.python.org\/pypi\/Unidecode\">Unidecode<\/a> library (Yim included this in his instructable to handle Central European characters, so it&#8217;s useful to keep in):\n<pre class=\"lang:sh decode:true \">sudo apt-get install python-unidecode\r\n<\/pre>\n<\/li>\n<li>To install Apache, MySQL and PHP, I followed Ste Wright&#8217;s detailed instructions at:\n<ol>\n<li><a href=\"https:\/\/www.stewright.me\/2016\/03\/turn-raspberry-pi-3-php-7-powered-web-server\/\">Turn your Raspberry Pi 3 into a PHP 7 powered web server<\/a><\/li>\n<li><a href=\"https:\/\/www.stewright.me\/2016\/04\/install-mysql-server-raspberry-pi\/\">Install MySQL Server on your Raspberry Pi<\/a><\/li>\n<li><a href=\"https:\/\/www.stewright.me\/2012\/09\/tutorial-install-phpmyadmin-on-your-raspberry-pi\/\">Install PhpMyAdmin on your Raspberry Pi<\/a><\/li>\n<\/ol>\n<\/li>\n<li>And I needed to install the PHP extensions <em>mbstring<\/em> and <em>gettext<\/em> to get the PhpMyAdmin page to load:\n<pre class=\"lang:sh decode:true\">sudo apt-get install php7.0-mbstring\r\nsudo apt-get install php-gettext\r\n\r\nsudo \/etc\/init.d\/apache2 restart\r\n<\/pre>\n<\/li>\n<li>The <em>mysql.sql<\/em> script should be able to set up the MySQL DB.<\/li>\n<li>Entered the name, surname &amp; tag ID into the <em>people<\/em> table of the database.<\/li>\n<\/ol>\n<h2>The hardware<\/h2>\n<p>This project uses <a href=\"http:\/\/raspberrypi.stackexchange.com\/questions\/12966\/what-is-the-difference-between-board-and-bcm-for-gpio-pin-numbering\">GPIO.BOARD<\/a>, but the GPIO pins column lists the BCM numbers, because it was easier to wire them up with the <a href=\"http:\/\/www.maplin.co.uk\/p\/adafruit-t-cobbler-plus-for-raspberry-pi-a-b-pi-2-n67ea\">T-Cobbler<\/a> when testing.<\/p>\n<table>\n<tbody>\n<tr>\n<th>GPIO Pins<\/th>\n<th>First RC522<\/th>\n<th>Second RC522<\/th>\n<\/tr>\n<tr>\n<td>3V3<\/td>\n<td>3.3V<\/td>\n<td>3.3V<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<tr>\n<td>GPIO 25<\/td>\n<td>RST<\/td>\n<td>RST<\/td>\n<\/tr>\n<tr>\n<td>MOSI<\/td>\n<td>MOSI<\/td>\n<td>MOSI<\/td>\n<\/tr>\n<tr>\n<td>MISO<\/td>\n<td>MISO<\/td>\n<td>MISO<\/td>\n<\/tr>\n<tr>\n<td>SCLK<\/td>\n<td>SCK<\/td>\n<td>SCK<\/td>\n<\/tr>\n<tr>\n<td>CE0<\/td>\n<td>SDA<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>CE1<\/td>\n<td>&#8211;<\/td>\n<td>SDA<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\" colspan=\"3\">Green LEDs<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>Negative leg<\/td>\n<td>Negative leg<\/td>\n<\/tr>\n<tr>\n<td>GPIO 4<\/td>\n<td>Positive leg<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>GPIO 17<\/td>\n<td>&#8211;<\/td>\n<td>Positive leg<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\" colspan=\"3\">Red LEDs<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>Negative leg<\/td>\n<td>Negative leg<\/td>\n<\/tr>\n<tr>\n<td>GPIO 27<\/td>\n<td>Positive leg<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>GPIO 22<\/td>\n<td>&#8211;<\/td>\n<td>Positive leg<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\" colspan=\"3\">Buzzers<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>Negative leg<\/td>\n<td>Negative leg<\/td>\n<\/tr>\n<tr>\n<td>GPIO 18<\/td>\n<td>Positive leg<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>GPIO 24<\/td>\n<td>&#8211;<\/td>\n<td>Positive leg<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<figure id=\"attachment_236\" aria-describedby=\"caption-attachment-236\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-236\" src=\"http:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800-300x212.jpg\" alt=\"The wiring diagram for two RC522 readers and a buzzer\" width=\"300\" height=\"212\" srcset=\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800-300x212.jpg 300w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800-768x542.jpg 768w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800-425x300.jpg 425w, https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/NFC-RFID_bb_w800.jpg 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-236\" class=\"wp-caption-text\">The wiring diagram for two RC522 readers and a buzzer<\/figcaption><\/figure>\n<h2>The Python code<\/h2>\n<p>I&#8217;ve based my code on <a href=\"https:\/\/github.com\/mxgxw\/MFRC522-python\">MFRC522-python code by mxgxw<\/a>, and adapted it to use two RFID readers. At the moment the code continually switches the SPI master between the two readers, polling them for chip reads &#8211; which probably isn&#8217;t the most efficient way to do things (if anyone who understands the SPI interface and Raspberry Pi can suggest a better way, or a different interface, then I&#8217;d be very interested). But as my application doesn&#8217;t have to do anything but log chip reads, then it will probably manage Ok.<\/p>\n<p>I also noticed that the chip IDs read in by the code can sometimes be corrupted &#8211; for my purposes, I&#8217;ve just hardcoded the chip IDs into the python script, and only log a read if it matches one of those IDs (again, not very efficient, and it would be great to improve it).<\/p>\n<ol>\n<li>Set up a directory on your Pi for the project &#8211; I usually create a &#8216;Python Projects&#8217; directory in &#8216;Documents&#8217;:\n<pre class=\"lang:sh decode:true \">mkdir ~\/Documents\/Python\\ Projects\r\ncd ~\/Documents\/Python\\ Projects\r\n<\/pre>\n<\/li>\n<li>Get the source code for this project from the <a href=\"https:\/\/github.com\/eoghan-c\/team_track\">GitHub repository<\/a>:\n<pre class=\"lang:sh decode:true\">git clone https:\/\/github.com\/eoghan-c\/team_track.git\r\n<\/pre>\n<\/li>\n<li>Copy the HTML file and PHP script so they can be served by the Pi&#8217;s webserver:\n<pre class=\"lang:sh decode:true \">sudo cp ~\/Documents\/Python\\ Projects\/team_track\/scripts\/* \/var\/www\/html\r\n<\/pre>\n<\/li>\n<\/ol>\n<h2>Troubleshooting<\/h2>\n<p>As probably many others do, my web host&#8217;s security required me to <a href=\"https:\/\/www.tsohost.com\/knowledge-base\/article\/642\/remotely-accessing-your-mysql-mssql-database-on-the-cloud\">register my Raspberry Pi&#8217;s external IP address<\/a> with them before my python scripts could write to my MySQL DB on their servers. This took a little messing around to get working (especially as the IP address they say on that page that we need to connect to doesn&#8217;t seem to be the correct one!). I could use the Pi as a web host and database server, but when it&#8217;s connected to the University&#8217;s eduroam on the day, that wouldn&#8217;t allow external people to view the progress page.<\/p>\n<h2>Auto-run the script on boot<\/h2>\n<p>I used systemd, as detailed by Matt in <a href=\"http:\/\/www.raspberrypi-spy.co.uk\/2015\/10\/how-to-autorun-a-python-script-on-boot-using-systemd\/\">How To Autorun A Python Script On Boot Using systemd<\/a><\/p>\n<p>(though &#8216;Type=simple&#8217; seemed to work for my script).<\/p>\n<p>My Unit file at <em>\/lib\/systemd\/system\/team_track.service<\/em> contained:<\/p>\n<pre class=\"lang:sh decode:true\">[Unit]\r\nDescription=Track our team's climbing progress using NFC tags\r\nAfter=multi-user.target\r\n\r\n[Service]\r\nType=simple\r\nExecStart=\/usr\/bin\/python \"\/home\/pi\/Documents\/Python Projects\/team_track\/team_track.py\"\r\nRestart=on-abort\r\nUser=root\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n<p>After refreshing the daemon with\u00a0<em>sudo systemctl daemon-reload<\/em> I told systemd to start the service during the boot sequence, with:<\/p>\n<pre class=\"lang:sh decode:true \">sudo systemctl enable team_track.service\r\n<\/pre>\n<p>The following commands are useful to get the status, or stop the service:<\/p>\n<pre class=\"lang:sh decode:true\">sudo systemctl status team_track.service\r\nsudo systemctl stop team_track.service\r\n<\/pre>\n<h2>Limitations<\/h2>\n<h3>Hardcoded info<\/h3>\n<p>As usual, this was a very rushed project. A lot of information hardcoded into the Python scripts could be handled better &#8211; e.g.:<\/p>\n<ul>\n<li>The tag IDs are listed in the <em>chip_uids<\/em> variable in <em>team_track.py<\/em> script, but are also are entered into the <em>people<\/em> table of the MySQL DB.<\/li>\n<li>The target height of our combined climb is listed in <em>scripts\/content.php<\/em> script, in the\u00a0<em>$target_height<\/em> variable &#8211; might be better to have is in a separate MySQL table?<\/li>\n<li>The SQL database, user and password are in variables at the top of the <em>scripts\/content.php<\/em> script.<\/li>\n<li>The SQL database, user and password are also added in the\u00a0Connect() function of the <em>mysql.py<\/em> script.<\/li>\n<li>As I couldn&#8217;t get a static address for the Raspberry Pi, the <em>get_ip_addr.py<\/em> script posted the Raspberry Pi&#8217;s current IP address to a <em>ip.html<\/em> page on an external server.\n<ul>\n<li>The <em>remote_account<\/em> variable was hardcoded with the user &amp; server address of the server (e.g. &#8216;myuser@123.45.0.6&#8217;).<\/li>\n<li><em>remote_file_dir<\/em> held the path to the directory to write to.<\/li>\n<li><em>remote_url_prefix<\/em> held the URL to the <em>ip.html<\/em> page.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Improvements<\/h2>\n<p>Storing some data on the tags themselves could be an idea, maybe have the names of the people on the tag instead of listed in the people table of the MySQL DB (but maybe that wouldn&#8217;t simplify things after all, especially as I seem to get data corruption when reading the tags).<\/p>\n<h2>The final result<\/h2>\n<p>In the end the area roped off for our challenge only contained 8m walls &#8211; so we set both NFC readers to register 8m, instead of one for 8m and one for 6m.<\/p>\n<p>While we climbed, <a href=\"http:\/\/eoghan.me.uk\/other\/climb\/\">this webpage displayed our running total<\/a> (where it stays, frozen in time).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This NFC project uses a Raspberry Pi 2 Model B, and the proceedure may be different to connect RC522 RFID readers to older Raspberry Pis. This is also a work in progress, and these notes are not yet complete. A few friends from work and I are taking part in a sponsored climb, six [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":235,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Raspberry Pi with NFC - Eoghan&#039;s Notes<\/title>\n<meta name=\"description\" content=\"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Raspberry Pi with NFC - Eoghan&#039;s Notes\" \/>\n<meta property=\"og:description\" content=\"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/\" \/>\n<meta property=\"og:site_name\" content=\"Eoghan&#039;s Notes\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-29T20:27:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-01T18:28:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eoghan\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eoghan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/\",\"url\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/\",\"name\":\"Raspberry Pi with NFC - Eoghan&#039;s Notes\",\"isPartOf\":{\"@id\":\"https:\/\/eoghan.me.uk\/notes\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg\",\"datePublished\":\"2016-04-29T20:27:48+00:00\",\"dateModified\":\"2017-12-01T18:28:24+00:00\",\"author\":{\"@id\":\"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/8d580b9cc431078e942962f5df92e800\"},\"description\":\"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.\",\"breadcrumb\":{\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage\",\"url\":\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg\",\"contentUrl\":\"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg\",\"width\":800,\"height\":600,\"caption\":\"The two RC522 readers wired up to the Pi\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eoghan.me.uk\/notes\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Raspberry Pi with NFC\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/#website\",\"url\":\"https:\/\/eoghan.me.uk\/notes\/\",\"name\":\"Eoghan&#039;s Notes\",\"description\":\"The odd note that might come in handy someday\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eoghan.me.uk\/notes\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/8d580b9cc431078e942962f5df92e800\",\"name\":\"Eoghan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/248edf410b45769042d524cee3cce559fa8db50415efb82f79ea8a2d138b15cf?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/248edf410b45769042d524cee3cce559fa8db50415efb82f79ea8a2d138b15cf?s=96&d=mm&r=g\",\"caption\":\"Eoghan\"},\"url\":\"https:\/\/eoghan.me.uk\/notes\/author\/eoghan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Raspberry Pi with NFC - Eoghan&#039;s Notes","description":"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/","og_locale":"en_GB","og_type":"article","og_title":"Raspberry Pi with NFC - Eoghan&#039;s Notes","og_description":"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.","og_url":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/","og_site_name":"Eoghan&#039;s Notes","article_published_time":"2016-04-29T20:27:48+00:00","article_modified_time":"2017-12-01T18:28:24+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg","type":"image\/jpeg"}],"author":"Eoghan","twitter_misc":{"Written by":"Eoghan","Estimated reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/","url":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/","name":"Raspberry Pi with NFC - Eoghan&#039;s Notes","isPartOf":{"@id":"https:\/\/eoghan.me.uk\/notes\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage"},"image":{"@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage"},"thumbnailUrl":"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg","datePublished":"2016-04-29T20:27:48+00:00","dateModified":"2017-12-01T18:28:24+00:00","author":{"@id":"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/8d580b9cc431078e942962f5df92e800"},"description":"A project to track the progress of climbers on an indoor charity climb by attaching two NFC readers to a Raspberry Pi using the SPI interface.","breadcrumb":{"@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#primaryimage","url":"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg","contentUrl":"https:\/\/eoghan.me.uk\/notes\/files\/2016\/04\/breadboard_side_w800.jpg","width":800,"height":600,"caption":"The two RC522 readers wired up to the Pi"},{"@type":"BreadcrumbList","@id":"https:\/\/eoghan.me.uk\/notes\/2016\/04\/29\/raspberry-pi-nfc\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eoghan.me.uk\/notes\/"},{"@type":"ListItem","position":2,"name":"Raspberry Pi with NFC"}]},{"@type":"WebSite","@id":"https:\/\/eoghan.me.uk\/notes\/#website","url":"https:\/\/eoghan.me.uk\/notes\/","name":"Eoghan&#039;s Notes","description":"The odd note that might come in handy someday","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eoghan.me.uk\/notes\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/8d580b9cc431078e942962f5df92e800","name":"Eoghan","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/eoghan.me.uk\/notes\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/248edf410b45769042d524cee3cce559fa8db50415efb82f79ea8a2d138b15cf?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/248edf410b45769042d524cee3cce559fa8db50415efb82f79ea8a2d138b15cf?s=96&d=mm&r=g","caption":"Eoghan"},"url":"https:\/\/eoghan.me.uk\/notes\/author\/eoghan\/"}]}},"_links":{"self":[{"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":68,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":400,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/posts\/181\/revisions\/400"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/media\/235"}],"wp:attachment":[{"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eoghan.me.uk\/notes\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}