Tag archieven: twitter

TinkerLicht

Verander de kleur van een lamp via Twitter

Verander de kleur van het TinkerLicht door middel van een Twitter- of Facebookbericht. Je kunt het resultaat daarna zelf bewonderen, want er wordt een foto teruggestuurd!

TinkerLicht werkt al een tijdje (sinds december 2013, toen het nog Twitmaslights heette), via Twitter. In oktober 2015 is er er ook Facebook ondersteuning bij gekomen, die nu helaas niet meer werkt.

Hoe?

Twitter

Om het TinkerLicht via Twitter te besturen, verzend je een tweet met daarin de hashtag #tinkerlicht gevolgd door een dubbele punt en een kleur. Gebruik geen spaties. Een compleet overzicht van alle 140 toegestane kleurnamen vind je hier: List of colors.

140 verschillende kleuren niet genoeg? Je kunt ook een RGB code (6 hexadecimale cijfers) in je bericht vermelden.

Kun je niet kiezen? Met het woord random wordt er een willekeurige kleur gekozen.

Als alles goed gaat, wordt er na ongeveer een halve minuut een foto van de lamp met de door jou ingestelde kleur op de TinkerLicht Facebook pagina geplaatst. Je account moet niet afgeschermd (privé) zijn, want anders wordt je Tweet niet gevonden.

Facebook

De mogelijkheid om TinkerLicht via Facebook te besturen is momenteel voor onbepaalde tijd uitgeschakeld.

Omdat Facebook gebruikers "anders" zijn dan Twitter gebruikers (ik druk me voorzichtig uit), werkt het via Facebook ook anders. En er is minder mogelijk.

Bezoek de TinkerLicht Facebook pagina en plaats een bericht waarin een officiële html kleurnaam voorkomt.

Voorbeelden met kleurnamen

#tinkerlicht:blue
#tinkerlicht:yellow
#tinkerlicht:seagreen
#tinkerlicht:papayawhip

Voorbeeld van een tweet:

Dit is dan het resultaat:


Een compleet overzicht van alle 140 toegstane kleurnamen vind je hier: List of colors

Voorbeelden met kleurcodes

140 verschillende kleuren niet genoeg? Je kunt ook een RGB code (6 hexadecimale cijfers) gebruiken.

#tinkerlicht:FF00FF
#tinkerlicht:8040A0
#tinkerlicht:4F95C1
#tinkerlicht:C268BC

Kleurverloop

Het is nu ook mogelijk een kleurverloop van twee kleuren te kiezen. Zet dan een koppelteken tussen de tweet kleuren.

#tinkerlicht:red-green
#tinkerlicht:8040A0-FFFF20
#tinkerlicht:orange-F6DA12

Willekeurige kleur

Kun je niet kiezen? Gebruik dan random om een willekeurige kleur te selecteren.

#tinkerlicht:random
#tinkerlicht:random-green
#tinkerlicht:random-random

Scream

Elke reply van @TinkerLicht begint met een leuke uitroep. Wil je dat er alleen een uitroep wordt getweet? Gebruik dan

#tinkerlicht:scream

Behind the scenes

En dit is de TinkerLicht opstelling IRL:

2015-04-26 21.11.18

Een bijdrage leveren

De complete broncode, waaronder de lijst van "screams" waaruit willekeurig wordt gekozen, kun je op GitHub bekijken.

Waarom eigenlijk?

Hierom dus!

 

Share Button

Twitmaslights: gebruik een Arduino Yún om de kleur een led strip via Twitter te veranderen

English version

Nadat het me gelukt was om een led strip met een Arduino Uno en een Wifi schield via Twitter te besturen, wilde ik ook een webcam toevoegen, zodat de Arduino met een foto van de lampjes met de nieuwe kleur terug kan tweeten. Voor dat doel heb ik een  Arduino Yún gekocht.  Net als de andere Arduino's heeft deze ook een ATmega processor. Maar het speciale van de  Yún is that deze ook over een Atheros AR9331 processor beschikt. En daar draait Linux op! Dit bord heeft onder andere wifi, een USB-A poort, een micro-SD kaart slot, digitale input/output pins en een micro USB aansluitiing, die ik allemaal voor dit project nodig heb.

