Reader small image

You're reading from  ESP8266 Internet of Things Cookbook

Product typeBook
Published inApr 2017
PublisherPackt
ISBN-139781787288102
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Chapter 5. Cloud Data Monitoring

In this chapter, we will cover:

  • Internet of Things platforms for the ESP8266

  • Connecting sensors to your ESP8266 board

  • Posting the sensor data online

  • Retrieving your online data

  • Securing your online data

  • Monitoring sensor data from a cloud dashboard

  • Creating automated alerts based on the measured data

  • Monitoring several ESP8266 modules at once

  • Troubleshooting common issues with web services

Introduction


In this chapter, we will be looking at cloud data monitoring using the ESP8266. The ESP8266 is an ideal chip for IoT projects since it offers Wi-Fi connectivity as well as basic GPIO pin functionality. To demonstrate all that, we will use the ESP8266 to read sensor data and log it to and retrieve it from online servers. We will also look at other different features of IoT platforms that we can use to secure and monitor our data.

Internet of Things platforms for the ESP8266


The ESP8266 module is a very popular chip in the IoT field. As such, there are many IoT platforms that are based on it. The platforms come with different features and configurations that facilitate the use of the ESP8266 in IoT projects. This recipe is going to look at some of the available platforms and their features and functionalities.

Sparkfun ESP8266 thing

The Sparkfun ESP8266 thing is a development board designed around the ESP8266 module. It comes with an integrated FTDI USB-to-serial chip, Li-Po battery charging circuit, Wi-Fi, 512 KB flash memory, power switch, and an LED. In addition to this, it has very good documentation that guides users on how to set it up and use it.

The Sparkfun thing can be used for basic GPIO pin functions, such as reading sensors and controlling outputs such as LEDs. It can also be used to post data to online servers. Sparkfun has an online platform where you can post your data. It is http://data.sparkfun.com...

Connecting sensors to your ESP8266 board


In this recipe, we are going to look at how to connect sensors to an ESP8266 board. There are two kinds of sensors that you will be using with your ESP8266: digital sensors and analog sensors.

The digital sensors output digital signals that you can read using the ESP8266 digital GPIO pins. The digital sensor outputs have only two states: high (logic 1) and low (logic 0). The high signals are ideally at a voltage level of 3.3V, while the low signals are at a voltage level of 0V.

Analog sensors output analog signals. The output comes in various voltage levels between 0V and 3.3V. The output signal is read using the ESP8266 analog pin (labeled ADC on our board).

It is advisable not to connect the analog sensor output directly to the ESP8266 analog pin. This is because the sensor output voltage range of 0V-3.3V is greater than the input voltage range of the analog pin, which is 0V-1V. The best way to connect an analog sensor to the analog pin is via a voltage...

Posting the sensor data online


Using the ESP8266, you can log sensor data to online servers for monitoring and control purposes. In this recipe, we will be looking at how to do that. We will use an ESP8266 board to post and store sensor data on dweet.io.

Getting ready

To do this tutorial, you will need an ESP8266 board and a USB cable among several other things, which include:

The hardware setup will resemble the one in the previous recipe.

In addition to setting up the hardware, you will set up the online platform where the sensor data will be posted. Luckily the platform we are using, dweet.io, is simple to use and requires no setup or signup. All you need to do is choose a name for your thing, which in this case is your ESP8266, then you can start publishing data to dweet.io.

How to do it…

Posting data to dweet.io is simple...

Retrieving your online data


The ESP8266 can be used to retrieve data from online servers so long as it is connected to the Internet. To demonstrate how to do that, we will use our ESP8266 module to retrieve the most recent sensor data that was posted to dweet.io, in our previous recipe. This will give you an idea of how to go about retrieving data from online sources.

Getting ready

For this recipe, you will only need your ESP8266 board and a USB cable. You can also leave your setup as it was in the second recipe in this chapter, although we won't need to read sensor input this time round.

How to do it…

