connect an esp8266 to the internet
TRANSCRIPT
Connect an ESP8266 to the Internet with
thethings.iO
thethings.iO is the Internet of Things platform that enables fast and scalable connection of things to the Internet, allowing you to monitor and manage your
devices in real time and get flexible analytic reports.
What’s thethings.iO?
We are going to test the esp8266 with a simple example in which we can toggle a LED on and off.
We will use the firmware NodeMCU to ease the process of programming and prototyping the board.
STEP 1: Get NodeMCU
1. Send it to your email
web: http://frightanic.com/nodemcu-custom-build/
* Make sure it has the following modules included: node, file, GPIO, WiFi, net,
timer and MQTT.
STEP 2: Setup the board to flash the firmware
1- Wire GPIO0 and ground to LOW on the FTDI. 2- Wire chip enable and VCC to VCC on the
FTDI.
3- Wire the TX and RX on the board to the FTDI. Connect the USB to your PC.
STEP 3: Flash the firmware
1- Check the port of the FTDI in /dev/tty(USB|ACM|S)* 2- Use the esptool utility to flash it (https://
github.com/themadinventor/esptool)
$ esptool.py --port /dev/ttyUSB0 write_flash 0x00000 nodemcu.bin
STEP 4: Setup the board to upload the Lua script
1- Wire the GPIO0. 2- Wire a LED and resistor to GPIO2
and ground.
STEP 5: Upload the script
1- Clone the esp8266 repository from https://github.com/theThings/esp8266.
2- Edit the led lua file and change the ssid, password and token variables to suit
your needs.
3- Load the script using luatool: $ luatool.py -sdr -f mqtt/lua/led.lua -t init.lua -p /
dev/ttyUSB0
4- Restart the board.
STEP 6: Testing
Use curl to send the value you want the LED to be: $ curl -H "Content-Type: application/json" -X POST "https://api.thethings.io/v2/
things/TOKEN" -d “{\"values\":[{\"key\":\"LED\",\"value\":\"ON\"}]}"
$ curl -H "Content-Type: application/json" -X POST "https://api.thethings.io/v2/things/TOKEN" -d "{\"values\":[{\"key\":\"LED\",\"value\":
\"OFF\"}]}"