Live-tweeting a marathon with MQTT, Node-RED and IBM MessageSight
Christian Karasiewicz 270005XS4E Comments (2) Visits (14879)
"How am I going to find you in the crowd?"
Running a marathon requires support—lots of it. You need energy gels, sports drink and, most important, encouragement. Two days before my first marathon last February, I was trying to explain to my wife exactly when and where to meet me on the marathon course to provide support. As she asked the question above, I realized that "I'll be passing mile 17 sometime between 9:30 and 10:00 a.m." is a pretty imprecise answer!
Being your typical software guy, I like to hack together useful applications in my free time. In my role with IBM I get to do the same thing: hack together demo applications that showcase the "art of the possible" in the Internet of Things (IoT) space, using the IBM MessageSight appliance and lightweight MQ Telemetry Transport (MQTT) publish/subscribe protocol. So the next day, while resting for the race, I combined work and play and built a real-time marathon tracking solution: IBM RaceTracker.
How does it work? In a nutshell: a GPS capture device publishes location data to a message broker, which is consumed by an analytics application (capturing mile splits, average pace and so on), which publishes stats and events to the message broker that are consumed by a mobile web application and a "tweeting" application.
That’s a lot of components! Here's some more info:
1. The GPS capture device I selected is the iOS/Android app OwnTracks, an open-source "location diary" that continually publishes a message with location information at a periodic interval (for example, every 5 seconds or 10 meters moved). OwnTracks is perfect for this solution because of the simplicity and ease of configuration: just configure the publish topic, point to a messaging broker and your location information starts getting published. Here's an example:
2. The publish/subscribe protocol used here is MQTT, a lightweight messaging protocol perfectly suited for the Internet of Things. MQTT conserves battery life on the mobile, has clients for nearly all major platforms and languages, and uses a simple programming interface that is easy to integrate into any application. The messaging quality of service (QoS) is configurable: because of the large number of cell signals (runners and spectators) clustered near the starting line, the "exactly once" QoS was perfect for times during the race when my cell signal was lost momentarily.
3. The messaging broker is IBM MessageSight, a messaging appliance optimized for the IoT. It is tuned for massive throughput and scalability, with the ability to handle up to a million connected clients and up to 12 million messages per second. In other words, we could use one appliance to track runners at the largest marathons (NYC, Boston, Chicago) at the same time!
4. I built the analytics application in Node.js and deployed to Codename: BlueMix, IBM's platform as a service (PaaS) solution based on Cloud Foundry. Node.js has several MQTT client modules available; I chose the MQTT module. The analytics application is very simple: it subscribes to an MQTT wildcard topic for all runners in a particular race (Rac
The analytics application also keeps a static definition of the race in the form of a course map (a set of longitude and latitude coordinates making up the route) and landmark positions. When the application is first started, the MQTT client publishes this information as MQTT "retained" messages (the MQTT broker will retain these messages for new subscribers).
6. Since my analytics application is already publishing events through IBM MessageSight at key moments of the race, I can easily consume this information from multiple subscribers. Along with consuming the data in the web app, I created a simple Node-RED flow to convert the "events" to "tweets," published on the account @bryanboydruns.
Node-RED is a Node.js-based tool that allows you to quickly and easy map input events (for example, an MQTT message or HTTP request) to output events (for example, database and file logging, MQTT publish, tweet, HTTP response).
This solution worked perfectly! My wife and friends were able to view my progress in real time and easily find me on the course to hand out sports drinks and high fives. About twenty-five others used the app and Twitter feed to follow my progress remotely. My father even watched my progress from a restaurant in Germany, with the wait staff cheering me on!
The demo is accessible here, with my race data running in a playback loop: http
It's amazing how simple it is to build applications in a publish/subscribe "IoT environment," where many "things" (iOS app, analytics app, web app, tweeting app) communicate with each other through a central messaging broker in real time. The fact that I crafted this in less than a day is evidence of that.
I want to hear from you! What is a mobile or IoT solution you have built to solve a personal, real-world problem? Leave a comment below, or reach out to me on Twitter at @bryanboyd.
I'll be demoing this and other applications at IBM Impact, April 27 to May 1 in Las Vegas. Stop by the IBM MessageSight Gaming Zone or attend my Thursday afternoon session (IOT-1912) to learn more.