Reading the most recent data from dweet.io is just as simple as posting it. All you've got to do is send an http request using the following URL: https://dweet.io/get/latest/dweet/for/my-thing-name:

  1. Replace my-thing-name with the name of your thing and you are good to go. Therefore, in our case, the URL we will use is https://dweet.io/get/latest/dweet/for/garden-monitor-11447.

  2. In addition to getting...

Securing your online data


dweet.io secures your data through a method known as locking. Locks keep your data secure by preventing access, unless a thing or a person provides a special key. In this recipe, we will look at how to set up a lock and some features that come with it. This way you will know how to secure the data you post online from your ESP8266.

Locking your things

When you lock your thing, its name cannot be used by another person. You can acquire and maintain a lock by paying a small fee of $1.99 every month. Once you pay, you are provided with a lock and a special key. Using the lock and key, you can secure your things and prevent other people/things from accessing your data on dweet.io.

When you pay for a lock, you receive your lock ID and a unique key in your e-mail account. You can then lock your things through the web API by calling this URL:

https://dweet.io/lock/{thing_name}?lock={your_lock}&key={your_key}

If your thing is locked successfully, you will receive this...

Monitoring sensor data from a cloud dashboard


In this recipe, we will be looking at how to use a graphical interface to monitor the data logged by the ESP8266. One of the main reasons why sensor data is posted online is so that you can easily monitor the data over time. This is facilitated by cloud dashboards that take the posted data and convert it to meaningful graphical presentations. The graphical presentations guide us in the decisions and actions we take pertaining to the system that is being monitored. We will use dweet.io and freeboard.io to demonstrate how cloud dashboards work.

Getting ready

Set up the hardware the same way you did in the, Connecting sensors to your ESP8266 board ercipe and upload the code for posting sensor data to dweet.io.

Note

That is the code we used in the, Posting the sensor data online recipe.

No configuration will be required in dweet.io for you to get a graphical view of the posted data. On the other hand, you will need to set up a few things in freeboard...

Creating automated alerts based on the measured data


In this recipe, we will be looking at how to create alerts based on the data you logged online. Alerts are available for locked dweets. They send notifications to you when the posted data exceeds a certain limit. This is an important feature for real-time monitoring. To demonstrate this, we will create an alert to inform us when the temperature exceeds 25 degrees Celsius.

Getting ready

You will need an ESP8266 board, a USB cable, and several other hardware components:

Set up the hardware as we did in the, Connecting sensors to your ESP8266 board recipe:

We will still use same thing name, garden-monitor-11447, when posting data online. However, you may need to use another thing name just in case the one suggested earlier is locked. If that is the case, remember to use your...

Monitoring several ESP8266 modules at once


In advanced and more complex monitoring solutions, you will have to use several ESP8266 modules. This may be due to the distance between the areas where parameters are being monitored, or when the sensors being read are more than the number of GPIO pins available on an ESP8266 module. In such cases, you will have to monitor data from more than one ESP8266 module on the same dashboard. To demonstrate how to do that, we will use one ESP8266 board to monitor temperature and humidity with the DHT11 sensor, and another ESP8266 board to monitor soil moisture. Data from both ESP8266 boards will be monitored using one dashboard.

Getting ready

You will need these hardware components:

Start by mounting the ESP8266 board and the DHT11 sensor onto the breadboard...

Troubleshooting common issues with web services


In this recipe, we will discuss some of the problems you may run into and how to troubleshoot and solve them.

The board is not connecting to the Wi-Fi network

This usually happens if the Wi-Fi ssid and password provided in the code do not match those of the Wi-Fi network that the ESP8266 is supposed to connect to. You can solve this by providing the correct credentials in your code.

The lock feature on dweet is not working

The lock feature fails to work if the lock is already being used on another thing. On the other hand, it can fail if the lock ID and key are not entered correctly. Therefore, first check you have entered the correct lock ID and the correct key. If they are already correct, check whether the lock is being used on another thing. If another thing is using the lock, just unlock it using this URL: https://dweet.io/unlock/{thing_name}?key={your_key}

If you are not sure of the name of the other locked thing, call this URL so that you...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
ESP8266 Internet of Things Cookbook
Published in: Apr 2017Publisher: PacktISBN-13: 9781787288102
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz