Reader small image

You're reading from  Developing IoT Projects with ESP32 - Second Edition

Product typeBook
Published inNov 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781803237688
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Vedat Ozan Oner
Vedat Ozan Oner
author image
Vedat Ozan Oner

Vedat Ozan Oner is an IoT product developer and software architect, with an excellent blend of technical knowledge and experience. During his career, he has contributed to several IoT projects in different roles, which allowed him to discover all key aspects of developing successful IoT products in highly competitive markets. Vedat has a bachelor's degree in METU/computer engineering and holds several industry-recognized credentials and qualifications, including PMP®, ITIL®, and AWS Certified Developer. Vedat started his limited company, Mevoo Ltd, in London in 2018 to provide consultancy services to his clients as well as develop his own IoT products. He still lives in London with his family.
Read more about Vedat Ozan Oner

Right arrow

Project – Smart Home

Developing an IoT product requires many hardware and software components to work together flawlessly for the best customer experience. As IoT developers, we might not be experts in all of them, but we still need to know the components and how to integrate them into a project. All that is needed is practice to gain experience with the options. A smart home is a good example because it has all the main IoT components operating together. It is a well-known field in the IoT world: a smart home solution incorporates sensors and actuators to help people monitor and control their homes and entertainment systems, which are integrated in the solution for a complete experience. The devices in a smart home usually run in the same local network. The solution implements a backend infrastructure as the backbone of the entire system, and web or mobile applications are included for end users to use their devices remotely. This chapter is a good opportunity to learn how...

Technical requirements

The hardware requirements of the chapter are:

  • ESP32-C3 DevkitM-1
  • A relay module (any 3.3V 1-channel relay with optocoupler isolation, available in online stores)
  • ESP32-S3 Box Lite
  • A BME280 breakout
  • A TSL2561 ambient light sensor breakout
  • Jumper wires

We will also need two mobile applications to test the project. They are:

  • ESP RainMaker: The companion application that comes with the RainMaker platform to add devices and manage them in the platform. It is available for both Android and iOS.
  • Amazon Alexa: The mobile application by Amazon to control and monitor Alexa-enabled devices. It is available for both Android and iOS.

