Vous êtes sur la page 1sur 55

Build your first Internet of Things

(IoT) service with ESPresso Lite


MakerAsia - Espert
Build your first Internet-of-Things (IoT) service
with ESPresso Lite Workshop Guide
Workshop Objectives:

• To give novice learners a broad overview of the elements of IoT;

• To allow novice learners to tinker and experiment with the ESPresso Lite quickly
and easily;

• To provide opportunities for them to consider how they can participate as a


maker,

developer, entrepreneur or instructor


Workshop Topics
A. ESPresso Lite Primer I. Arduino Basic Programing

B. Making it work

C. Building a simple sensor

D. Publishing & subscribing data

E. Visualizing the sensor data

F. Controlling an actuator

G. Conditional programming

H. Building a hot button service.


Activities
A. Connecting the ESPresso Lite to WiFi/Internet

B. Subscribing to MQTT broker

C. Visualizing the data using Freeboard.

D. Publishing a command to MQTT broker

E. Creating an IFTTT account

F. Hardcoding the IFTTT key into the ESPresso Lite

G. Build a hot button


Activities
H. Programming - Using Arduino IDE

I. How to upload program Over-The-Air

J. Arduino: Lesson 1 - Blinking an LED

K. Build a Hot Button - D.I.Y version

L. Build a Smart Plug - D.I.Y version


Introduction
The topic of Internet-of-Things (IoT) is one of the most talked about among the
tech or start-up circle as the most promising trend that potentially could lead to
big financial rewards. Big companies continue to dominate the mindshare and
sentiments of the IoT scene in various ways. For example, the Industrial 4.0 by
Bosch, big data analytics by IBM, cloud platform by Google/ Microsoft/AWS and
connected hardware by Samsung/Intel, etc.
In this workshop, we will learn to connect ‘things’ to the ‘Internet’ using the
ESPresso Lite. We will learn how to connect the ESPresso Lite to the ‘Internet’
(ESPert cloud) via Wi-Fi as well as connecting the cloud to your mobile device
a.k.a your smartphone. Next we will learn how to control and connect these
devices at the cloud level (using MQTT web socket panel) and creating a
web-service to build a simple IoT service between the ESPresso Lite and the
smartphone.
ESPresso Lite Primer
ESPresso Lite is the name of a Wi-Fi-enabled development board made by Espert
Pte Ltd. It uses ESP8266 chip as the main micro-controller and supports the
Arduino environment. This is so that beginners with no experience in software
programming or electronics can start building objects that can respond to light,
sound, touch and movement autonomously and wirelessly (‘smart’ objects)
connect them together
Why do we need ESPresso Lite?
• Low cost

• Ease of use

• Direct OLED display & sensor plug-in

• Powerful micro-controller function

• Full Wi-Fi capability (TCP/UDP stack)

• Low power consumption


Making it work
- Open the box
- Prepare to wiring them together
- Power on self test
- Config network
Connecting the ESPresso Lite to Internet using the AP mode

- Next, we need to connect the ESPresso Lite to a Wi-Fi network. This is


achieved by turning the ESPresso Lite into a (temporary) Wi-Fi access point
(AP) and configure the connection wirelessly

- First, connect the OLED display, DHT11 sensor and USB cable (yellow is GND
and pink is VIN)

- When this happens, your ESPresso Lite will be in AP mode and will display the
board id as a WiFi network name
- Look for your board’s Wi-Fi
network name.
- Click on it to connect the
ESPresso Lite to your computer
- An Internet protocol (IP)
address 192.168.4.1 will
appear in the OLED display. Key
in this number into your web
browser and run it.
- A box will appear and prompt
you to choose an appropriate
Wi-Fi network SSID and
password
- Choose SSID : IoT-Workshop
Password : espresso
Building a simple sensor
- The ESPresso Lite is specially designed to minimise wiring when building
simple sensors such as for temperature-humidity. The components can be
inserted into the appropriate headers directly

- In this workshop, an Arduino sketch/program has already been pre-loaded


