Posting a Tweet with the ESP8266

In this project you’re going to post a Tweet with an ESP8266. The goal of this project is to show the endless possibilities that this $4 WiFi module offers when integrates with a free platform that I’m about to show you.

In order to accomplish this task you have to sign up for one free service called IFTTT which stands for “If This Then That”.

IFTTT is a platform that gives you creative control over dozens of products and apps.

You can make apps work together. For example when you send a request to IFTTT, it triggers a recipe that sends you an email alert.

Before continue reading this project, please complete the following tutorials:

If you like the ESP and you want to do more projects you can read my eBook Home Automation using ESP8266 hereLet’s get started!

Creating Your IFTTT Account

Creating an account on IFTTT is free!

Go the official site: https://ifttt.com/ and click the “Sign Up” button in the top of the page.

Complete the form with your personal information (see Figure below) and create your account.

signup

After creating your account, follow their getting started tutorial.

Open the Applet

I’ve created an Applet that integrates perfectly in this project and you can also use it.

If you’re logged in at IFTTT and you open this URL below to use my Applet instantly:

Press the “Turn on” button:

Next, you need to grant access permissions to Maker Webhooks and Twitter. Let your IFTTT account connect to your Twitter account. A new page loads when you finish connecting your Twitter.

Complete the Applet

Fill the Applet with your own information. Follow these instructions:

  1. Type “post_tweet” in your event name
  2. Edit the text that you want to your ESP8266 to send out as a Tweet
  3. Press the “Save” button

Now, go to this URL: https://ifttt.com/maker_webhooks and open the “Settings” tab.

Copy you secret key to a safe place (you’ll need them later in this project). In my example my secret key is: b6eDdHYblEv2Sy32qLwe

Test Your Applet

Let’s test if your request is working properly. Replace YOUR_API_KEY from the following URL:

https://maker.ifttt.com/trigger/post_tweet/with/key/YOUR_API_KEY

With your API KEY:

https://maker.ifttt.com/trigger/post_tweet/with/key/b6eDdHYblEv2Sy32qLwe

Open your URL with your API KEY in your browser.

browser

You should see something similar to the preceding Figure. Then go to your Twitter and a new Tweet should be there!

If you like Twitter, you can follow me there @RuiSantosdotme for news related to electronics.

tweet_with_esp8266

Parts List

Here’s the hardware that you need to complete this project:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematics (3.3V FTDI Programmer)

The schematics for this project are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266 to upload some code.

ESP-Bitcoin-price_bb

Downloading ESPlorer

I recommend using the ESPlorer program created by 4refr0nt to create and save Lua files into your ESP8266.

Follow these instructions to download and install ESPlorer:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the main folder
  4. Run ESPlorer.jar. It’s a JAVA program, so you need JAVA installed on your computer
  5. Open the ESPlorer

esplorer start

Writing Your Lua Script

Don’t forget that first you need to flash your ESP with NodeMCU firmare. Copy and paste the code below into ESPlorer. Then edit line 5 with your network credentials and line 13 with your API KEY.

-- Rui Santos
-- Complete project details at https://randomnerdtutorials.com

wifi.setmode(wifi.STATION)
wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD")

