-->
Page 1 of 2

Tweet Using Thingspeak API

PostPosted: Sun May 17, 2015 11:50 pm
by jconenna
I had found code for updating a twitter feed using NodeMCU and LUA to program the ESP8266 directly by github user ok1cdj, but didn't find much help with doing this in the Arduino IDE which supports programming the
ESP8266 directly. This code when flashed to the ESP8266 allows it to connect to an access point and update a twitter feed with the account linked at thingspeak.com. Maybe this will be useful for somebody, so I will just leave it here. :D

Code: Select all// Arduino IDE code for standalone ESP8266 to update a twitter account using the thingspeak.com API


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>

// create an account at thingspeak.com and link your twitter account to get your API key, replace the x's
String API = "xxxxxxxxxxxxxxxx";
             

// enter your ssid and password
const char* ssid = "xxxxxxxxxxxxxxxx";
const char* password = "*******";

// your message
String tweet = "Hello world. @esp8266";

// open client
WiFiClient client;


void setup() {
 
// connect to wifi
WiFi.begin(ssid, password);

// allow time to make connection
while (WiFi.status() != WL_CONNECTED)
    delay(500);

// if connection to thingspeak.com is successful, send your tweet!
if (client.connect("184.106.153.149", 80))
{
  client.print("GET /apps/thingtweet/1/statuses/update?key=" + API + "&status=" + tweet + " HTTP/1.1\r\n");
  client.print("Host: api.thingspeak.com\r\n");
  client.print("Accept: */*\r\n");
  client.print("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n");
  client.print("\r\n");
}

}// setup


void loop()
{
}

Re: Tweet Using Thingspeak API

PostPosted: Mon Aug 10, 2015 3:54 pm
by dmpotter
Thank you that was fun. I had to make a few subtle changes but it worked!

Re: Tweet Using Thingspeak API

PostPosted: Thu Jan 14, 2016 8:05 pm
by lsags
Thanks you! Very Helpful indeed!

Re: Tweet Using Thingspeak API

PostPosted: Fri Oct 21, 2016 10:15 am
by chiprobot
Thanks for posting... your code is directly to the point.
I could instigate a Tweet however it only tweets the first part of a message...
i.e.My twitter account displays just "Hello" instead of "Hello world. @esp8266"
It seems that the space after the Hello kills the rest of tweet.
... any Ideas on how to fool the rest of the message to TX?