In this simple example of the "Internet of Things", we show you how to trigger a tweet from your mbed using an RFID tag.
For this example, we use:
To drive these hardware components and to talk to twitter, we use the following libraries:
Here is the setup we are going to use:

First of all, plug your mbed into the breadboard. Connect the ground (GND) pin with the breadboard's ground line and the USB power pin ((VU) to the power line.
RFID Reader
Ethernet Socket
The socket's pinout is valid for this part. If you are using a different one, be sure to check if the pinout is not different.
Then plug a network cable into the socket, and connect your mbed to your computer!
The basic authentication service for twitter is going down at the end of the week. To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy. Simply visit the website to setup your twitter account for this API. See: http://www.supertweet.net/about/documentation
The full program including the libraries is published here:
Here is the main code form that program for reference:
// RFID Tweeter
#include "mbed.h"
#include "ID12RFID.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"
#define TWITTER_USER "donatiengarnier"
#define TWITTER_PASSWORD "myverysecurepassword"
#define IDS_COUNT 3
const int ids_list[IDS_COUNT] = {89481809, 89481810, 89481811};
const char* names_list[IDS_COUNT] = {"Donatien", "Simon", "Dan"};
EthernetNetIf ethernet;
HTTPClient twitter;
ID12RFID rfid(p14);
DigitalOut tag_present(LED1);
DigitalOut tweet_ok(LED4);
int main() {
ethernet.setup();
twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD);
while(true) {
int id = rfid.read();
tag_present = 1;
for(int i = 0; i < IDS_COUNT; i++) {
if (ids_list[i] == id) {
HTTPMap msg;
msg["status"] = names_list[i];
msg["status"] += " just arrived home!";
HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL);
tweet_ok = !r;
}
}
tag_present = 0;
}
}
The program requires some configuration for your own setup
Compile the program and download it to your mbed. Press the reset button, and it should spring in to life!
Hopefully this can be used as an easy reference for creating all sorts of "Internet of Things" applications.
HTTPClient,
ID12,
internetofthings,
RFID,
tutorial,
twitter
|
5 comments
Please login to post comments.
I have a problem. My program, exactly as above (except my ID tag number inserted, and twitter credentials changed) just stops after successfully detecting the tag. Examining the progress in a terminal window, I have an IP address OK (I have verified full Ethernet is OK using another program), the LED1 lights when the tag is presented, but I can get no further. I have added a printf just below the HTTPResult and it never gets there, so I asssume it's getting stuck here for some reason. Has anyone else had problems? Cheers