Book Image

Developing IoT Projects with ESP32 - Second Edition

By : Vedat Ozan Oner
3 (2)
Book Image

Developing IoT Projects with ESP32 - Second Edition

3 (2)
By: Vedat Ozan Oner

Overview of this book

ESP32, a low-cost and energy-efficient system-on-a-chip microcontroller, has become the backbone of numerous WiFi devices, fueling IoT innovation. This book offers a holistic approach to building an IoT system from the ground up, ensuring secure data communication from sensors to cloud platforms, empowering you to create production-grade IoT solutions using the ESP32 SoC. Starting with IoT essentials supported by real-world use cases, this book takes you through the entire process of constructing an IoT device using ESP32. Each chapter introduces new dimensions to your IoT applications, covering sensor communication, the integration of prominent IoT libraries like LittleFS and LVGL, connectivity options via WiFi, security measures, cloud integration, and the visualization of real-time data using Grafana. Furthermore, a dedicated section explores AI/ML for embedded systems, guiding you through building and running ML applications with tinyML and ESP32-S3 to create state-of-the-art embedded products. This book adopts a hands-on approach, ensuring you can start building IoT solutions right from the beginning. Towards the end of the book, you'll tackle a full-scale Smart Home project, applying all the techniques you've learned in real-time. Embark on your journey to build secure, production-grade IoT systems with ESP32 today!
Table of Contents (15 chapters)
13
Other Books You May Enjoy
14
Index

Consuming RESTful services

In this example, our sensor will read its configuration from a RESTful server by connecting it as a client and publishing its state on the same server. As a server, we will run a simple Flask application in a virtual Python environment. Let’s prepare the server in steps:

  1. Copy the ch6/rest_client_ex/server directory from the GitHub repository and switch to this directory. Install the Python requirements in a virtual environment:
    $ python --version
    Python 3.6.8
    $ pyenv virtualenv 3.6.8 apptest
    $ pyenv local apptest
    (apptest) $ pip install -r requirements.txt
    
  2. Set the Flask application:
    (apptest) $ export FLASK_APP=./rest_server.py
    
  3. Start the server. The -h 0.0.0.0 option makes Flask serve on all network interfaces of the machine:
    (apptest) $ flask run -h 0.0.0.0
    * Serving Flask app './rest_server.py' (lazy loading)
    <logs removed>
    * Running on http://10.8.0.2:5000/ (Press CTRL...