Wat het doet

Elke 30 seconden wordt op Twitter gezocht naar de meest recente openbare tweet met de hashtag #twitmaslights, gevolgd door een dubbele punt en een kleur. Deze kleur kan in hexadecimale notatie zijn gegeven of als een van de 140 officiële html kleurnamen. Wanneer er een tweet wordt gevonden, wordt de tekst na "#twitmaslights:" geparsed en gecontroleerd op een geldige kleurcode of kleurnaam. Als dat lukt, veranderen de kleuren van de led strip en neemt de camera een foto. Die foto wordt aan een reply toegevoegd van @twitmaslights, aan degene die de #twitmaslights tweet verstuurde. Op die manier ben ik tenminste niet de enige die van de kerstverlichting in mijn woonkamer kan genieten. 🙂

Twitmaslights gear

Hoe het werkt - of eigenlijk: hoe het dat niet doet

Het heeft een tijdje geduurd voordat ik doorhad hoe de twee "kanten" - de ATmega (Arduino) en de Atheros (Linux) - moesten worden gebruikt om met elkaar te communiceren. Met de Bridge library kun je dat op verschillende manieren doen, maar hoe, wat, waar, wanneer en waarom was me in het begin niet zo duidelijk.

In eerste instantie gebruikte ik de ATmega om al het zware werk te verrichten, inclusief het zoeken naar tweets, parsen, controleren op geldige kleurcodes en het tweeten van updates. Omdat er hierbij veel bewerkingen met strings (tekst) nodig zijn, bleek de kleine hoeveelheid RAM geheugen (slechts 2,5 KB!) van de Arduino microcontroller al snel niet toereikend te zijn. En ik had op dat moment de camera nog niet eens aangesloten!

Ik maakte ook gebruik van Temboo, een erg slimme en gemakkelijke manier om een Yún te verbinden met verschillende online services (Twitter, Facebook, Google+, Paypal, Instagram, FourSquare... noem maar op!) Hier was ik erg van onder de indruk, totdat ik er achter kwam dat een gebruiker maar een beperkte hoeveelheid (1000 per maand) api verzoeken krijgt. Als je meer wilt, moet je betalen voor een uitgebreid plan. Een ander nadeel van Temboo is het geheugengebruik: in mijn geval snoept het nog eens minstens 10% van het programmeerbaar geheugen af en vertoont onvoorspelbaar gedrag als er nog maar weinig RAM aan de Arduino kant overblijft. Aan de andere kant verdient Temboo wel een groot compliment voor hun support: ze namen zelf het initiatief om contact met me op te nemen toen ze merkten dat ik problemen had met het versturen van tweets vanaf de Yún.

Twitmaslights: purple

Hoe het uiteindelijk wel werkt

Ik bedacht me toen (waarom had ik dat niet eerder gedaan?!) dat ik de Linux kant van de Yún moest gebruiken om al het zware werk te verrichten. Je kunt je eigen Python scripts schrijven, ze op een micro SD kaart opslaan en ze uitvoeren vanaf de Arduino kant. Ook is het eenvoudig om gegevens van de ene naar de andere kant te sturen. Als je eenmaal doorhebt hoe dat werkt, snapt hoe je extra Python modules op de juiste manier kunt installeren, deze methode gebruikt om Twython te installeren en deze aanwijzingen gebruikt om een webcam aan de praat te krijgen, wordt het tweeten van een foto zelfs eenvoudiger en krachtiger dan wanneer je dat met Temboo had gedaan!

 

Share Button

Twitmaslights: use an Arduino Yún to control colored led lights with Twitter

Nederlandstalige versie

