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 6. Interacting with Web Services

In this chapter, we will cover:

  • Discovering the Temboo platform

  • Tweeting data from the Arduino board

  • Posting updates on Facebook

  • Storing data on Google Drive

  • Automation with IFTTT

  • Sending push notifications

  • Sending e-mail notifications

  • Sending text message notifications

  • Troubleshooting common issues with web services

Introduction


One of the main functions of the IoT is to provide instant notifications from remotely located devices. Online dashboards are able to facilitate instant data monitoring, but are not very helpful in real-time monitoring on the go. This is because some dashboards are not compatible with phones and require an Internet connection.

It is for this reason that IoT platforms are embracing social media platforms, e-mail, and text messages, to provide instant notifications and updates from IoT devices. Most phones are configured to receive notifications when there are updates on social media platforms or when new e-mails are received. This way, people can receive instant alerts on their Internet-enabled phones. Text messages, on the other hand, are considered to be the best way to send alerts from IoT devices. This is because the alerts can be received by all types of phones without requiring an active Internet connection.

In this chapter, we will look at how to send tweets, Facebook updates...

Discovering the Temboo platform


Temboo is a fully fledged online IoT platform that links your IoT projects to numerous other online platforms for instant notifications, data logging, and control purposes. You can use Temboo with many open-source hardware IoT platforms. In this chapter, we will be looking at using Temboo with the Arduino platform, and the ESP8266. Note that Temboo is not free, but you can make several requests to the service with their free plan.

There are many functions of the Temboo platform that come in handy in IoT projects. Some of them include the following:

  • Code generation: The platform allows you to select the device and sensors you want to use and automatically generates code that you can use to achieve your desired task

  • Sensor data monitoring: You are able to monitor your sensors using graphical means and keep track of your IoT systems

  • Cloud controls: The platform provides an interface that you can use to control your actuators with just one click

Temboo has a comprehensive...

Tweeting data from the ESP8266 board


This recipe will look at how to tweet sensor data directly from the ESP8266 board. To show you how to do it, we are going to use an ESP8266 board to tweet temperature readings from the DHT11 sensor, through the Temboo platform.

Getting ready

The hardware setup will require the following components:

Mount the ESP8266 board onto the breadboard. Then connect one leg of the photocell to the 3V pin of the ESP8266 board and the other leg to the 1 kΩ resistor. Connect the 1 kΩ resistor's other leg to the GND pin of the ESP8266 board, so that the photocell and resistor make a voltage divider circuit. Then connect the junction of the photocell and resistor to the ADC pin of the ESP8266 board.

The setup will look like this:

How to do it…

Refer to the following steps:

  1. Log in to your Temboo account. The first page that you will land on will be the libraries...

Posting updates on Facebook


The ESP8266 board can post Facebook updates. With this capability, you can receive real-time data from your IoT projects wherever you are. While this sounds like a difficult task, it is actually easy when using Temboo, thanks to its Facebook Choreo. This recipe will show you how to configure the Choreo to successfully post updates on Facebook.

Getting ready

For this recipe, you will need an ESP8266 board, a USB cable, and a Temboo account. If you do not have a Temboo account, check the first recipe in this chapter to see how you can get one.

How to do it…

Refer to the following steps:

  1. Navigate to Facebook | Publishing on the libraries menu on Temboo. This will open the Facebook publishing page.

  2. Then sign up for a Facebook developer account if you do not have one already. The link is provided in the setup instructions on the publishing page.

  3. Once you have a Facebook developer account, proceed to create an app in the developer console. Use the My Apps menu at the top of...

Storing data on Google Drive


In this recipe, we will look at how to store data on Google Drive directly from an ESP8266 board. This usually comes in handy when you need to log data continuously, over a period of time, from your IoT project. The data can be stored in different formats on Google Drive. So you can store virtually any kind of data, ranging from digital sensor inputs to images. Here we will look at how to log analog sensor input to a spreadsheet on Google Drive.

Getting ready