It is not a mandatory tool since I will provide the generated code, but the GUI in the sensor application is designed by using SquareLine Studio (available at https://squareline.io/ for all mainstream platforms).

You can find the project code in the GitHub repository...

The feature list of the smart home solution

The smart home solution will have the following features:

  • A plug that will be able to power small home appliances.
  • A mobile application to turn the plug on or off.
  • The plug firmware can be updated over-the-air remotely.
  • A multisensor that will show temperature and ambient light intensity on its display.
  • Temperature and light intensity values can be monitored remotely via the mobile application.
  • The multisensor firmware can be updated over the air remotely.
  • The solution will support automation. Users will be able to define rules such as if the light intensity is over 20, turn off the plug.
  • The solution will integrate Amazon Alexa as the voice interface.

Let’s discuss a possible solution architecture for these features.

Solution architecture

The solution will integrate common components that a typical smart home product can usually have. There will be smart devices, a plug and a sensor, applications, a cloud system that provides control and monitoring facilities, and a mobile application for end user to access the devices remotely. We will employ ESP RainMaker (https://rainmaker.espressif.com/) as the cloud system that the devices connect to. ESP RainMaker also comes with a mobile application for remote access to the devices. The following figure shows this architecture:

Figure 9.1: Solution architecture

ESP RainMaker provides all the backend functionality that we need in order to implement this project. By integrating with the ESP RainMaker infrastructure, we will have the following capabilities:

  • Device provisioning, that is, adding/removing devices via the mobile application
  • Remote monitor and control
  • OTA device firmware upgrade
  • Alexa Voice Services integration...

Implementation

The solution architecture defines three different software packages:

  • Common libraries and components: We can reuse the third-party libraries and the components that we developed in the previous examples. After all, it is the whole point of modular software design.
  • Plug application: The plug application will have the AppPlug class on top of the common libraries to satisfy the project requirements.
  • Multisensor application: We will develop the AppSensorNode and AppUi classes in the multisensor application. The application will integrate all the classes as a whole as described in the requirements.

Let’s start with the common libraries.

Preparing common libraries

The requirements and the design reveal some of the third-party libraries that we are going to need to develop the project. They are:

Testing project

We have two devices in the solution. Let’s begin with the plug. We will flash the application on the devkit, then provision it to ESP RainMaker and see how the plug application behaves.

Testing plug

We can test the plug application as follows:

  1. Make sure the plug hardware is ready with ESP32-C3 DevkitM-1 and the relay module connected to it.
  2. Go to the plug ESP-IDF project directory and flash the application on the devkit:
    $ idf.py erase-flash flash monitor
    Executing action: erase-flash
    Serial port /dev/ttyUSB0
    Connecting....
    Detecting chip type... ESP32-C3
    <more logs>
    I (9447) app_wifi: Scan this QR code from the ESP RainMaker phone app for Provisioning.
    <QR-code is here>
    
  3. Start the RainMaker application on your mobile device and add the plug. The application runs a wizard for provisioning. When the provisioning is completed, tap on the Done button and return to the main screen.

    Figure 9.7: Adding...

Troubleshooting

Each project comes with its own specific challenges. If you encounter some issues while developing the project, the following list may help:

  • First and foremost, make sure the paths in the root CMakeLists.txt file are correct if you configure the project yourself. The GitHub clone should compile without an issue since it is already configured with the relative paths in the repository, but when you collect the components and libraries yourself, you need to update the paths according to your directory structure.
  • The idf.py tool detects the connected devkit automatically without the serial port argument if there is only one. However, we need two devkits to be connected at the same time in this project. Therefore, pass -p <port> to idf.py when you flash or monitor the second one.
  • The default transport method is BLE when provisioning the RainMaker nodes in this project. You can run menuconfig and set the provisioning method to SoftAP in the ...

New features

Here are some ideas for new features that you can add to the project:

  • ESP32-C3 DevkitM-1 doesn’t have a display, but it would be nice to have a feedback mechanism for the plug connection status. Use the devkit’s LED as an indicator to show the disconnected and connected events.
  • We enabled the Local Control Service on the devices (https://rainmaker.espressif.com/docs/local-control-service.html). It runs a web server and mDNS on the device. Update the plug application to define an endpoint (https://docs.espressif.com/projects/esp-idf/en/v4.4.4/esp32c3/api-reference/protocols/esp_http_server.html) on the web server and handle the state change requests. You can use the following curl commands to test:
    $ curl -X PUT http://<ip>/state?value=ON
    $ curl -X PUT http://<ip>/state?value=OFF
    $ curl -X PUT http://<ip>/state?value=TOGGLE
    
  • Update the multisensor application to discover the plug in the network by scanning...

Summary

In this chapter, we designed and developed a smart home solution with two different devices, a plug and a multisensor, for a given set of requirements. We integrated them with the RainMaker platform, which provides cloud connectivity for our devices. We used the mobile application that comes with the RainMaker platform in order to provision and manage the devices. The platform also supports Alexa and Google Assistant voice services. We tested our devices with the Alexa mobile application after the account linking between RainMaker and Alexa.

IoT products are great; they make people’s lives easier in the most basic terms. However, they become even more effective when they are powered by artificial intelligence. In the next chapter, we will discuss how to run Machine Learning (ML) applications on ESP32.

Learn more on Discord

To join the Discord community for this book – where you can share feedback, ask questions to the author, and learn about new releases...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Developing IoT Projects with ESP32 - Second Edition
Published in: Nov 2023Publisher: PacktISBN-13: 9781803237688
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 €14.99/month. Cancel anytime

Author (1)

author image
Vedat Ozan Oner

Vedat Ozan Oner is an IoT product developer and software architect, with an excellent blend of technical knowledge and experience. During his career, he has contributed to several IoT projects in different roles, which allowed him to discover all key aspects of developing successful IoT products in highly competitive markets. Vedat has a bachelor's degree in METU/computer engineering and holds several industry-recognized credentials and qualifications, including PMP®, ITIL®, and AWS Certified Developer. Vedat started his limited company, Mevoo Ltd, in London in 2018 to provide consultancy services to his clients as well as develop his own IoT products. He still lives in London with his family.
Read more about Vedat Ozan Oner