Category Archives: Programming

Magic Candles – fun with Alexa and IoT

A while back my wife had picked up a packet of flameless candles from costco. These come with an infrared remote which you can change colors, switch modes between glow and flicker and schedule the candles to turn off after a predetermined time interval.

I thought it’d be cool to be able to have my Alexa controlling these, you walk into the room, turn off the lights and turn on these candles thereby creating a perfect environment for a romantic candle lit dinner. Right?

I got some time over the weekend to work on this and here it is, in all it’ s glory for you to enjoy.

If you’re not interested in the technical details involved in setting this up, then you can stop here. Here’s the hardware that I’ve used –

  • Raspberry Pi (This plays a dual role, it hosts the server that communicates with the IR blaster and it’s also the IoT device that Alexa talks to)
  • Blackbean Mini (This is the IR blaster, it mimics the remote)
  • Flameless Candles and Remote (For obvious reasons)

The software components are –

  • broadlink-http-rest – HTTP server, running on Raspberry Pi to Communicate with the IR blaster
  • AWS IOT SDK – This is also running on my Raspberry Pi to make it an IOT device which listens on an MQTT topic to which the Alexa Skill publishes messages. This reads that message and makes a REST call to our HTTP Server
  • Alexa Skills Kit SDK – For the Alexa Skill, to publish a message to the MQTT topic
  • AWS Lambda, to host the Alexa Skill – I don’t think I’ll ever spin up another web server for my hobby projects

Here’s a visual diagram that represents the interaction between the pieces to paint a clearer picture –

And for those of you who want to dive deeper and play with the code, you can find it on Github.

I’ve also jotted down some notes and learnings based on developing this –

  • The AWS IOT suite is really good, MQTT is a secure way to interact with IOT devices. Going forward I expect to see more devices use this, the current IOT scene is quite messy with every manufacturer spinning up their own HTTP version, with base64 encoded communication which provides no security. With this you can rest assured that it wont be easy for hackers to use you IoT device for the next DDOS attack.
  • The MQTT/HTTP performance is really good, as you can see in the demo; there’s no lag between my wife talking to Alexa and the action being performed, despite this going through multiple systems each running on different infrastructure and written in different languages. The IR Server Bridge is written in python, the Raspberry Pi runs the AWS IOT Javascript SDK, the Alexa skill is written in Java and is run on demand on a serverless platform.
  • REST is awesome, this build upon the previous point. This seamless integration is possible because all these pieces talk REST
  • AWS IOT SDK documentation is atrocious to the point that it almost negates all the great features that it exposes. It took me more than a few hours to read up the documentation, source code and even some Javascript examples to understand how to open a line of communication with my device using the Java SDK. This despite my familiarity with a bunch of other AWS Services. Writing good services and software isn’t enough, if your users can’t figure out how to use it. I hope that my code helps someone else battling similar issues. I have a lot more to say about this, but if I was to go on, it would end up being a rant. I’ll reserve that for a future post(maybe).

I had a lot of fun building this, maybe this can give someone else inspiration for their own IoT project. It’s really easy to extend this to control other devices in your home – TVs, ACs, Game Consoles and a bunch of other things are all controlled with IR remotes. The IoT domain is so much fun these days, the fully automated smart home even on a budget is now a reality.


Path Tracker an Alexa Skill for local train timings

I’ve had the Amazon Echo for a while, recently I had some time on my hands and decided to build a skill that at least I would find useful.

Typically my wife and I talk with Alexa to ask her for the weather, we use it to set timers when doing the laundry or short term reminders and occasionally to play music or audiobooks.

Before leaving home for office, my wife and I generally check the public transit timings. I thought it’d be cool if Alexa could tell us that instead, with this in mind I searched around for PATH schedules and how to access that information programatically. Turns out the Port Authority have this available to developers in the GTFS . After reading the GTFS Reference and playing around with the PATH feed it took me a couple of hours to wrap my head around and to come up with a simple way to find train timings between any two stations.

After I had a working version of the train timings algorithm coded, I proceeded to read the documentation for the Alexa skills programming model, the documentation is a little dry but starts making sense as you code up and test your skill. I found the Big Nerd Ranch youtube videos to be very helpful in getting a general feel of the programming model.

I had initially planned to host the backend as a service on one of my raspberry pi’s but due to the number of hoops that Amazon makes you jump through, I ended up leaning towards AWS lambda. It was a bit of a pain to get started with lambda as the support community is rather limited, you’ll need to figure out some of the things yourself by trial and error. (I had no luck at AWS forums and very little at StackOverflow, overall though StackOverflow seems to be a much better place to ask your questions and get some help)

Once you overcome the initial challenges with running your skill on AWS lambda, it’s actually a fun platform to develop on, I was no fan going into this but came out a believer the Zero Infrastructure and configuration to host code is certainly going to catch on. I do have some complaints about performance during a cold start but I reckon that this is only going to get better with time.

After everything was done and I had tested the functionality with my local echo device, I submitted the skill for certification.
A few days later I heard back from the certification team that my skill was rejected. I got this response

Issues with skill in English (US)

1. When attempting to invoke the skill with your second and third example phrases, the skill fails to recognize the phrases. The example phrases must function without error since these are interactions that users are most likely to try. Please see test case 3.1 from our Submission Checklist for guidance on example phrases.


User: “Alexa Ask Path Tracker When is the next train between Exchange Place and Newark”/ “Alexa Ask Path Tracker Train to Exchange Place from Newark”

The skill fails to recognize the phrases.

I spent an hour or so trying to figure out why the skill won’t recognize the phrase and came to a conclusion that maybe Newark wasn’t the best station to list on the sample interaction, I recalled that I didn’t know how to pronounce it either before I’d moved to the US, so I changed the sample to –

