Twitter Remote Control

Description

In this project, I created a way to remotely control different devices using twitter accounts. There are a few main components to this set-up:

  • mbed's Twitter account
  • Controlling Twitter account
  • A supertweet.net interface for your application
  • mbed's Ethernet interface
  • Devices being controlled

The purpose is to use the controlling Twitter account to tweet at the mbed's account with a predetermined syntax that the mbed can translate into commands. This serves practical purposes where you might need to set values on internet-ready household devices (like preheating your oven while you're buying supplies for dinner or changing your thermostat while you are on vacation).

/media/uploads/jlind6/lab3pic3.jpg /media/uploads/jlind6/lab3pic2.jpg

Example

In this example, I used a Nokia LCD screen with a breakout board from Sparkfun as the device I'm controlling. There are a few commands that I can send to the mbed:

  • background [color] -> You can use this command to set the background color of the LCD to 'blue', 'green', or 'red' (example: @mbedcontroller background green)
  • write [text] -> This writes text specified in the tweet to the LCD screen. You cannot use anything with quotation marks (") (example: @mbedcontroller write Hello World!)
  • square [length] -> This draws an empty square in the screen with a side length of the number included in the tweet. The size of the screen is 130 x 130, so a size of over 130 will cause an error. (example: @mbedcontroller square 20)

Any other commands will cause the screen to display an error message. The unique commands will stack on each other, but if background is set and the background command is sent again with a new value that new value will overwrite the old one on the screen.

New tweets are retrieved every 30 seconds. Multiple commands can be sent at once and will be processed in the order in which they were received.

Connections

With the example code...

mbedEthernet breakout boardLCD Display
VoutVBATT, 3.3V
GNDGND
TD+P1
TD-P2
RD+P7
RD-P8
P5DIO
P7SCK
P8CS
P9RESET

Code

In addition to the following code, a few changes have to me made to the HTTPClient library. First, the buffer for the path of the request needs to be increased so that we can make larger requests with the JSON arguments.

Second, you have to add your own authentication header in like this

  snprintf(buf, sizeof(buf), "Authorization: Basic bWJlZGNvbnRyb2xsZXI6U2MxZW5jZSEh\r\n");
  ret = send(buf);
  CHECK_CONN_ERR(ret);

where the bWJlZGNvbnRyb2xsZXI6U2MxZW5jZSEh part comes from running your username and password in the format of "username:password" through a 64-bit encoder. The officially supported library unfortunately does not include basic authentication at the moment.

The following program is the code needed to run the system.

Import programtwitterController

Control an LCD connected to your mbed with a Twitter account.

Video Example

Problems Encountered/Future Steps

  • Dealing with the authentication on supertweet.net is an issue that is solved by hard coding in the library. Ideally there would be dynamic account authentication, but that would require a 64 bit encoding library.
  • The request to pull tweets after a certain tweet was failing for a long time. The HTTPClient library was limiting the length of the path in the request, so I had to extend that in the library.


Please log in to post comments.