Pages: [1]   Go Down
Author Topic: Twitter via WiFly  (Read 1814 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I've been trying to get my arduino to tweet over wifi. I have the WiFly shield set up from sparkfun which is working, but I haven't been able to successfully send tweets over it. As far as I can tell, the twitter libraries (I've been looking at http://arduino-tweet.appspot.com/) are set up to work with the ethernet shield.

Has anyone managed to send a tweet via wifi?

Best,
Matt
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 553
Posts: 46295
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't had any use for twitter, but...

Quote
but I haven't been able to successfully send tweets over it.
Using what code? What happens?
Logged

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

I haven't been able to port the library (code doesn't compile). I'm not entirely sure I'm up to porting the twitter library to work with the WiFly library unfortunately. I was wondering if any had done it at some point and maybe never shared it online.  smiley
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 553
Posts: 46295
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It shouldn't be that difficult to port. Post the code that generates the errors, and the errors it generates.
Logged

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


Remove under two line in the your sketch and Twitter.h
-#include <Ethernet.h>
-#include <EthernetDNS.h>

and
in the Twitter.cpp, comment out below code.
    DNSError err = EthernetDNS.resolveHostName(LIB_DOMAIN, server);
    if (err != DNSSuccess) {
       return false;
    }
and you need to hardcode for "arduino-tweet.appspot.com"
-static uint8_t server[] = {0,0,0,0}; // IP address of LIB_DOMAIN
+static uint8_t server[] = {74,125,127,141}; // IP address of LIB_DOMAIN

Logged

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

All you really need to do is something like this.

Code:

#include <SPI.h>
#include <SC16IS750.h>
#include <WiFly.h>
#include "Credentials.h"


char token[] = "YOUR TOKEN HERE"; //@normbot
char msg[140];


char url[] = "arduino-tweet.appspot.com";
int hour = 3600000;

WiFlyClient client( url, 80 );

void setup() {

  Serial.begin(9600);
  SC16IS750.begin();

  WiFly.setUart(&SC16IS750);
  WiFly.begin();

  if (WiFly.join(ssid, passphrase)) {
    Serial.print("Associated with ");
    Serial.println(ssid);
  }
  else {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  } 

}

void loop() {
  Serial.print("connecting to ");
  Serial.println( url);
  String starDate( millis());
  String startOfMsg("Normbot Log: Stardate " + starDate);
  String fullMsg( startOfMsg + ". Still no sign of WD40" );
  for ( int i = 0; i < sizeof( msg ); i++ ) {
    msg[i] = '\0';
  }
  fullMsg.toCharArray( msg, fullMsg.length() + 1 );
   

  if (client.connect()) {
    Serial.println("connected");
    client.println("POST http://arduino-tweet.appspot.com/update HTTP/1.0");
    client.print("Content-Length: ");
    client.println(strlen(msg)+strlen(token)+14);
    client.println();
    client.print("token=");
    client.print(token);
    client.print("&status=");
    client.println(msg);
  }
  else {
    Serial.println("connection failed");
  }
 
  if ( client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  delay(600000);
}


It's not perfect - I cobbled the code together as a proof of concept. I will work on porting the Twitter library to WiFly when I get more time. The code above works though.
Logged

Pages: [1]   Go Up
Jump to: