Update Twitter with ThingTweet and Arduino + Ethernet Shield

This tutorial explains how your Arduino via an Ethernet Shield can update a Twitter status using the ThingTweet App from ThingSpeak.

Setup ThingTweet

Sign in to https://thingspeak.com/login, select Apps from the menu, and then click on ThingTweet.

Under the ThingTweet App, select “Link new Twitter account”. This will redirect you to Twitter to see if you want the app to have the ability to access your account. You can Allow or Deny the process. Once you have confirmed the right Twitter account, Twitter will send you back to ThingSpeak.

The app generates a ThingTweet API Key for you to use. If you send an HTTP POST with your ThingTweet API Key, then the message will be relayed to Twitter. All of the parameters from the Twitter API (statuses/update) are possible including geolocation.

ThingSpeak API IP Address

The Arduino + Ethernet Shield does not have DNS by default, so you need to send data using an IP address. ThingSpeak has an API address dedicated for its API.

byte server[]  = { 184, 106, 153, 149 }; // ThingSpeak IP Address: 184.106.153.149

HTTP POST to ThingTweet

Here is an example HTTP POST to update a Twitter Status via ThingTweet:

POST /apps/thingtweet/1/statuses/update HTTP/1.1
Host: api.thingspeak.com
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: (number of characters in message)api_key=(thingtweet_api_key)&status=My thing is social!

ThingTweet Arduino Sketch [Arduino 1.0+]

This Arduino sketch uses ThingTweet to update a Twitter status via an Arduino and Ethernet Shield.

Arduino_to_ThingTweet.ino

ThingTweet Arduino Sketch [Arduino 0023 or less]

This Arduino sketch uses ThingTweet to update a Twitter status via an Arduino and Ethernet Shield.

ThingTweet.pde

6 comments

  1. hi,
    when i keep trying to verify the sketch, it says client has been renamed as EthernetClient

    and when I change it to EthernetClient, it says no matching function for call to ‘EthernetClient::EthernetClient(byte [4],int)’

    Any suggestions??
    I just want this to tweet…

    • My first thought is that you are using a newer version of the Arduino IDE than when this tutorial was written. The above tutorial is for Arduino 0023 or less. We have been maintaining Arduino 1.0 on GitHub. Here is a link: https://github.com/iobridge/ThingSpeak-Arduino-Examples

      Significant changes were made to the Ethernet Client in Arduino 1.0+ – this is why the sketch is failing.

      Another tip, if the Arduino sketch ends in .pde – it is for the older IDE, and .ino is for Arduino 1.0+ IDE.

      I will update the tutorial to show another example.

  2. If I wanted the tweet sending to be controlled by an external signal, say a pushbutton, where should I insert the if statement? should I do it inside the first loop so

    if (pushbutton ==1) {
    updateTwitterStatus(“My thing is social @thingspeak”);
    }
    else

    or should I do the whole void function conditionally?

  3. I’m trying to tweet from my arduino, I wonder why this tutorial isn’t working for me.

    Arduino Uno R3 with ethernet shield, IDE 1.0.5 with code straight from your GitHub

    I’m getting this error:

    Connecting to ThingSpeak…

    HTTP/1.1 400 Bad Request
    Server: nginx/0.8.53
    Date: Tue, 08 Oct 2013 03:52:41 GMT
    Content-Type: text/html; charset=utf-8
    Transfer-Encoding: chunked
    Connection: close
    Status: 400
    Cache-Control: no-cache
    X-Rack-Cache: invalidate, pass

    1
    0
    0

    …disconnected

    What am I doing wrong? my ThingTweet API key is correct!

Leave a comment