Category Archives: tech tips

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.

 

Smart DNS to sidestep geolocation checks

One of the HDMI ports of my TV is powered by Raspberry Pi, I use this to stream content that isn’t available in my current geography. The most obvious way to bypass geo-restrictions is to use a VPN, these are great in theory but a high performance VPN provider is hard to find and quite expensive as well.

Recently I discovered that Smart DNS is an alternative to VPNs, this is a very clever implementation, which intercepts only a small portion of the traffic that corresponds to the geolocation checks.

I tried out CactusVPN, they’re one of the rare providers that provide a truly free service. Shout out to you guys at CactusVPN, I was able to set this up easily on both my mobile devices as well as the raspberry pi, they have apps for all major platforms/oses(Windows, macOS, Android and iOS) as well as documentation for setting up DNS on linux; which is really nice! The DNS service is available for locales like US, Canada, UK, Germany, Poland and Sweden. Here’s a list of websites that can be unblocked using their services. I hope that they expand their services into other regions as well – India would be swell!

If you want more control, then you could setup your own Smart DNS server in the cloud. Netflix-Proxy looks really promising and I’m going to set it up in India to see if I can unblock Hotstar.

Do note that Smart DNS may not be the best solution for the more adventurous who use P2P, in those cases VPN may be better. But Smart DNS works great for cases where you want to access freely available content or content that you actually pay for and are traveling or are locked out due to poorly implemented checks.

Do let me know if you know of other Smart DNS providers, I’d love to take them out for a spin(specially if they have Indian endpoints)

Downgrade grub2 to grub

There was this weird issue that I’ve been facing for some time with both ubuntu 12.10 and 12.04, what happens is that my Acer Aspire One 722 netbook doesn’t boot into linux at times. The first couple of times I dismissed it as a one off but that didn’t stop the problem from recurring. Then I blamed my exotic grub2 setup wherein I had installed grub2 to /dev/sda5 and then was using the windows 7 bootloader to chainload it.
Continue reading Downgrade grub2 to grub

Keep Windows and Linux time in sync

Every time I log into windows after having used linux on my netbook there is a problem with the system time. It is because linux treats the time set in your BIOS clock to use the UTC clock, this is a problem as windows treats it to be set to your local time. If you’re using only one OS then both of these choices are acceptable design choices but when you use it becomes a problem. When I’m online it’s not a problem as both windows and linux sync their times with the internet but when offline it’s irritating to look at the clock and see a time that makes no sense.

Fortunately you can tell linux to follows the convention that windows follows, telling windows to behave like linux on the other hand is significantly harder. The best thing about linux is that it makes it’s assumptions and lets you change them to suit your preference. We need to edit this file /etc/default/rcS for ubuntu 12.10


# assume that the BIOS clock is set to UTC time (recommended)
UTC=no

By default the option is yes but we need to change it to no and from the next reboot the problem is solved!

Reliance Netconnect+ Settings for Ubuntu

I had written a post on how we can easily get MTS Mblaze to work under linux and as it turns out, the Reliance Netconnect+ is equally easy to set up and use. Instead of repeating the entire procedure which I have already mentioned here, I’ll just post the relevant wvdial configuration file. You need to add the following snippet to your /etc/wvdial.conf

[Dialer netconnect] 
New PPPD = yes 
Init1 = ATZ 
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 
Modem Type = USB Modem
Baud = 460800 
New PPPD = yes 
Modem = /dev/ttyUSB0 
ISDN = 0 
Username = 9388****** 
Password = 9388****** 
Phone = #777 
Stupid Mode = 1 

It goes without saying that you need to replace the username and password with your netconnect phone no. To connect simply type this in a terminal

sudo wvdial netconnect

Here’s what I get

 ➜  ~  sudo wvdial netconnect 
--> WvDial: Internet dialer version 1.61 
--> Initializing modem. --> Sending: ATZ OK 
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 OK 
--> Modem initialized. 
--> Sending: ATDT#777 
--> Waiting for carrier. ATDT#777 CONNECT 3100000 
--> Carrier detected.  Starting PPP immediately. 
--> Starting pppd at Mon Dec  3 15:45:39 2012 
--> Pid of pppd: 3981 
--> Using interface ppp0 
--> local  IP address 115.242.128.198 
--> remote IP address 220.224.141.145 
--> primary   DNS address 220.226.6.104 
--> secondary DNS address 220.226.100.40
 

Happy browsing with Reliance Netconnect+, I suspect that the MTS device and the Reliance device are actually identical, the only difference being the firmware. As usual let me know in the comments if this helped or if you have some clarifications.

Using the Windows 7/8 bootloader to dual boot linux

In the past whenever I had to install linux along with windows I would install grub and it works flawlessly most of the time. Sometimes however when you’re experimenting with something unusual, it is handy to know how to load linux using the windows bootloader. I used it when I was transferring my ubuntu installation from my laptop to my netbook.
Continue reading Using the Windows 7/8 bootloader to dual boot linux

gprs and wvdial over bluetooth

I must say that the network manager handles ppp connections rather poorly, sometimes they work but most of the times they don’t. The situation is worse still with mobile phones, I have a nokia series 40 mobile phone and when my mts subscription expires, I need to use it for a couple of days. I’ll walk you through the steps that allowed me to connect to the internet using my tata docomo gprs connection over bluetooth.

Continue reading gprs and wvdial over bluetooth

Fixing the keyboard on a hackintosh

I installed iAtkos L2 on my Acer 5742G laptop and it works really well, there was one thing that has been bugging me. I couldn’t press ~ on the keyboard and using the terminal was painful when it came to specifying paths relative to my home directory.

After some looking around I found this application KeyRemap4MacBook. As the name suggests it allows us to remap keys on the keyboard and assign them different functions. The problem I had was that I got § instead of the usual backquote(`). Here’s the relevant xml snippet that performs the desired conversion


<?xml version="1.0"?>
<root>
<item>
<name>Fix Tilde</name>
<identifier>private.fix_tilde</identifier>
<autogen>--KeyToKey-- KeyCode::UK_SECTION, KeyCode::BACKQUOTE</autogen>
</item>
</root>

 

The best part about this is that it’s an open source project. I didn’t know about the keycodes and had problem finding the ones that I needed, so I asked by opening an issue on github and the author took the time out to help me. I absolutely love the open source community. Hopefully this will help someone else who had a similar issue. This application can also be useful for those who have keyboards with multimedia keys that don’t work out of the box for hackintoshes.

Changing your DNS for MTS Mblaze

For the last few days, the news of Monday being the internet doomsday have been doing the rounds. But there are trivial fixes that can help you avoid meeting with that fate if your system is infected. You can change your DNS servers and you’re good to go, to put it simply DNS is the mechanism that translates the ip addresses that the computer understands from the human readable domain names.
Now the real reason that I wanted to change my DNS servers is because of the problems that I encounter with MTS’s servers, many times you can access most of the websites but inexplicably a few just wouldn’t open up at other times,  it’d show that I’m connected to the internet but no websites would open. So here is how you can use google’s public DNS with MTS.

 

The picture is worth a thousand words, after making the changes be sure to save your settings.

If you don’t like google for some reason or the other, then there are also other providers that you can use. All of you should check to see if your computer is infected with the DNS Changer virus, it should be noted that it affects only Windows and Mac OS so if you’re on linux like you should be then you’re good to go.