Internet of Things: Paranoid Gardener

I think it’s fair to say that my project turned out to be rather simplistic. After some initial hardware-pondering and debugging (thanks Samu for expertise), it turned out that element14’s explore-nfc expansion board was the choice to go with. The expansion board along with a Raspberry Pi model B + a usb wifi dongle was the hardware arsenal on top of which this NFC-reading application was built.

Starting out with the task I suspected to be the most intensive, I set out to write a client on top of the Raspberry Pi in C. This client would be responsible for 1) reading nfc tag id’s and 2) uploading the tag id’s along with timestamps to a web-backend. At first, I had a design that employed TCP sockets and a little bit of linux signalling and forking in my mind. Wanting to add some new elements to the mix, I was going to write the networking part using a message-queuing library called ZeroMQ. ZeroMQ would make it easy to add encryption and some nice network designs to the project.Knowing that ZeroMQ was written in C++, I assumed that would be a not-too-different (and not any less well documented!) C-API available. Well, it turned out that due to the socket management that ZeroMQ does, it isn’t straightforward to fork the process using standard Linux system calls. From how I got it, ZeroMQ sockets live in the realm of a ZeroMQ context – this context cannot simply be shared among multiple threads or processes. Instead, ZeroMQ provides it’s own thread handling functionality, for which I deemed the CZMQ’s (a ZeroMQ C-API implementation) documentation to be insufficient. Balancing between learning and getting the project wrapped up, I decided to code the networking parts of the client using standard linux socket APIs.

Another thing on the client side that struck me was the question of how to give feedback to a NFC-keychain swinging user. I figured that the most obvious solutions would be either using a speaker or blinking LED lights. To keep things simple, the final project uses the one and only controllable green LED light that’s on board a Raspberry Pi. No user friendliness here, but it works.

To conclude, a little bit of the www-backend. It’s divided into two parts: 1) a TCP server listening for incoming nfc-id &  timestamp tuples and 2) an actual www-server, both of which are implemented using Node.JS and communicate through MongoDB. The www-server uses Twitter bootstrap for templating and Angular.JS + jQuery for implementing some AJAX functionality.Initially, the plan was togo and only use Angular.JS (and the minimalistic jQuery implementation that comes along with it). I also wanted to use Twitter bootstrap’s modals to increase the UI-friendliness when letting the user see and make comments that are associated with timestamped NFC id readings. Angular.JS and Twitter bootstrap modals did not seem to work together out of the box (going deeper into this would’ve defocused the project), so I decided to mix in a little bit of jQuery. Well, it ain’t fancy, but it works.

The original post is below:

Gardening and crops are a serious business. Rumor has it that some players have even gone as far as patenting their long-cultivated and slightly modified plants and the seeds they produce. Gees! It is clear that such an industry that holds secrets more valuable than the welfare of the gardeners themselves needs adequate protection mechanisms, and fast.

My project’s called the Paranoid Gardener, but instead of Paranoid Androids, the platform it will be built on is a Raspberry PI.  As the process of evaluating the requirements to wholly secure such a vital system (everybody has to eat, right?) is still continuing, the exact plan isn’t 100% fool-proof yet.. but it will at least involve an NFC authentication system. Besides the authentication of users, the system should aim at tracking the approximate flow of visitors to the garden by recording the times the door has been opened.  If there’s time, it would be interesting to take a look at nearby mobile device detection by catching WIFI probes. On the other hand, the system could interact with its user by sending messages over BT. Minimally, the system should publish its authentication data to web. We shall see how the final design comes together.

One thing that isn’t clear at this stage is the access control and management of NFC tags that are associated with the system. A promising way could be the running of a web backend on the PI through which commands could be sent in order to create new NFC tags, or remove old ones. This will be a point to be considered later.