Schwartz | ESP8266 Internet of Things Cookbook | E-Book | sack.de
E-Book

E-Book, Englisch, 268 Seiten

Schwartz ESP8266 Internet of Things Cookbook


1. Auflage 2017
ISBN: 978-1-78728-355-8
Verlag: Packt Publishing
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)

E-Book, Englisch, 268 Seiten

ISBN: 978-1-78728-355-8
Verlag: Packt Publishing
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)



The ESP8266 Wi-Fi Module is a self contained System on Chip (SOC) with an integrated TCP/IP protocol stack and can give any microcontroller access to your Wi-Fi network. It is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.
This book contains practical recipes that will help you master all ESP8266 functionalities. You will start by configuring and customizing the chip in line with your requirements. Then you will focus on core topics such as on-board processing, sensors, GPIOs, programming, networking, integration with external components, and so on. We will also teach you how to leverage Arduino using the ESP8266 and you'll learn about its libraries, file system, OTA updates, and so on. The book also provide recipes on web servers, testing, connecting with the cloud, and troubleshooting techniques. Programming aspects include MicroPython and how to leverage it to get started with the ESP8266. Towards the end, we will use these concepts and create an interesting project (IOT).
By the end of the book, readers will be proficient enough to use the ESP8266 board efficiently.

Schwartz ESP8266 Internet of Things Cookbook jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


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, :

We will still use same thing name, , 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 new thing name in all the URLs.

Since alerts work with locked things, it is advisable to get yourself a lock and key before proceeding to the next section. Visit https://dweet.io/locks to do that.

How to do it…


  1. To create an alert, make an request using a URL with this format:

    In the preceding URL:

    • : This refers to e-mail addresses you want to send notifications to. If there are several e-mail addresses, separate them using commas.
    • : This is the valid name for your thing.
    • : This is a JavaScript expression that you use to evaluate data stored in . For example:

    The expression is limited to 2,000 characters and should not contain JavaScript reserved words, loops, or other complex things:

    • : This is the valid key for your locked dweet
  2. To create an when the temperature exceeds degrees Celsius, we will use this URL: .
    • You can remove alerts using this URL format:

    • Instead of using your ESP8266 board to lock your thing and create an , you can use a web browser. Using the web browser is the fastest way to do it, since all you need to do is call the URL for locking dweets and the URL for setting alerts on your Internet browser. Moreover, you will only need to lock your thing and create an alert once, so there is no need for your ESP8266 board to repeat the process every time it turns on.
    • Therefore, use your web browser to call this URL to lock your thing: .
  3. Replace with the lock ID you were sent via e-mail and replace with the master key that was provided in the e-mail.
    • Once the thing has been locked successfully, create an alert to send you notifications when the temperature exceeds degrees Celsius. Do that by calling this URL in your web browser: .
  4. Remember to replace with your master key.
  5. After using your web browser to lock your thing and create an alert, upload the data logging sketch to your ESP8266. This will log sensor data on and inform you when the temperature goes above 25 degrees Celsius:
    // Libraries #include
    • This sketch is the same as the one for logging data to an unlocked thing on . The only difference is that this time the key is included in the URL, so you will have to provide the master key in this section of the code:
      // dweet.io lock and key String key = "your-key";
    • The key is then appended to the URL in this section of the code:
      // We now create a URI for the request String url = "/dweet/for/garden-monitor-11447?key="; url += key;
  6. Copy the sketch to your Arduino IDE and change the in the code from to the name of your Wi-Fi network, and change the from to the password of your Wi-Fi network. Also, change the from to the key that was provided to you via e-mail. Use the master key, not the read- only key.
  7. Upload the sketch to your ESP8266 board and open the serial monitor so that you can view the incoming data.

How it works…


The program connects to the Wi-Fi network using the provided and . It then proceeds to connect to the provided cloud/host server using the function. Once the ESP8266 connects successfully, data from the sensors is then read and a URL is generated that includes the updated sensor data and the master key for the lock. The URL is then sent to the server using the function.

Once the data has been successfully sent, the sketch waits for a reply from the server. It does this with the function, which checks whether there is incoming data from the server. If there is data available, the sketch reads it and displays it on the serial monitor. The ESP8266 posts sensor data to every five seconds.

monitors the temperature value and sends alerts to your e-mail address, when the temperature exceeds 25 degrees Celsius. The e-mail will look like this:

There's more…


Try and change the current alert to be triggered when the temperature exceeds another value. You can even add alerts for the other parameters, and .

See also


Now that you can successfully monitor data from one ESP8266 board, you can take it a notch higher and start monitoring more than one ESP8266 module at the same time. The next recipe will show you how to do...



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.