Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By jconenna
#17717 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()
{
}
User avatar
By chiprobot
#56901 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?