Assembling the device
What is required to assemble a sensor like this:
- Breadboard - 1 pc.
- IoT platform ESP-WROOM-32 DevKit v1 - 1 pc. (any other platform variation with or without an ESP32 microcontroller on the Dev Board).
- Male to male jumper cable - 3 pcs.
- DHT11 humidity and temperature sensor - 1 pc.
- USB-micro USB cable.
All necessary components:
To assemble the device, we used the following example of a circuit found by searching for images on Google:
Here's what happened as a result:
Making the “smart” assembled device
1 - Go to the vendor's account using the link - https://cloud.2smart.com/ . Log in to your account.
2 - On the Products page, click Add Product and select the ESP32 microcontroller.
3 - On the new product page, enter its name and upload the icon - with this data, the device will be displayed in the mobile application.
4 - Click " Add Firmware" and select an ESPHome base for it.
5 - Paste the following firmware code into the opened window:
- platform: gpio
- platform: dht
Explanation of the firmware code:
✔ The first six lines are the standard code for controlling the LED on the microcontroller.
✔ The next eight lines are the standard code for the DHT11 sensor taken from here. We've made two changes to this:
- changed the data update interval - every 10 seconds instead of every 60 seconds,
- the pin of the microcontroller to which the sensor is connected is indicated - in our case it is GPIO15.
6 - Save the code configuration in the product setup window and then click Build Firmware for the Sandbox option. Specify the data for connecting to your Wi-Fi network - they will be embedded in the firmware code so that the device will immediately go online and connect to the platform.
7 - Wait for the firmware build and click "Download".
8 - Extract the downloaded archive, enter the folder with the received files and read the instructions for firmware in the readme.md file.
Firmware is available from Mac OS and Linux devices - we used Mac OS.
9 - Connect your device to your computer using a USB cable. Erase the microcontroller memory with the command ./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART.
10 - Wait for the cleanup and run the firmware installing command ./2smart.sh write -d /dev/tty.SLAB_USBtoUART.
11 - After completing the firmware process, return to the platform - the device will automatically connect to the Sandbox environment. Successful connection is indicated by a green color and Ready status in the “Device Status” field.
12 - Click “Preview state” - you will have access to the data of all sensors of your device, including the current temperature and humidity.
13 - Click “Add layout” - the mobile application emulator will open. Appropriate widgets are automatically created for all sensors on your device. You can customize the appearance of the application to your liking, including choosing different types of widgets instead of the default widgets and organizing the order of the widgets on the screen.
Please note that the sensor values are updated in real time already in the mobile application emulator. You can also control the device from the computer screen - in this case, the LED can be turned on / off.
14 - Open the settings of the temperature and humidity sensors and make sure that the historical data collection checkbox is checked on the “Advanced” tab. It is also recommended to add units and boundaries along the vertical axis.
15 - Please note that in the mobile application, in addition to the widget screen, a telemetry screen with metadata is automatically created. It is not recommended to delete.
16 - By clicking the “Back” arrow in the mobile app emulator, you can see how the sensor will look in the list of connected devices.
17 - Go back to the device management interface, go to the temperature and humidity widgets and see how the graphs with the history of the corresponding readings will look like. So far, you can only evaluate the appearance of the graph - its values themselves in the test mode have nothing to do with reality and are presented for clarity.
After you finish configuring the interface, click "Save".
18 - Launch the 2Smart Cloud mobile app on your smartphone - most likely you've already used it to connect and control a virtual lamp. Log out of your account, turn on sandbox mode and log in using the email and password that you used when registering at the vendor's account.
19 - Your new device is already showing in the app - make sure you can turn on / off the LED on the board and get the correct temperature and humidity sensor readings.
20 - Go back to the platform and click "Build Firmware" for the "Production" option.The final version of the firmware will be built, which will not contain the parameters of your Wi-Fi network and other specific lines of code needed to work in the test environment. Download the archive that you received.
21 - Upload the Production device with the firmware similar to the Sandbox firmware version. Remember to clear the microcontroller memory first.
Use the following commands:
./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART
./2smart.sh write -d /dev/tty.SLAB_USBtoUART
22 - Click Publish to start using your device.
23 - Go back to the mobile app, log out and disable Sandbox mode. Log in with any parameters as a regular user.
24 - Click the “Add Device” button on the “Devices” screen and the pairing procedure will start.
25 - Select "Others" from the list of available devices to bind to the application. Then click "Continue".
26 - Specify the data of your Wi-Fi network, which will be sent to the device to connect to the Internet.
27 - After uploading Production firmware, the microcontroller will have access point mode with a name that meets the name of your device on the platform. Connect to this network in the next step.
28 - Wait for the pairing procedure to complete.
29 - Your temperature sensor is now displayed on the Devices screen. Make sure you can control it from your smartphone. Wait until the history of temperature and humidity readings appears and check the status of the corresponding graphs.
That's all! In just 30 minutes, we created a useful IoT device that can be used on a daily basis. If necessary, the temperature and humidity sensor can be placed on a printed circuit board, as well as printed out the device body on a 3D printer. By placing it in a room or any other
premises, you can control temperature and humidity from anywhere with Internet access.