After I successfully managed to control a LED strip via Twitter with an Arduino Uno and a Wifi Shield, I wanted to add a webcam, so the Arduino could reply with a picture of the newly colored lights. For this purpose, I bought an Arduino Yún. Like other Arduino devices it has an ATmega processor. But the the thing that is special about the Yún is that it also has an Atheros AR9331 processor, which supports Linux! And among other features, the board has wifi, a USB-A port, a micro-SD card slot, digital input/output pins and a micro USB connection, all of which I need for this project.

What it does

Every 30 seconds, Twitter is searched for the latest public tweet which contains the hashtag "#twitmaslights:", followed by a color. This color can be given in hexadecimal notation, or as one of the 140 official html color names. When a new tweet is encountered, the text after "#twitmaslights:" is parsed and checked for a valid color code or name. When this succeeds, the colors of the LED strip change and the webcam takes a picture. This picture is added to a reply from @twitmaslights to whoever posted the #twitmaslights tweet, so at least I'm not the only one who gets some satisfaction from the Christmas lights in my living room 🙂

Twitmaslights gear

How it works - or rather: how it doesn't

It took me some time to understand the way the two "sides" - the ATmega (Arduino) and the Atheros (Linux) - had to be used to communicate. The Bridge library offers various methods to do this, but what, where, how, when and why wasn't very clear to me in the beginning.

At first, I used the ATmega to do all the heavy work, including searching for tweets, parsing, checking for valid color codes and tweeting updates. Because there are many string (text) operations involved with this, the little RAM memory (only 2.5 KB!) of the Arduino microcontroller soon turned out not to be enough. And that was at the point I didn't even connect the camera yet!

I also used Temboo, which offers a very inventive and easy way to connect a Yún to many different online services (Twitter, Facebook, Google+, Paypal, Instagram, FourSquare... you name it!) I was very impressed with this, until I found out that a user has only a limited amount (1000 a month) of api requests. If you want more, you'll have to pay for an extended plan. Another drawback of Temboo is its memory usage. In my case it ate up at least another 10% of program memory and showed unpredictive behaviour when I ran out of RAM on the Arduino side. On the other hand, a big pro for Temboo is their support: they actively took the initiative to contact me when they noticed I was having trouble sending tweets from the Yún.

Twitmaslights: purple

How to really get it to work

I figured out (why hadn't I done that before?!) that I had to use Linux side of the Yún to do all the heavy work. You can write your own Python scripts, save them on a micro SD card and call them from the Arduino side. It's also easy to send data from one side to another. If you know how this works, know how to install additional Python modules the right way, use that method to install Twython and use this guide to succesfully connect a webcam, tweeting an image even becomes easier and more powerful than using Temboo!


 

Share Button

How to hack a doorbell and connect it to Twitter - Part 7: Adding it all together

After combining the sender, receiver and both Twitter sketches (and making some adjustments), I now present to you... the final result.

IMG_20130718_142140

The following sketch

  • checks for tweets with a specific hashtag every 40 seconds. When it finds one, it makes the doorbell ring and posts the screen name of the tweep as a new tweet;
  • posts a tweet when someone pushes the doorbell button.

To avoid posting a duplicate tweet (which isn't allowed by Twitter), the program appends a timestamp to each tweet.

Lees verder How to hack a doorbell and connect it to Twitter - Part 7: Adding it all together

Share Button

How to hack a doorbell and connect it to Twitter - Part 6: Using an Arduino to search on Twitter

Besides detecting the signal with the "sniffer" sketch, this part took me the most time to figure out. It turns out that Twitter just recently decided that you can't use a HTTP GET command of the REST API v1.0 anymore. Developers must now use v1.1, which means you have to use OAuth even if you want to search for tweets. Since just recently, Twitter offers applications the ability to issue authenticated requests on behalf of the application itself (as opposed to on behalf of a specific user). This is called Application-only authentication, but the drawback of this is that you have to connect to the Twitter servers through SSL. Unfortunately, an Arduino isn't capable of doing this because it hasn't enough recources to do so.

Lees verder How to hack a doorbell and connect it to Twitter - Part 6: Using an Arduino to search on Twitter

Share Button