Alexa Ask Path Tracker What time is the next train from Grove Street to World Trade Center

And submitted the skill for certification again and voila after a couple of days I got an email to let me know that my skill was now live.

The source code is available at Github, feel free to share your feedback or certification experience at either place.



It’s been a while since I last blogged, sort of lost the interest didn’t know what to write about but you don’t really care about that do you! Lets get to the point and I’ll tell you what has me so excited about Meteor.

New programming languages and frameworks keep coming along faster than the speed of light in the world of technology but most of them just whiz by and hardly interest me. There are however a few which stand out amongst the crowd and Meteor is one of them. I’ve had a bittersweet relationship with JavaScript, back in the day when I had only gotten started with programming with C++ in school I found it like a breath of fresh air. It could add that fancy rollover effect to pages or a bouncing ball on a webpage, I was amazed by it. But the cross browser issues, quirky behavior and it being a nightmare to debug I gave up on JavaScript.

For a few years it stayed that way, I taught myself some php got bored by it and moved to ruby tried dipping my feet in rails but without much luck as it was too magical. I boarded the Sinatra bandwagon, it is an awesome framework. No magic, no nonsense simply rest but then again Sinatra itself isn’t enough to make nice websites you need something for the front end too and that’s when I started to dive into jQuery rediscovering my love for JavaScript. I read a couple of books on jQuery embraced the asynchronous and restful nature of the web and it was such a joy to make web applications again.

After that for the last couple of years things have been slowed down, sure there have been performance enhancements in jQuery and node.js came along too. I had a brief look at node.js but really didn’t see how much more of a value add it was over Sinatra. Similarly Knockout.js didn’t really knock me out neither did backbone have that much of a backbone for me. Meanwhile at work I used GWT which in my opinion isn’t the best way to write a web application today(It may have been 5 years ago, not anymore). Had I discovered the ultimate framework? Had I achieved nirvana? I sure thought so.

That was untill a week ago when I was struck by meteor.js, I had watched the introductory video and my head was abuzz with such excitement after a long time indeed. I watched the second video and boy was I jumping up and down. Meteor isn’t just an evolutionary framework it’s revolutionary! It doesn’t split the client and server parts of your web app but presents them together. It’s how you would develop any application, sure you need to know about the security aspects but when you’re developing something it should be fun, you shouldn’t be spending time on downloading jQuery and your favorite bootstrap framework and other trivial details. Ideally you should be able to focus on the core of your application and all the secondary things should be dead easy to implement. I also like the social focus of meteor, it couldn’t be easier to integrate your app with Facebook/twitter or for that matter any other social networking site.

What trumps all those minor features and enhancements is it’s publish subscribe feature, if you asked me what was the one single feature that defines meteor. You don’t need to implement polling to write a fluid always up to date interface, this isn’t the 1980s. Meteor just works where most other frameworks make you do too much unnecessary work! Also the package management is pretty sleek, it compares and in some cases surpasses the ruby gems which I consider the ideal package manager.

Having heaped so much praise on meteor I still have a few doubts, the most important is about how well will meteor scale? This is one factor that will probably decide meteors future in the years to come. Will it end up as a toy for prototyping stuff or will it dislodge rails from its pedestal remains to be seen. From a technical perspective it’ll be curious to see what strategy they eventually take to scale and perform under high load. Another thing that is probably on meteor’s roadmap is to support the various other nosql stores other than mongo db. It’ll be interesting to see how they implement this, right now the syntax is quite specific to mongo it’d be better if it was neutral so that there could be support for stores like dynamo db with no change in the existing application code. One last thing that would be absolutely awesome is integration with Native Mobile Apps, even though web apps work well on mobile devices native apps are miles ahead. It remains to be seen how easily can one write the app in meteor and then hook up the presentation onto the native platforms. Boy would that be sweet!

All in all this makes meteor a very interesting framework to watch out for even if you don’t write too much JavaScript, it has so much potential where it will be in two or three years time is an open question. Regardless of how it ends, the ride along the way promises to be a lot of fun. I don’t know about you but I’m boarding it right now!

Introducing Chagol!

Having learnt how easy it was to develop ruby gems, I thought of putting my newly learned skills to the test and the result is chagol. Any work of software starts by scratching a developer’s personal itch and chagol does that for me. Before I tell you how to get hold of chagol, let me tell you why I’ve started developing it. As a student most of my communication is through text messages and quite often when I’m working on something I get a message that I have to respond to. I typically reply back using the phone or use a service like way2sms to do the same both of these take more time than that ought be taken. I’m a command line junkie so a command line tool with a simple interface would be ideal for me and since none existed I thought I’d write one myself. Continue reading Introducing Chagol!

Churning out ruby gems

If you didn’t already know then let me tell you that I’m a huge fan of the ruby programming language. I have dabbed with a few imperative languages and none can come close to ruby, it’s syntax is like sugar and libraries like alcohol. You get addicted to them once you start. I use gems (that’s the fancy name for ruby libraries) from time to time. They can be used in both programs that you write and some also provide a standalone binary. But that is hardly the fascinating part, what is fascinating is that how easy it is to create them. I just created one and will mention the steps briefly so that you are also inspired to try your hand at it. Continue reading Churning out ruby gems

Getting graphics.h to work on Windows and Linux

We have an introductory Computer Graphics course at our university this semester, we will be working with BGI(Borland Graphics Interface) which has its origins in Borland Turbo C. It goes without saying that I’m not a big fan of Turbo C, its a wonder why its so popular in India even though its so out of date. I have mingw set up on windows and also dual boot sabayon linux. I’ll set it up on both and list the steps here. This should work with Bloodshed Dev-Cpp but your mileage might vary. Continue reading Getting graphics.h to work on Windows and Linux