into the ESPresso Lite boards. When it is connected to power source, the
ESPresso Lite will boot up (& connects to the Internet) and starts to take
sensor reading. As we cannot ‘see’ the data that is being transmitted by the
ESPresso Lite to the cloud, we will need to check the ESPert MQTT web
socket panel in our browser using
http://www.espert.io/mqtt
Publishing and subscribing data
MQTT or “message queuing telemetry transport” is a type of messaging protocol
which

- is designed for light-weight messaging


- is publish-subscribe based
- requires a message broker
Publishers
publishers (in this workshop, all the ESPresso Lite used to collect the
temperature-humidity data are the publishers), don’t send the information directly
to subscribers like in a typical HTTP. Instead, it characterize message payloads
into classes without the specific knowledge of which subscribers the messages
are sent to. In other words, they simply have to collect the data and send it to the
broker without having to worry if the data will be received by the relevant
subscribers.
subscriber
Appropriate subscribers (the owner of the ESPresso Lite that ‘publishes’ the data
in this case) will only receive messages that matches the topic indicated without
needing to know who the other publishers are. The ESPert.io cloud operates as the
broker in this system and routes the published data to the appropriate subscribers
that specify the correct topics
Subscribing to MQTT broker
- Go to http://www.espert.io/mqtt
- Click on ‘Connect’ to start connection with the Espert.io MQTT broker via
MQTT Websocket Panel
- Click ‘Add New Topic Subscription’
- A dialog box will appear where you need to use your board id to create the
topic in the format below: ESPert/XXXXXXXX/#
- Once the correct topic is entered and subscribed, a series of messages will
appear
- The message used the JSON format where readable text is used to transmit
data objects consisting of attribute-value pairs. In this instance, 3 data
objects are being received every 5 seconds:
- Temperature
- Humidity
- ESPresso Lite board id
-
- As it is not easy to read, understand and visualize the data presented in this
format, we can make the data more presentable using Freeboard.
How to Retain data
Visualizing the sensor data
- Go to http://www.espert.io/freeboard
- At ‘Datasources’, click on ‘Add’
- Select the type of datasource as “Paho MQTT”
- Key in the following details:
- Name: <Optional>
- MQTT Server: mqtt.espert.io
- Port: 8000
- Use SSL: No
- Client id: xxxxxxx(board id)
- Topic: ESPert/610692/Status
- JSON Message?: Yes
• Click Add Pane > + > Gauge
and key in ‘Temperature’.

• Click Datasource > Espert >


msg > temperature

• Set the units as ‘C’ and min


and max units as ‘0’ and ‘100’
respectively

• Once this is completed, a


temperature gauge will be
displayed.

•Repeat this method to create


a gauge for humidity too
Controlling an actuator
- Publishing a command to MQTT broker
- Besides subscribing, you can also publish a command to the MQTT broker.
For instance, to cause the LED on the ESPresso Lite to turn on and off, you
just need to key in the topic according to

topic: ESPert/xxxxxxxx/Command
Command message: {“LED”: “1” }

- When the message is published, LED will turn on.


- Another cool feature is to use your browser to control the LED:
{“LED”:0},{“LED”:1},{“LED”:2}

- Change LED to OLED you can send message to display on OLED Screen
{“OLED”:”Hello World”}

- Use bridging you can send message directly from the browser itself
www.espert.io/bridge/ESPert/xxxxxxxx/Command?LED=11&Message=LED
http://www.espert.io/bridge/ESPert/14348880/C
ommand?OLED=Hello World&Message=Button
pushed
Take a break
Conditional programming with IFTTT
- IFTTT or “If This Then That” is a free web-service that allow users to connect
other web-services together, triggered based on the conditional statement of
“if this then that”
- IFTTT can help novice IoT learner to create simple a IoT service as you can
turn everyday things into ‘smart’ objects by setting up its relationship using
simple logic such as “if the room is too hot, then turn on the airconditioning”.
- We will learn to use this service for our next task: To build a push notification
service whereby “if a button is pressed, then send a text message to your
ESPresso Lite
Creating an IFTTT account
- First, let’s begin by creating an IFTTT account at http://ifttt.com
- Create an ‘applet’ by selecting a channel for the trigger. You will be using the
Maker channel
- Connect to the Maker channel and find out what is the key (auto-generated)
for you
- Copy this key (Ctrl-C)
as we will need to use
this later
Hardcoding the IFTTT key into the ESPresso Lite
- At the MQTT web socket panel and publish the message containing

