sample output on console
sample irc connection code
sample led control code
sample stream setup
There was a tournament for CSGO in Boston where the audience got these white bracelets. Nobody knew what they were until a team won a round, and all of the bracelets in the arena showed that team's respective colors. More match events were showing up on the bracelets as well. At first, I got the idea to use Riot API for League of Legends to control my light bulb depending on events happening in my games, but the Riot API has a three minute delay for anti-cheating measures. My roommate gave me the idea of using Twitch API, and the most famous example of twitch commands from users in the IRC was Twitch Plays Pokemon. TPP allowed users to send commands for a game of Pokemon. This meant thousands of people would have to work together to complete the game remotely. I decided to combine both ideas and let twitch chat control my LED.
What it does
Users can send in commands in twitch chat on my channel that starts with an exclamation point "!" like so. I have hard coded five commands, !red, !green, !blue, !off, and !rainbow. I also allow an interpreted command of any six digit hex code for example: !#FF00FF for magenta/purple.
How I built it
My bulb is the Flux Wifi LED, which does not have an official API (well it does now, and it's a 3rd party reverse engineering of the mobile app the bulb comes with). This API is missing a few features from the official mobile application, but for what I need it to do it works (If remote access worked, I wouldn't be required to be on the same network as the controller, in this case, my PC running the code). Next I'm using a Twitch API wrapper for Python, which is also 3rd party official. Both are in Python and this is my first time using python on a real project.
Challenges I ran into
Originally the idea was to add the bulb onto WSU Wireless along with my laptop. Then I could connect to twitch IRC and starting reading in commands and setting my bulb on or off. The first and primary problem was that WSU Wireless does not let my code connect to twitch IRC. I don't know why, but after VPN'ing my code to my roommates server back at our apartment, it worked. So we figured out it was just a problem of WSU and we setup an Amazon server with the hackathon coupon and setup a VPN to my machine with OpenVPN. This worked, but problem two arises being that my laptop is no longer technically connected to WSU wireless. The VPN makes my machine think it's on an Ethernet connection. Luckily windows 10 has a hotspot feature that I can connect my bulb to. The bulb API can only search the Wifi port, so scanning PCs network will only show bulbs connected to the VPN also, not local hotspot. I couldn't find any indication of the hotspot port on google, so I just took the IP address of the bulb shown in my hotspot connections and hardcoded it into my project. This leaves two problems though, one the internet connection is less than perfectly stable, and two the wifi connection of the bulb will time out. If the scanning API worked the bulb would be found every time, but the hardcoded method runs into timing out, or just missing the window where the bulb is communicating with the program. This is tough because the commands coming in may or may not be at regular intervals, and may be too fast or slow for the connection window to hit. Anecdotal estimate says it'll drop connection around 1 in 8 commands.
Accomplishments that I'm proud of
I'm glad that it works as well as it does. I'm also glad I've started to seriously learn python as an alternate language, it's very useful. I'm glad I got two unofficial "official" API to work together.
What I learned
I learned things last night that I never thought I'd need to know, especially the server and VPN stuff. I also learned how to read python pretty well in the span of a few hours.
What's next for controlmyled
Docker could help keep this version of a solution running by restarting the bot whenever it crashes. This would just automate the process of what I'm already doing, restarting the code periodically. If I could do some reverse engineering and study the packets for remote network control for the LED, I could get the whole program to run on an external server. Usually twitch bots are run on servers, or bot sites.