You will need the following hardware components:

The setup will resemble the one in Tweeting data from the Arduino board in this chapter, where you used your ESP8266 board to read analog input from a Light Dependent Resistor (LDR) connected to a 10 kΩ resistor in a voltage divider circuit.

Also, you need to create a spreadsheet on Google Drive. To do that, visit https://docs.google.com/spreadsheets...

Automation with IFTTT


If This Then That (IFTTT) is an online service that allows users to create simple conditional statements called applets. The applets are triggered depending on changes made on or to other web services. For instance, you can set an IFTTT applet that sends you an e-mail if a user includes a certain hashtag in their tweets. You can also configure an applet that saves all the photos that you have been tagged in on Facebook to a cloud server such as Google Drive.

In this recipe, we will look at how to use the IFTTT online service to automate IoT projects. We will use it to publish data to different online platforms, just like Temboo. To demonstrate how to do that, we are going to publish temperature data from a DHT11 sensor to Twitter, using an ESP8266 board.

Getting ready

You will need the following hardware components:

The DHT11 pin configuration...

Sending push notifications


Using IFTTT, you can easily send push notifications to your phone from your ESP8266-based IoT project. This is possible through the Pushover service. To demonstrate this, we will get a temperature measurement from the DHT11 sensor using the ESP8266 and send push notifications to an Android phone when the temperature goes below 30 degrees Celsius.

Getting ready

You will use the same setup as in the previous recipe, which includes a DHT11 sensor connected to an ESP8266 board. Also, download the Pushover app on your phone, create an account, and provide the name of your device.

How to do it…

  1. Log in to your IFTTT account and create a new applet.

  2. Set the Maker service as your This, as you did in the previous recipe. The event name will still be temperature_low. The Maker service configuration will be as follows:

  3. Once the Maker service is fully configured, proceed to set up the That service. The service we will be using to send the push notifications is the Pushover service...

Sending e-mail notifications


In this recipe, you will learn how to send e-mail notifications from your ESP8266 board. To achieve that, we will use the e-mail service on the IFTTT platform. This way, we will receive an e-mail from the ESP8266 whenever the temperature goes down by 30 degrees Celsius.

Getting ready

You will need the following hardware components:

The setup will be the same as in Automation with IFTTT of this chapter:

Note

If you do not have an e-mail account, start by creating one on the e-mail service provider of your choice. In this recipe, we will be using a Gmail account.

How to do it…

  1. Create a new applet on IFTTT and click on this to select the service that is going to be monitored. Select the Maker service and configure it (refer back to Automation with IFTTT).

  2. Once the setup is complete, click on that to select the service whose actions are going...

Sending text message notifications


Getting text message notifications is probably the most reliable way to deliver real-time data and information. This is because the phone doesn't need an Internet connection to receive the notifications. With IFTTT, you can use your ESP8266 board to send text messages from your IoT projects to your phone. To demonstrate this, we will send text message notifications to a phone from the ESP8266, when the temperature measurement from the DHT11 sensor goes below 30 degrees Celsius.

Getting ready

You will use a hardware setup similar to the one in Automation with IFTTT. Also, you will have to set up the SMS service on IFTTT.

How to do it…

  1. Create a new applet on IFTTT and click on this to select the service that is going to be monitored. Select the Maker service and configure it (refer back to Automation with IFTTT).

    Note

    Remember to call the event temperature_low. If you change the event name, you have to also change it in the Arduino code.

  2. Once the setup is complete...

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 the ESP8266 is supposed to connect to. You can solve this by providing the correct credentials in your code.

The generate code button on Temboo returns an error when pressed the second time

Choreos, especially those of social media platforms, may return an error when they are tested more than once. This error is returned by social media platform servers because they have detected a duplicate update. To solve the issue, change the data that is being updated to the social media platform before clicking on the generate code button again.

The Temboo sketches bring up errors when I try to compile them

This happens because the Temboo library that comes with the Arduino IDE does not support...

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