IndieWeb Summit 2019 – Hack Day Recap

Today is day two of IndieWeb Summit 2019, emphasizing hands-on experimentation to learn more about the IndieWeb, improve your web site, and/or help other folks with their own projects.  My goal for the day was to resolve a number of the issues I was having getting core IndieWeb functionality working with my WordPress based blog. Thanks to some great help from David Shanske and Jack Jamieson (plus the power of hands-on tinkering), here’s what I accomplished:

  • Adopted a WordPress theme that’s both fully compatible with IndieWeb protocols and microformats and visually appealing to me.  Specifically I installed and switched to IW26 — David Shanske’s fork of the WordPress 2016 standard theme.
  • Enabled support for IndieAuth, WebMention and MicroPublish endpoints by adding the right <link> elements to my home page.  As part of that learned how to use the Microformats parser on microformats.io to examine and debug my own settings.
  • Set up an .htaccess file in my site’s home directory with rules to properly handle redirection to https: and to dereference  the www. prefix to site URLs.  Made the appropriate matching adjustments in WordPress and my Dreamhost admin panel.
  • Developed a better understanding of WordPress Post Kinds (after all, David wrote the plugin), customized the set to fit what I’m likely to use when I post, and tested a few.
  • Added rel-me connections to my blog for Flickr and Instagram using the WordPress widget.
  • Tested use of Quill as a micropublishing client. Successfully posted a note to my blog from Quill in Firefox on an Android phone.
  • Tested WebMention support thanks to Jack, resulting in a series of comments on our respective sites (and also highlighting a formatting bug he was able to fix on his custom WordPress theme with some help from David).
  • Added Syndication Link support and tested it by posting a review to TripAdvisor.com and a companion note on my blog reference that review.

This got me over the WordPress vs. IndieWeb theme problem I’d been struggling with and hoped to resolve today, and a lot more overall IndieWeb functionality as a bonus.  Thanks to David & Jack’s help I’m comfortable asserting that you can satisfyingly bring IndieWeb to a WordPress site, though more compatible themes and onboarding resources would both be big wins.

Fiftieth Anniversary of Apollo 11

Apollo 11 lifted off on July 14th, 1969 so in three weeks we’ll be celebrating the fiftieth anniversary of that historic mission.  I was thirteen years old in July 1969 and several years into a deep childhood fascination with the space program.  Not surprisingly I was glued to the television and newspapers for every aspect of the Apollo 11 mission and still remember how I felt watching and following along.

I’m looking forward to repeating that experience this July and am delighted to have the Internet to help me out.  For my own part I’ve taken a timeline of mission events from NASA, wrapped it in a bit of JavaScript, and created a simple web page that will help me keep track of the flow of the mission in real time (though fifty years after the fact).

I don’t have a rich collection of mission photos, videos, and artifacts, or the time to find and weave any into my mission timeline, something I knew other folks would be better positioned to accomplish.  Ben Feist and team have done precisely that in creating Apollo 11 in Real Time so I’ll also have that open continuously between liftoff on July 14 and splashdown on July 24.

Last night I watched Todd Douglas Miller’s “Apollo 11” documentary on CNN (which released it) and it brought back vivid memories of July fifty years ago.  I expect I’ll watch it several more times over the course of the next three weeks — highly recommended.

Happily both July 14th, liftoff day, and July 20th, landing/EVA day, fall on weekends so I expect I’ll set aside time both those days to reconnect with the event that was such a powerful and formative part of my youth. Might also be a good time to build a few space-themed model kits I’ve squirreled away, attend a Splashdown 50 event on the nearby USS Hornet (which recovered the Apollo 11 capsule and crew) or just listen to the official mission mixtape.

Exploring Arduino Interrupts

I’ve been wanting to add wind & rain sensors to my home-built Arduino-powered weather station and thanks to a recent sale at Sparkfun have acquired their nicely-built set.  As a result, though, I have two interesting problems to solve in getting those sensors integrated to the temperature and barometric pressure ones I have deployed today.  First, I need to work out where and how to install the wind/rain sensors as placement is critical in getting good readings  Of more immediate concern, however, is that I need to rethink my weather station application in order to properly integrate the new sensors, especially the anemometer and rain gauge.

