Wednesday, June 03, 2015

An NFC Based Audit Log, Adventures In Overengineer A Garden Notebook

I want to do a better job of tracking garden activities. Sure, I could pick up a $1.75 notebook at the store, but I lose all the niceties that go with having a digital copy of the data. Besides, there's actually an interesting problem to solve here: how do you associate an audit log with a physical object? Ideally an audit log is write-only, automatically timestamped and has minimal opportunities for user error. While my garden ramblings hardly require this level of sophistication, it would be nice to work out a solution to this problem. Once I had one, I could keep logs of all sorts of physical items (I'm looking at you furnace, with your filters that need to be changed yearly...).

OK, let's over-engineer a solution!

My first thought was to print out some QR Codes, and leverage that technology. The QR Code, in theory, would help me avoid human error associated with matching my notes up with the right object (i.e., plant). But why stop there? How awesome would it be to slap NFC tags on the my plants (or really, their containers) and use that to identify them.

The NFC tag could serve two purposes: first, it would kick off the log entry process and second, it would uniquely identify that plant I'm making notes about.

I ordered 10 NFC stickers from eBay. If all goes well, they'll be waterproof and simple to attach to the containers or a popsicle stick. With the easy part out of the way, I now needed to figure out a crafty way to make these NFC tags actually do something.

Enter Tasker.

I already use Tasker and NFC tags in our laundry room, so I know kicking off a Task is no big deal. The next ingredient: taking note input from the user. This, too, is easy to do in tasker. Just invoke the Variable Query action. It's ugly, but totally effective.

Moving on, I needed to figure out where I was going to store these entered notes. My ideal solution was to have it appended to a Google Spreadsheet of my choice. I imagined having to work out Google Authentication from within Tasker and figured I'd have to lower my sights a bit. Perhaps Tasker could write to a text file and FolderSync could push these files to the web. Still, I figured it wouldn't hurt to Google around for a Spreadsheet solution.

And what do you know, it's easy to do! Using a Google Form, you can trivially post data to a spreadsheet. I developed a quick form that looks like so:

I then used an HTTP POST action from within Tasker to submit this form. The results are timestamped rows, which is exactly what I was after.

I was almost there. I had my notes and place to store them, I was now missing the NFC Serial Number to associate my notes with the object. Unfortunately, there's no obvious way to get the NFC Serial Number from within Tasker. On to Plan B. Each NFC Tag is setup with Tasker as its own Profile. I can name these profiles and using %caller2, I'm able to access this name. In some respects, using the Profile name is even better than the NFC Tag, as the name is under my control (versus being a random alphanumeric string).

The solution is built! Let's test it out. Consider a test tag setup in Tasker:

When I hover my phone over my test tag I get the following prompt:

After I hit submit, my Google Spreadsheet auto updates with this information:

As solutions go, there's no denying this is clunky, but it precisely meets my needs. Setting up a new tag should be fast (New Profile; Scan Tag; Name Profile; Done) and using them should be even faster (Scan; Type; Done). Google Spreasheets even has improved filter capability. This means that I can look at a season's worth of planting data, or just the detail of one plant, with ease.

There you have it: a write-only, auto-timestamped, idiot-proof solution to tracking notes associated with an object.

I'll truly know this works when the NFC stickers arrive. In the meantime, I may splurge and implement this same capability with QR Codes. The code for the Post Notes Task is below. Happy Hacking!

Profile: Test Tag (51)
    State: Locale NFC Plugin [ Configuration:C26745C6 - repetitive ]
Enter: Post Notes (47)
    Abort Existing Task
    A1: Variable Set [ Name:%src To:%caller1 ] 
    A2: Variable Split [ Name:%src Splitter:: ] 
    A3: Variable Query [ Title:Notes Variable:%notes Input Type:Normal Text ] 
    A4: HTTP Post [ Server:Port:https://docs.google.com
                    Path:/forms/d/1qVh0HbYKXal25c8VCm_ov9GFFsYx6D0bSsp2GpFdMfI/formResponse
                    Data:entry.1657698255=%src2
                         entry.1862053229=%notes
                     Content Type:application/x-www-form-urlencoded ] 
    A5: Vibrate Pattern [ Pattern:0,500 ] 

No comments:

Post a Comment