-- A simple http client
conn = nil
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) end)
conn:connect(80,"maker.ifttt.com")
conn:on("connection", function(conn, payload)
conn:send("POST /trigger/post_tweet/with/key/YOUR_API_KEY HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:close()
print('Posted Tweet')

View raw code

Uploading Your Lua Script

When you open the ESPlorer you should see a window similar to the preceding Figure, follow these instructions to send commands to your ESP8266: Connect your FTDI programmer to your computer

  1. Set bad raute as 9600
  2. Select your FTDI programmer port (COM3, for example)
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Copy the your Lua script into ESPlorer

Then you simply click the button Send to ESP. And you should see a a print saying “Posted Tweet” in the ESPlorer windowEverything that you need to worry about or change is highlighted in red box in the following Figure.

esplorer_IDE

Limitations and Taking it Further

Twitter doesn’t allow you to post the same tweet over and over again. So you can use the following script (by changing line 5 with your network credentials and line 13 with your API KEY) to add parameters to your POST request.

In my example below I’m using the parameter “value1” and sending the value “True”. IFTTT supports three parameters called “value1”, “value2” and “value3” to customize your Tweets and make them unique.

-- Rui Santos
-- Complete project details at https://randomnerdtutorials.com

wifi.setmode(wifi.STATION)
wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD")

-- A simple http client
conn = nil
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) end)
conn:connect(80,"maker.ifttt.com")
conn:on("connection", function(conn, payload)
conn:send("POST /trigger/post_tweet/with/key/YOUR_API_KEY HTTP/1.1\r\n"..
  "Host: maker.ifttt.com\r\nConnection: close\r\nAccept: */*\r\nContent-Type: application/json\r\n" ..
  "Content-Length: 17\r\n\r\n{\"value1\":true}\r\n") end)
conn:close()
print('Posted Tweet')

View raw code

In your POST request make sure you set the right “Content-Length” in my case it’s “17”, but if you change the “value1” or you add more parameters to your body request the “Content-Length” also changes. If you make a request with the wrong Content-Length it will fail.

With this concept in mind you can post data from your sensors (like temperature, humidity, etc) directly to Twitter using the ESP.

Here’s the end result:

twitter_ifttt_value1

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

22 thoughts on “Posting a Tweet with the ESP8266”

  1. Now all you need is to add a button! 🙂 hackster.io/noelportugal/esp8266-ifttt-easy-button and V2 hackster.io/noelportugal/ifttt-smart-button

    I’m glad IFTTT has a Maker channel now!

    Reply
  2. Hello
    this is confirm what I read on the web about the esp8266 .

    I do not use twiter or facebook but thingspeak.com with APPS thinghttp for notification sms on my mobile phone .

    Thank you
    Jean-Claude

    Reply
    • Yes, you can use thingspeak to acomplisht that. Or you can also use ifttt to send sms to your mobile phone with the ESP8266.
      USe this recipe for example: ifttt.com/recipes/317502-esp8266-sends-message-to-android-phone

      Reply
  3. Hi Rui you know i had been straggling with the module but now that is the thing of the past thanks to your tutorials and books. Thanks man

    Reply
  4. Hi Sir Rui, can I use arduino uno as usb to serial converter (as substitute to FTDI programmer) to program the ESP8266. If yes, can you show us how. Thanks a lot!

    Reply
    • Hi Ralph,
      Yes, but keep in mind that the Arduino pins operate at 5V and the ESP pins operate at 3.3V.
      In order to establish a serial communication between your ESP and your Arduino you need to use a voltage divider or use a logic shifter.

      Reply
  5. Hi Rui,
    I just want to know if my follower is respond or re tweeted then is it possible to receive a feedback from this tweeter channel and send it to esp 8266 and maybe put some led indicator in GPIO output turnout to high?
    Please advice

    Reply
    • I apologize for the delay answering your comment.
      No I don’t think you can with IFTTT, at least I’ve taken a look and I don’t see anything like that…
      Thank you for asking!
      Rui

      Reply
  6. I want to power the ESP8266 using a battery without using any voltage regulator.

    Further I tried using voltage regulator and it switches on the the ESP8266 successfully. But, it does not posts the tweet. Same happens while sending an E-mail. But, when I power it using the FTDI breakout board, it sends the G-Mail.

    Please help.

    Reply
  7. Nice Project Though. But none of the Links in this projects are working, it says the page not found, whether IFFT Applet or Maker Channel.

    Reply
    • Hi.
      This project is a bit old and it is outdated.
      You need to create the applet.
      The trigger should be webhooks and the action should be twitter: Post a tweet.
      I’m also not sure if the code is still working.
      Regards,
      Sara

      Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.