NodeMCU talking to twitter via ThingSpeak
|Connecting NodeMCU to twitter:
In this blog we will see how to post a tweet from nodeMCU (Connecting NodeMCU to twitter). Making nodeMCU talking to twitter server is difficult , we will use ThingSpeak to do the heavy lifting we will simply post some thing to ThingSpeak and things speak will take care forwarding it to twitter.
First you need to login in to thingspeak.com -> Apps-> ThingTweet (you need to link you twitter account with ThingTweet and ThingTweet will give you API_KEY which we need to post data to the ThingSpeak)
You need to get a build for your nodeMCU, that includes HTTP module. you can build a custom image form here. You can follow this blog to update the ROM.
The operation itself is very simple , we will post our update to ThingTweet and ThingTweet will relay the same to twitter.
config.lua -> In this file we will store the wifi details (update your WiFi connection details in this file)
setup.lua -> This script is responsible for making the wifi connection
app.lua -> This file contains the actual application logic,Make sure you upadate API_KEY in this file
init.lua -> NodeMCU will execute this file on startup, we will use this script to bootstrap our application
You need load all this files to nodeMCU and reset the nodeMCU. The init.lua will automatically start executing.
The code is available in GitHub
I am not able to successfully send this HTTP POST ! I get a Panic message !
ESP8266 mode is: 1
MAC address is: 1a:fe:34:d4:7f:5e
IP is 192.168.1.13
====================================
Tweeting….
PANIC: unprotected error in call to Lua API (app.lua:5: attempt to index global ‘http’ (a nil value))
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
===
app.lua is as shown.
===
print(“Tweeting….”);
http.post(‘https://api.thingspeak.com/apps/thingtweet/1/statuses/update’,
‘api_key=XXXXXXXXXXX&status=Hello From nodeMCU’,
function(code, data)
if (code < 0) then
print("HTTP request failed")
print(code)
else
print("Responce came1")
print(code, data)
end
end)
Hi,
Http module may not be present in your current firmware, PLease note you need a build that include http module.You
can generate a build using http://nodemcu-build.com/
you can install new firmware by following
http://icircuit.net/setting-up-node-mcu/743