- This step essentially hardcodes the IFTTT key into the ESPresso Lite to
prevent third-party abuse of the key. The device will retain the information
even after it has been switched off
1h Build a hot button / push notification service
Let’s start to create the push notification service to ESPresso Lite board of your
friend using the conditional statement below:

If the FLASH button in the ESPresso Lite is pressed, then send a text message to
ESPresso Lite board of your friend

• Firstly make sure that you have obtained the IFTTT channel key and publish the
key via the MQTT web socket panel at http://www.espert.io/mqtt
• Once these prior setup is done, you can start creating your own button Applet
IFTTT
Choose a service
type “Maker”
in text box
Receive a web request
Sending notification to
Your friend’s board
Press the button
Once this action is created, you can proceed to test out your first IoT service. If it
works, congratulations! If it doesn’t, continue to troubleshoot and identify the
steps you may have missed out.
PROGRAM WITH ARDUINO IDE
1. Download the Arduino IDE
2. Install the Arduino core for ESP8266 (WROOM-02)
3. Install dependency for ESPresso Lite V2.0 board
Download the Arduino IDE
- The Arduino IDE can be downloaded from
https://www.arduino.cc/en/Main/Software
- we recommend using earlier versions (e.g. 1.6.13)
- Install Arduino 1.8.1 https://www.arduino.cc/en/Main/Software
- Start Arduino and open Preferences window.
Install the Arduino core for ESP8266 (WROOM-02)

1. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json
into Additional Board Manager URLs field.
2. Open Board Manager from Tools > Board > Board Manager and then install
esp8266 by ESP8266 Community (current version is 2.3.0*) by clicking on it.
3. From menu Tools > Board select ESPresso Lite 2.0
Install dependency for ESPresso Lite V2.0 board
Open Library Manager (menu Sketch > Include Library > Manage Libraries…) then
install the following libraries

1. ESPert by Jimmy (current version 1.2.6)


2. Adafruit NeoPixel by Adafruit (current version 1.0.6)
3. ArduinoJson by Benoit Blanchon (current version 5.8.3)
4. DHT sensor library by Adafruit (current version 1.3.0) -use 1.2.3 if encounter
any problems
5. ESP8266 Oled Driver for SSD1306 display by Daniel Eichborn (current version
3.2.7)
6. HttpClient by Adrian McEwen (current version 2.2.0)

7. PubSubClient by Nick O'Leary (current version 2.6.0)

When you are ready, open the Arduino IDE and try compiling some examples from
ESPert.
How to upload program Over-The-Air
1. OTA (Over the Air) update is the process of loading the firmware to ESP
module using Wi-Fi connection rather that a serial port.
2. Such functionality became extremely useful in case of limited or no physical
access to the module
3. OTA may be done using
a. Arduino IDE
b. Web Browser
c. HTTP Server
Web Browser OTA
1. web browser OTA can be useful in the following typical scenarios
2. after application deployment if loading directly from Arduino IDE is
inconvenient or not possible
3. after deployment if user is unable to expose module for OTA from external
update server
4. to provide updates after deployment to small quantity of modules when
setting an update server is not practicable
Concept
1. View compilation file by Open File > Preferences, look for “Show verbose
output during:” and check out “compilation” option
2. Start Arduino IDE and load sketch WebUpdater.ino available under File >
Examples > ESP8266HTTPUpdateServer
3. Update ssid and pass in the sketch so the module can join your Wi-Fi network
4. Upload sketch Once done open Serial Monitor and check message displayed,
that contains url for OTA update
5. Now open web browser and enter the url provided on Serial Monitor
6. Upload file new .bin

1.
Arduino: Lesson 1 - Blinking an LED
1. Open BlinkOTA.ino from resources folder
2. Compile the sketch and copy .bin path
Build a Hot Button - D.I.Y version
Build a Smart Plug - D.I.Y version
Q&A

Vous aimerez peut-être aussi