Internet of Things Projects with ESP32
eBook - ePub

Internet of Things Projects with ESP32

Build exciting and powerful IoT projects using the all-new Espressif ESP32

Agus Kurniawan

Compartir libro
  1. 252 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Internet of Things Projects with ESP32

Build exciting and powerful IoT projects using the all-new Espressif ESP32

Agus Kurniawan

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Create and program Internet of Things projects using the Espressif ESP32.

Key Features

  • Getting to know the all new powerful EPS32 boards and build interesting Internet of Things projects
  • Configure your ESP32 to the cloud technologies and explore the networkable modules that will be utilised in your IoT projects
  • A step-by-step guide that teaches you the basic to advanced IoT concepts with ESP32

Book Description

ESP32 is a low-cost MCU with integrated Wi-Fi and BLE. Various modules and development boards-based on ESP32 are available for building IoT applications easily. Wi-Fi and BLE are a common network stack in the Internet of Things application. These network modules can leverage your business and projects needs for cost-effective benefits.

This book will serve as a fundamental guide for developing an ESP32 program. We will start with GPIO programming involving some sensor devices. Then we will study ESP32 development by building a number of IoT projects, such as weather stations, sensor loggers, smart homes, Wi-Fi cams and Wi-Fi wardriving. Lastly, we will enable ESP32 boards to execute interactions with mobile applications and cloud servers such as AWS.

By the end of this book, you will be up and running with various IoT project-based ESP32 chip.

What you will learn

  • Understand how to build a sensor monitoring logger
  • Create a weather station to sense temperature and humidity using ESP32
  • Build your own W-iFi wardriving with ESP32. Use BLE to make interactions between ESP32 and Android
  • Understand how to create connections to interact between ESP32 and mobile applications
  • Learn how to interact between ESP32 boards and cloud servers
  • Build an IoT Application-based ESP32 board

Who this book is for

This book is for those who want to build a powerful and inexpensive IoT projects using the ESP32.Also for those who are new to IoT, or those who already have experience with other platforms such as Arduino, ESP8266, and Raspberry Pi.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Internet of Things Projects with ESP32 un PDF/ePUB en línea?
Sí, puedes acceder a Internet of Things Projects with ESP32 de Agus Kurniawan en formato PDF o ePUB, así como a otros libros populares de Computer Science y Computer Networking. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2019
ISBN
9781789953121
Edición
1

Controlling IoT Devices over the Internet

Internet of Things (IoT) is one of the most popular topics in the technological industry. IoT can be applied in various scenarios, such as monitoring and automation. In this chapter, we will learn how to implement IoT on an ESP32 board through a Wi-Fi network. Here, we will begin to connect to an existing Wi-Fi and then make our own smart home application over Wi-Fi.
We will cover the following topics in this book:
  • Connecting to an internet network via ESP32
  • Accessing data from a web server
  • Building a web server inside ESP32
  • Making a smart home application

Technical requirements

Before we begin, make sure you have the following things ready:
  • A computer with an OS installed, such as Windows, Linux, or macOS.
  • An ESP32 development board. We recommend the ESP-WROVER-KIT v4 board from Espressif.
  • A Wi-Fi network with internet access capability.

Introducing ESP32 Wi-Fi development

Wi-Fi, or a wireless network, is a communication model that makes it possible to interact with another system. With these, we can perform common network tasks over network protocols such as TCP/IP, UDP/IP, HTTP, or SMTP/POP3. Since the ESP32 chip has built-in Wi-Fi and a Bluetooth module, we connect our ESP32 board to an existing network.
To work with Wi-Fi on ESP32, we need the esp_wifi.h header file to be included in our project:
#include "esp_wifi.h"
Wi-Fi programming in ESP32 uses an event-based model. We call the Wi-Fi API from the board driver in order to access the Wi-Fi module on the ESP32 board. The ESP32 Wi-Fi API supports Wi-Fi security such as WPA, WPA2, and WEP. A list of Wi-Fi API functions can be found at https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_wifi.html.
In this chapter, we will work with a Wi-Fi network stack in the ESP32 board. For demo purposes, I have used the ESP-WROVER-KIT v4 board.

Scanning Wi-Fi hotspot

The first demo is used to perform Wi-Fi scanning. We will scan for all existing Wi-Fi networks in the surrounding area in which we are present. First, we will create the ESP32 project, called wifiscan. Our main program is wifiscan.c.
Next, we load all libraries from header files into our program as follows:
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "nvs_flash.h"

#include "lwip/err.h"
#include "lwip/sys.h"
In the main entry app_main() function, we initialize storage for the Wi-Fi program by calling the esp_wifi_set_storage() function. We also need a function to listen to incoming events from the Wi-Fi API. For instance, we create a function named event_handler() and pass it into the esp_event_loop_init() function.
Next, we run the Wi-Fi service on ESP32 by calling the esp_wifi_start() function:
 esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );

tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
After the Wi-Fi service has started, we will perform Wi-Fi scanning using the esp_wifi_scan_start() function. To do this, we should pass the wifi_scan_config_t parameter into esp_wifi_scan_start(). For Wi-Fi scanning, we set NULL for the ssid and bssid parameters.
We perform looping in Wi-Fi scanning. After the Wi-Fi scanning process is done, we again call esp_wifi_scan_start():
 wifi_scan_config_t scanConf = {
.ssid = NULL,
.bssid = NULL,
.channel = 0,
.show_hidden = true
};

while(true){
ESP_ERROR_CHECK(esp_wifi_scan_start(&scanConf, true));
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
Now, we will implement the event_handler() function. Technically, we receive all events from the Wi-Fi service. You can read about Wi-Fi events in the ESP32 documentation at https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/wifi.html.
In this scenario, we will wait for the SYSTEM_EVENT_SCAN_DONE event. This event is raised after ESP32 performs the Wi-Fi scanning. To get the result of Wi-Fi scanning, we can call the esp_wifi_scan_get_ap_num() function.
Then, we will loop our program to retrieve Wi-Fi hotspot information by calling the esp_wifi_scan_get_ap_records() function. We will then print the Wi-Fi information into the Terminal as follows:
esp_err_t event_handler(void *ctx, system_event_t *event)
{
if (event->event_id == SYSTEM_EVENT_SCAN_DONE) {
uint16_t apCount = 0;
esp_wifi_scan_get_ap_num(&apCount);
printf("Wi-Fi found: %d\n",event->event_info.scan_done.number);
if (apCount == 0) {
return ESP_OK;
}
wifi_ap_record_t *wifi = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * apCount);
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&apCount, wifi));
....
}
After we have obtained a list of wifi_ap_record_t items, we will set the authentication name based on the wifi_ap_record_t.authmode type, as follows:
 for (int i=0; i<apCount; i++) {
char *authmode;
switch(wifi[i].authmode) {
case WIFI_AUTH_OPEN:
authmode = "NO AUTH";
break;
case WIFI_AUTH_WEP:
authmode = "WEP";
break;
case WIFI_AUTH_WPA_PSK:
authmode = "WPA PSK";
break;
case WIFI_AUTH_WPA2_PSK:
authmode = "WPA2 PSK";
break;
case WIFI_AUTH_WPA_WPA2_PSK:
authm...

Índice