2-Bullet Tuesday - Edition #65
Welcome back to 2-Bullet Tuesday, where we’ll share useful tips and awesome stuff sent in by Omega2 users all around the world. Check out creative projects and tutorials that will supercharge your IoT development!
Omega Tip #1
Building Custom Kernel Modules for the Omega2
This week’s featured project is actually more of a tip and is brought to you by an active member of the Onion Community, Maximiliam Gerhardt. Max prepared a detailed guide on how to build a custom Kernel Module for the Omega2 using the LEDE Build System. For some background, kernel modules are code that can be loaded into the kernel dynamically (ie without having to reboot) to extend the functionality the kernel, and thereby, your device.
This very thorough guide covers what a Kernel Module is and why it’s useful, a full procedure for building a sample “Hello World” Kernel Module, and, the icing on the cake, builds on this knowledge to create a kernel module for accepting input from a USB XBox Joystick!
Thank you for such an amazing and detailed tutorial, Max! We especially like how you presented a topic super clearly, and then immediately used it to make something awesome!
Omega Tip #2
Using RFID & NFC Expansion to write/read NDEF Data
Last week we guided you through setting up your RFID & NFC Expansion and then reading and writing Mifare Ultralight tags. This week, we’ll continue using the new RFID & NFC Expansion, but this time, we’ll be writing standardized NDEF messages to a MiFare Classic card that can be read by other NFC enabled devices like smartphones!
We’ll guide you through the installation process and the hardware setup. Then we’ll jump into reading & writing NDEF data. So, let’s get started!
Installation of the tools
If you haven’t followed our earlier tip about setting up the RFID & NFC Expansion, take a look at that for more details. If you’re in a hurry, here are the commands you’ll need to run:
opkg update opkg install nfc-exp
This will install the
libfreefarelibraries and utilities that we’ll be using for this week’s tip. For more details on these libraries and utilities, see our Docs article on using the RFID & NFC Expansion.
Please note: During the boot process, the Expansion draws a lot of current. We recommend connecting it to a Dock while the Omega is powered off. If the Omega is powered on, the large current draw may cause the Omega to reboot.
NDEF? What is That?
NDEF stands for NFC Data Exchange Format and it is a standardized data format for exchanging data between NFC enabled devices. Rather than writing raw data like we did previously, the NDEF format allows us to give context to the data we’re writing. This allows the device that reads the NDEF-formatted data to automatically take action based on the data it reads, for example: opening a browser to navigate to a website stored on the card, or connecting to a WiFi network based on the network name and password stored on the card. In our case, we’ll be using NDEF to write a plain-text message to start.
If you’re interested in learning more about NDEF, Adafruit has a great article on the topic.
Writing NDEF Message to the Card
Let’s get started! For this example, we will be writing a plain-text (human-friendly) message to a Mifare Classic 1K Card.
First, we’ll need to write the message we plan to write to the card. On your Omega, create a file called
ndef-message.txtand populate it with the following text:
Hello World, I'm using Onion RFID & NFC Expansion
Now, we’ll write this message to your Mifare Classic card. From the command line, issue the following:
mifare-classic-write-ndef -y -o ndef-message.txt
And you’ll see something like the following:
-yoption tells the program we’re sure about what we’re doing and that it doesn’t need to prompt for any confirmation. The
-i ndef-message.txtargument specifies the contents of
ndef-message.txtas the NDEF message to be written
Our message has been written to the card successfully! Now let’s read the card’s NDEF content!
Reading NDEF Message from the Card
In order to read card’s NDEF content, issue the following command from your terminal:
mifare-classic-read-ndef -y -o read-ndef-message.txt
This well read the contents of the card, and store them on the Omega’s filesystem in a file called
read-ndef-message.txt. You can use
catto see the message:
Formatting the Card
If you’ve written a whole bunch of NDEF records to your card and want a clean slate, you can use the
mifare-classic-formatcommand to delete of the content currently stored on the card. The card will still be usable, it will just be empty. Just note that this operation cannot be reversed and all data on the card will be lost, so please proceed with caution and back up the data that you wish to save.
In order to format your card, run the following command:
This will perform a fast format (erases only MAD) and will not ask for confirmation.
And there you have it, we’ve learned how to read and write NDEF messages to a MiFare Classic card. As mentioned, NDEF messages are super useful since they can be quickly read by other devices, including most modern smartphones, opening the door to lots of awesome security, information sharing, and automation applications. We can’t wait to see all of the awesome NFC projects you all come up with!
Make sure to subscribe to 2-Bullet Tuesday to get technical tips about using the Omega, projects created by Omega2 users, and, occasionally, special promotions for the Onion Online Store sent directly to your inbox!
P.S. We're going to be out in Silicon Valley for a double-header in mid-May. Come see us at IoT World in Santa Clara May 14-17 & MakerFaire Bay Area May 18-20.