Posting a Tweet with the ESP8266

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.
Posting a Tweet with the ESP8266

-- Rui Santos
-- Complete project details at http://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')

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.

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 http://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')

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top