Pages: [1]   Go Down
Author Topic: Modified Twitter Library for the Arduino WiFi Shield  (Read 3389 times)
0 Members and 1 Guest are viewing this topic.
Toronto, Canada
Offline Offline
Newbie
*
Karma: 1
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

I'm not sure if this has been done before but I've been doing some work with the newly-released Arduino WiFi shield; it doesn't have much user-generated content available for it at this time. I needed to get the Arduino to tweet over WiFi as a part of my project, and didn't want to bother getting into OAuth, so I did a simple modification of the Twitter Library already present for the Ethernet Shield to port it over. Hope it helps someone out.


Installation:

1) Install the Arduino Twitter Library at http://arduino.cc/playground/Code/TwitterLibrary
2) Overwrite the Twitter.h and Twitter.cpp files within the newly installed library with the attached files.
3) Enjoy.

Note that at this rudimentary stage this will make your twitter library no longer compatible with the Ethernet Shield. To restore, just re-install.


Sample code to tweet, note you will still need to grab a token as was needed with the original library.

Code:
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>
#include <Twitter.h>


char ssid[] = "Network Name";
char pass[] = "Secret Password";

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Your Token Here!");

// Message to post
char msg[] = "Automatic tweet!";

void setup()
{
  delay(1000);
  WiFi.begin(ssid, pass);
  // or you can use DHCP for automatic IP address configuration.
  // WiFi.begin(mac);
  delay(10000);
  Serial.begin(9600);
 
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}

void loop()
{
}

* Twitter.h (0.51 KB - downloaded 184 times.)
* Twitter.cpp (1.59 KB - downloaded 183 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just want to say thanks for posting this.  Just used it and it worked great!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone used this with the WiFLY Shield from Sparkfun?
Just curious.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've changed the header names to Twitter_WiFi.h and Twitter_WiFi.cpp (The files are attached.)
So you can choose to include either one of them depending on whether you're using the Ethernet or WiFi module.
Hope this makes things easier and neater.

Cheers,
Bryan

* Twitter_WiFi.zip (3.83 KB - downloaded 38 times.)
Logged

Toronto, Canada
Offline Offline
Newbie
*
Karma: 1
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I think that works out a lot better.

edit: added a github link, for anyone who wants to continue working on this snippet of code https://github.com/gauravg11/arduinolibs
« Last Edit: June 26, 2013, 02:00:20 pm by gauravg11 » Logged

Pages: [1]   Go Up
Jump to: