Professional Documents
Culture Documents
of Contents
Cover 1.1
Introduction 1.2
Hardware 1.3
Microcontroller 1.3.1
Firmware 1.4
Toolchain 1.4.1
Tools 1.4.2
Development Platform 1.5
Arduino 1.5.1
Arduino Cloud 1.5.1.1
PlatformIO 1.5.2
Setup 1.5.2.1
Led 1.5.2.2
Mqtt 1.5.2.3
Blynk 1.5.2.4
Structure IoT Development Platform 1.5.3
Python 1.5.4
x86 1.5.4.1
Esp8266 1.5.4.2
Espressif 1.5.5
NodeMCU 1.5.6
Libraries 1.6
Projects 1.7
WiFi 1.7.1
Mqtt 1.7.2
Adafruit 1.7.3
WebServer 1.7.4
1
IBM Watson IoT 1.7.5
Sandbox 1.8
2
Cover
ESP8266
3
Introduction
Introduction
ESP8266
The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP stack and microcontroller
capability produced by Shanghai-based Chinese manufacturer, Espressif.
Wikipedia
ESP8266 Wiki
ESP8266 Wiki
ESP8266 Wiki Toolchain
4
Hardware
Hardware
ESP8266 Module Family
5
Microcontroller
Microcontroller
Espressif 8266
ESP8266EX is among the most integrated Wi-Fi chips in the industry.
Measuring just 5mm x 5mm, ESP8266EX requires minimal external circuitry
and integrates a 32-bit Tensilica MCU, standard digital peripheral interfaces,
antenna switches, RF balun, power amplifier, low noise receive amplifier,
filters and power management modules - all in one small package. Homepage
Low-power, highly-integrated Wi-Fi solution A minimal of 7 external
components Wide temperature range: -40C to +125C ESP8285 - ESP8266
embeded with 8 Mbit flash
Resources
6
Microcontroller
7
Firmware
Firmware
You customize your NodeMCU firmware and we build it. Just for you.
NodeMCU Custom Builds Lua based interactive firmware for mcu like
esp8266
8
Toolchain
Toolchain
Esp8266 SDK
Building the toolchain
Github
9
Toolchain
$ make clean
$ git pull
$ git submodule sync
$ git submodule update
10
Tools
Tools
ESP Tool
A cute Python utility to communicate with the ROM bootloader in Espressif
ESP8266. It is intended to be a simple, platform independent, open source
replacement for XTCOM.
Github
xe1gyq@jessie:~$ cd esptool/
xe1gyq@jessie:~/esptool$ ls
esptool.py LICENSE MANIFEST.in README.md setup.py
xe1gyq@jessie:~/esptool$
11
Tools
12
Tools
13
Tools
Connecting...
Erasing flash...
Took 1.64s to erase flash block
Wrote 477184 bytes at 0x00002000 in 46.1 seconds (82.8 kbit/s)..
.
Leaving...
Node-MCU Firmware
lua based interactive firmware for mcu like esp8266 http://nodemcu.com
https://github.com/nodemcu/nodemcu-firmware
https://github.com/nodemcu/nodemcu-firmware/releases/tag/0.9.6-
dev_20150704
https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide
14
Tools
http://hanneslehmann.github.io/2015/01/ESP8266Module_LUA/
15
Development Platform
Development Platform
Linux
1 Serial Connection
Port: /dev/ttyUSB0
Upload Speed: 115200
16
Development Platform
17
Arduino
Arduino IDE
Getting Started with Arduino
Unofficial list of 3rd party boards support urls
Generic ESP8266 modules
Olimex MOD-WIFI-ESP8266
NodeMCU 0.9 (ESP-12)
NodeMCU 1.0 (ESP-12E)
Adafruit HUZZAH ESP8266 (ESP-12)
SparkFun Thing
SweetPea ESP-210
WeMos D1
WeMos D1 mini
Setup Steps
1. File > Preferences > Additional Boards Manager URLs
http://arduino.esp8266.com/stable/package_esp8266com_index.json
2. Tools > Board > Board Manager
Linux Configuration
18
Arduino
Board Info
19
Arduino
20
Arduino Cloud
Arduino Cloud
A simple tool to connect your Arduino boards to the internet and to each other.
In order to use the tool you'll need to configure your environment. Arduino
Cloud
21
PlatformIO
PlatformIO
PlatformIO is an open source ecosystem for IoT development with cross
platform build system, library manager and full support for Espressif
(ESP8266) development. It works on the popular host OS: Mac OS X,
Windows, Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone,
CubieBoard).
PlatformIO Documentation
22
Setup
Setup
Documentation
This book contains the whole documentation for GitBook and gitbook.io.
Platform IO IDE
PlatformIo-Udev
23
Setup
24
Setup
PlatformIO Libraries
25
Setup
Options:
-h, --help Show this message and exit.
Commands:
install Install library
list List installed libraries
register Register new library
search Search for library
show Show details about installed library
uninstall Uninstall libraries
update Update installed libraries
26
Setup
27
Setup
28
Setup
29
Setup
30
Led
Led
Code Writing
#include "Arduino.h"
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
Code Execution
31
Led
32
Mqtt
Mqtt
Code Writing
/*
Basic ESP8266 MQTT example
This sketch demonstrates the capabilities of the pubsub library
in combination
with the ESP8266 board/library.
33
Mqtt
*/
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LE
D pin as an output
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void setup_wifi() {
delay(10);
34
Mqtt
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
35
Mqtt
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic", "hello world");
// ... and resubscribe
client.subscribe("inTopic");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
Code Execution
36
Mqtt
37
Blynk
Blynk
Create an app for any connected project or product based on Arduino,
Raspberry Pi, ESP8266, SparkFun, and other hardware.
Blynk Homepage
Blynk Getting Started
Blynk Community
Library Installation
Code Writing
38
Blynk
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "INFINITUMfjph", "1c3889dfdb");
}
void loop()
{
Blynk.run();
}
Code Execution
39
Blynk
40
Structure IoT Development Platform
PlatformIO Library
Welcome
Welcome
Applications
Create Application
Name: MyNodeMCU
41
Structure IoT Development Platform
New Application
42
Python
MicroPython
MicroPython - a lean and efficient Python implementation for microcontrollers
and constrained systems MicroPython Github
user@host:~$ ls
ACKNOWLEDGEMENTS docs lib pic16bit teensy zep
hyr
bare-arm drivers LICENSE py tests
cc3200 esp8266 logo qemu-arm tools
CODECONVENTIONS.md examples minimal README.md unix
CONTRIBUTING.md extmod mpy-cross stmhal windows
43
x86
user@host:~$ cd micropython/unix
user@host:~$ ./micropython
>>>
MicroPython v1.8.7-781-g299c0a39 on 2017-05-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> print("hi")
hi
>>>
44
Esp8266
user@host:~$ cd micropython/esp8266
user@host:~$ make
...
LINK build/firmware.elf
text data bss dec hex filename
572052 1096 64360 637508 9ba44 build/fir
mware.elf
Create build/firmware-combined.bin
esptool.py v1.2
('flash ', 36256)
('padding ', 608)
('irom0text', 536940)
('total ', 573804)
('md5 ', '9c0e81ca947e91beae3e3b7cec9df97f')
user@host:~$ cd unix/
user@host:~$ make axtls
45
Esp8266
Leaving...
user@host:~$ su
password
root@host:~# minicom -D /dev/ttyUSB0
<reset>
46
Esp8266
47
Esp8266
>>> wlan.ifconfig()
('192.168.1.71', '255.255.255.0', '192.168.1.254', '8.8.8.8')
>>>
48
Esp8266
49
Espressif
Espressif
Espressifs SDKs
Espressif Github
Tutorial for Beginners
50
NodeMCU
NodeMCU
NodeMCU is an eLua based firmware for the ESP8266 WiFi SOC from
Espressif. The NodeMCU firmware is a companion project to the popular
NodeMCU dev kits, ready-made open source development boards with
ESP8266-12E chips. Documentation
NodeMCU is an open source IoT platform. It uses the Lua scripting language.
It is based on the eLua project, and built on the ESP8266 SDK 1.4. It uses
many open source projects, such as lua-cjson, and spiffs. It includes firmware
which runs on the ESP8266 Wi-Fi SoC, and hardware which is based on the
ESP-12 module. Wikipedia
NodeMCU Github
Lua based interactive firmware for mcu like esp8266
NodeMCU Home Page
NodeMCU github Page
Getting Started with ESP8266 WiFi Transceiver (Review)
ESP8266 core for Arduino
Lua
51
NodeMCU
ESPlorer
ESPlorer
52
Libraries
Libraries
Arest
The aREST framework is a complete solution to build powerful RESTful
applications based on the Arduino & the Raspberry Pi platforms. It can handle
all kind of communications via Serial, WiFi, Ethernet, and much more. It
includes libraries for boards themselves, like Arduino boards, and also server-
side code to handle the communications between a server and remote
devices. The aREST framework is of course completely open-source and free
to use. Homepage
53
Projects
Projects
54
WiFi
WiFi
Taken from Sabas1080 Github
Search
/*
*MASLOW: an Open WiFi Detector with ESP8266
*based in Adafruit https://learn.adafruit.com/wifi-hotspot-find
er-adafruit-pro-trinket-cc3000
* by Andres Sabas
* The Inventor's House Hackerspace
* 19 sept 2015
*/
#include "ESP8266WiFi.h"
void sleep_now(){
Serial.print(F("Sleeping..."));
ESP.deepSleep(sleepTimeS * 1000000);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
pinMode(BUILTIN_LED, OUTPUT);
Serial.println("Setup done");
}
void loop() {
uint8_t sec;
analogWrite(BUILTIN_LED, 10);
Serial.print(F("Scanning..."));
55
WiFi
Connect
56
WiFi
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
void setup() {
Serial.begin(115200);
delay(10);
WiFiMulti.addAP("INFINITUMfdca", "1d8856da87");
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
void loop() {
const uint16_t port = 80;
const char * host = "192.168.1.1";
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
57
WiFi
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
return;
}
Serial.println("closing connection");
client.stop();
Serial.println("wait 5 sec...");
delay(5000);
}
58
Mqtt
Mqtt
/*
Basic ESP8266 MQTT example
*/
#include <ESP8266WiFi.h>
59
Mqtt
#include <PubSubClient.h>
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
60
Mqtt
if ((char)payload[0] == '1') {
digitalWrite(BUILTIN_LED, LOW);
} else {
digitalWrite(BUILTIN_LED, HIGH);
}
}
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
if (client.connect("ESP8266Client")) {
Serial.println("connected");
client.publish("outTopic", "hello world");
client.subscribe("inTopic");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LE
D pin as an output
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
61
Mqtt
62
Adafruit
Adafruit
63
WebServer
WebServer
Authentication
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if(WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
ESP.restart();
}
ArduinoOTA.begin();
server.on("/", [](){
if(!server.authenticate(www_username, www_password))
return server.requestAuthentication();
server.send(200, "text/plain", "Login OK");
});
server.begin();
Serial.print("Open http://");
64
WebServer
Serial.print(WiFi.localIP());
Serial.println("/ in your browser to see it working");
}
void loop() {
ArduinoOTA.handle();
server.handleClient();
}
Serial
Web Browser
Username:
Password:
Login OK
HelloServer
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
ESP8266WebServer server(80);
65
WebServer
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266!");
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) +
"\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
66
WebServer
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
Serial
...
Connected to INFINITUMfjph
IP address: 192.168.1.74
MDNS responder started
HTTP server started
Web Browser
67
WebServer
68
IBM Watson IoT
69
Sandbox
Sandbox
http://www.wemos.cc/tutorial/get_started_in_nodemcu.html
ESP8266 Wiki
https://www.gitbook.com/book/smartarduino/user-manual-for-esp-12e-
devkit/details
http://www.instructables.com/id/ESP8266-HTTP-IO-Server/
Olimex IoT Firmware
https://github.com/squix78/esp8266-projects/blob/master/arduino-
ide/thingspeak-data-logger/thingspeak-data-logger.ino
http://frightanic.com/computers/build-nodemcu-firmware-for-the-esp8266/
http://www.allaboutcircuits.com/projects/guts-of-the-iot-part-1-building-
nodemcu-from-source-for-the-esp8266/
http://blog.cudmore.io/post/2016/02/13/Programming-an-arduino-with-
platformio/?
utm_content=buffere8465&utm_medium=social&utm_source=twitter.com&ut
m_campaign=buffer
http://www.esp8266.nu/index.php/ESPEasy
http://www.wemos.cc/
ESP8266
ESP-12E
http://www.esp8266.com/wiki/doku.php#getting_started
https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-
ide
https://github.com/nodemcu
http://hanneslehmann.github.io/2014/12/ESP8266Module/
https://espressif.com/products/hardware/esp8266ex/overview/
https://mcuoneclipse.com/2014/10/15/cheap-and-simple-wifi-with-esp8266-
for-the-frdm-board/
https://scargill.wordpress.com/?s=esp8266
70
Sandbox
Services
IoT platform for Makers
http://jumpwire.io/
https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_esp826
6/mqtt_esp8266.ino
ESPlorer
https://github.com/4refr0nt/ESPlorer
http://randomnerdtutorials.com/download/
MQTT
ESP8266
ESP8266 Relay Board Homepage
ESP8266 Relay Board Github
A simple connected object with NodeMCU and MQTT
71