Adding Wi-Fi to our
Why Add Wi-Fi?
● Having network connectivity is good for any
computing system. It opens plenty of new
possibilities and adds to a systems utility.
● Can fetch data from anywhere in the WWW.
● Can push data to cloud or any specific server for
storage, computation or monitoring.
● We need a piece of external hardware that can
convert the Wi-Fi data into a data format
understood by common micro-controller, example
UART, SPI, I2C etc.
● The external hardware must have all the network
protocol stack, RF front ends, Encryption-
Decryption algorithm built into it.
● Plenty are there.
● Almost every SoC manufacturer have their own
● We will talk about the one which is easily
available, lowest cost, easy to use, supported by
community of users.
● $5 Micro-controller with Wi-Fi capability.
● Can be programmed just like any other MCU, it has GPIO,
SPI, I2C, UART, I2S.
● It has 802.11 b/g/n.
● Integrated TCP/IP Protocol stack. MAC/ Baseband Processor.
● Integrated TR Switch, Balun, LNA, Power Amplifier,
● Integrated PLL, regulator, DCXO, PMU.
DCXO – digitally controlled Oscillator, PMU – Power management unit
● Designed and distributed by a fab-less Chinese
company named Espressif Systems.
● Comes in a QFN-32 package, smaller than a
● Supported by a large user community online.
● Various breakout modules are available in market
at a cost as low as Rs. 300.
● We will be using ESP-01 Module.
RXD Receive Data
Vcc 3V3, DO NOT Connect 5V
GPIO0 Also, used to enter into Flash Mode, Active Low
GPIO 2 General Purpose I/O
CH_PD Chip Enable, Active High
TXD Transmit Data
There are many other commands for every other task ESP8266 can perform.
Remembering so many AT commands with all the correct parameter is hardly possible,
we need a more familiar system like C Language, Arduino Sketch or Any other easy to
write and read script.
NodeMCU and LUA Script
● ESP8266 is made to understand its AT Commands.
● For larger programs AT commands based program
becomes complex to read and write.
● NodeMCU is a very useful ESP8266 firmware.
● Allows writing of easy to understand LUA scripts
for ESP8266 applications.
Which is easy to remember?
wifi.setmode(wifi.STATION) AT+CWMODE = 1 [1 Indicates STATION]
LUA Script Style AT Commands
Using LUA is easy for application programmer for larger more complex programs.
How to flash Node MCU firmware to
● Use this sofware utility -“ESP8266 Flasher”
LUA Script for Web Client
4 tmr.delay(100000000) -- wait 1,000,000 us = 1 second
7 conn=net.createConnection(net.TCP, false)
8 conn:on("receive", function(conn, pl) print(pl) end)
10 conn:send("GET / HTTP/1.1rnHost: www.nodemcu.comrn"
Once written, this script can be permanently stored in ESP8266 flash memory and
can be called to run any time using any external serial interface.
Let's say the file name is client.lua, you can call this script by sending
=dofile('client.lua') over serial interface.
Programming the Flash
● Use ESPlorer sofware. Tie GPIO0 to Ground.
● Write your LUA script and press SEND to ESP to
run the script.
● Use SAVE to ESP to permanently flash the script
● NodeMCU firmware always executes init.lua upon
reset/ power on. In'init.lua' write everything you
need to run upon start-up.
Things to learn yourself
● Blynk (blynk.cc)
● ESP8266 using Arduino IDE
● LUA script in detail.