At the moment my weather station code uses basic clock timing to read temperature and barometric pressure sensors periodically, average their values, and display the readings on a small attached OLED. Temperature and pressure sensors are continuous so their values are always available and can be read whenever desired just based on the Arduino’s internal clock. While my new wind vane sensor also provides a continuous reading, the new anemometer and rain gauge don’t work that way.  Instead they report data discontinuously whenever they have something to share.

In the case of the anemometer it closes an internal switch every time the cups rotate through one revolution.  Deriving wind speed from the anemometer means counting the number of revolutions over some specific period of time and calculating the number of revolutions per second. Multiplying revolutions-per-second by a fixed factor based on the size and geometry of the anemometer lets you determine average wind speed over that period of time.  You can’t simply poll the anemometer and ask it to tell you what it is observing as you can with temperature, pressure, or wind direction sensors.

Similarly the rain gauge can’t provide a continuously-available reading, but instead closes a switch every time its internal self-emptying bucket fills and dumps.  The volume of the tiny bucket is known, so keeping track of how many times it has emptied over a specific period of time lets you figure out how much rain has fallen.

Therefore a different approach is needed to read sporadic sensors like the anemometer and rain gauge and keep track of every time their internal switches close, whenever that turns out to be and no matter how often.  The asynchronous, switch-closing nature of those sensors is a perfect case for interrupt-driven data gathering.

A good overview on interrupts and how they work on Arduino is available over at EngBlaze. In my case I need to modify my weather station code to add logic to handle the calculations to be done whenever either the anemometer or rain gauge closes their internal switch. Just as with reading my other sensors, I need to devote an Arduino pin to each of the anemometer and rain gauge so I can detect their respective switch closures.  This turns out to be pretty easy as Arduino has already set aside pins to handle two external interrupts: interrupt number 0 (or INT0) on digital pin 2 and interrupt number 1 (or INT1) on digital pin 3.  All you need to do is connect the interrupt-generating device to one of those two pins, write a simple handler function you want to be called every time an interrupt occurs, and use the special built-in attachInterrupt function to associate your handler with the chosen pin.

A simple example is provided in the Arduino reference for attachInterrupt(). Here’s another one aligned with my intent to use interrupts to read my anemometer and calculate wind speed:

/*
 * Example program for Arduino external interrupts, in this case to read
 * an anemometer connected to digital pin 2 (which is INT0).
 *
 * Author: David Bryant (david@orangemoose.com)
 */

volatile int interruptCnt = 0;  // Counts anemometer interrupts

unsigned long sampleDelayMs = 30*1000; // Sample interval, milliseconds
unsigned long prevSampleMs = 0;        // Timestamp for previous sample

void setup()
{
  Serial.begin(9600);
  Serial.println("Gathering data...");

  // Attach our interrupt service routine to INT0
  attachInterrupt(0,anemom_cnt,RISING);
}

void loop()
{
  unsigned long currentMillis = millis();    // Get current timer value
  /* See if it is time to calculate wind speed */
  if( (currentMillis - prevSampleMs) >= sampleDelayMs) {
    Serial.print("Anemometer count: ");
    Serial.println(interruptCnt);

    prevSampleMs = currentMillis;   // Remember clock time
    interruptCnt = 0;               // Reset counter
  }
}

/*
 * Interrupt service routine called when the anemometer switch closes.
 * All it needs to do is increment the interrupt counter.
 */
void anemom_cnt()
{
  interruptCnt++;
}

This works well enough and is quite straightforward, but I’m not completely happy with it.  To add my anemometer and rain gauge I need two interrupts, but I’d like to make broader use of interrupts in my weather station code. For example, I’m currently using a push button to step through a series of screens on an attached OLED so a user can browse a variety of information from the sensor including maximum and minimum readings, system statistics, etc.  At the moment that push button is read periodically as part of the sensor timing loop but it’d make more sense to have it generate an interrupt to trigger stepping to the next screen.  It may also make sense to use interrupts to handle other sensors I could add, or support other system functions. Using all the available external interrupts just for the anemometer and rain gauge seems short sighted.

Happily the Arduino supports handling interrupts on every pin, both analog and digital, through a different mechanism than INT0/INT1 and their attachInterrupt function.  That means there’s lots of room for expansion, but it requires a bit more low-level knowledge and coding.  That’s a good subject for another blog post…