However, the ESPHome-based device firmware has some limitations, with the main one being unable to update the firmware over the air. To install a new firmware version, each of the devices must be connected to the computer via a USB cable, which can be inconvenient at times.
The perfect solution was the use of the 2Smart Cloud platform SDK development kit. With its help, you can prepare custom firmware. Along with the ability to update the entire series of devices over the air, SDK provides extra features like a built-in web interface with device settings, sending notifications about the device’s status, and many more. Thanks to the SDK, all of this is available "out of the box" and immediately after installing the firmware on the devices.
A notable advantage of the SDK is that it already contains the basic functions of a standard device. The vendor just needs to get a suitable, ready-made example code and use it for their device based on the tutorial. This will help describe the business logic of the device's operation. There is no need to understand the mechanics of the 2Smart Cloud IoT platform when doing this.
Preparing Custom firmware based on the SDK
For the Wi-Fi relay, the Custom firmware is already written and the code can be found on the GitHub. Changes needed are minimal, one just needs to add product-specific parameters to the code.
Because the base firmware is completely changing (we worked with ESPHome before), we couldn’t edit the existing product on the platform. We had to prepare a new product based on Custom firmware.
1- In the Vendor Cabinet, go to “Products” and click “Add Product”.
2 - Select the microcontroller on which the device is based on. In our case, it is the ESP32.
3 - Enter the information about the device such as its name, and upload an icon.
4 - Click "Add Firmware".
5 - Select “Custom” and click “Next”.
6 - Click the "Connection Info" link.
7 - Leave the window with the connection parameters open as some of them will need to be copied into the firmware code.
8 - Go to the downloaded firmware repository and open the file “Firmware/src/main.h” where you will make the following changes:
- Copy the product ID and paste it into the firmware name and product ID sections.
- Specify your own product name instead of the default name in the “device name” section.
9 - Save the changes to the firmware code and install the firmware on your device.
Please note! If the firmware is already written to the microcontroller, remember to delete it by following the documentation.
10 - After successful installation, the device will create its Wi-Fi access point with the same name that was specified for the device in the firmware code. Connect to this network.
11 - Go to http://192.168.4.1/ to open the web interface of your device.
12 - Copy the information from the “Connection Information” window into the fields on the “Credentials” tab:
- In the “Login” field - "User Login",
- In the “Token” field - "Access Token",
- In the Hostname field (under the Advanced spoiler), enter "cloud.2smart.com",
- Enter "11883" in the Broker port field,
- in the Device ID field, copy "Test device ID".
After completing all, click Save.
13 - Confirm that your computer is still connected to the device's Wi-Fi hotspot. Click the “Wi-Fi” tab and then click “Scan”.
14 - Select your Wi-Fi network in the list and enter the password to access it. This step is necessary for your Sandbox device to connect to the test environment of the 2Smart Cloud platform.
Please note! Devices based on the ESP32 microcontroller support only Wi-Fi networks with a frequency range of 2.4 GHz!
15 - Return to your Wi-Fi network and open the vendor's cabinet. On the product page, close the window with the connection information. Pay attention to the status of the device. After changing the necessary settings in the web interface of the device, the status should change to “Ready”.
16 - By clicking the "Preview State" link, you will be presented with the current sensor data of the device.
17 - Click the "Add layout" button and configure the appearance of the mobile app to control the device. Note that after installing the firmware on the Wi-Fi relay based on the SDK, widgets are available for you to work with updates and notifications.
We recommend that you create a separate tab in the application interface for widgets related to firmware updates. In our example, we created six such widgets in the Firmware tab:
- Auto Update switch - turns on the automatic firmware update,
- Update button - force-start of firmware update.
- TimePicker widget to set the exact time of day when the device will look for a new firmware version to automatically download.
- Text widget with update status.
- Text widget with the version number of the current firmware on the device.
- Text widget with the IP address of the web panel of the device.
To configure notifications, consider creating a Notifications tab and add the following widgets to it:
- System switch for system notifications (for Wi-Fi relays, these are relay switching messages using the physical button on the housing).
- Update switch for firmware update notifications.
18 - After saving the configured interface, click the link "upload firmware" and download the ready firmware.bin file to the platform, which is located in the folder with the firmware .pio/build/esp32ev/.
19 - Click "Publish" and confirm your wish to place the new product on the platform.
20 - Since you have created a new device on the platform, delete the previous option from the 2Smart Cloud application and pair the device again by following the standard pairing action.
The control interface of the new device gives additional features configured in the vendor's cabinet. They include control of firmware updates over the air and the configuration of notifications from the device. In the case of a Wi-Fi relay, this is exactly what we wanted to get from Custom firmware.
And that's it. We installed the Custom firmware on the same device where ESPHome was installed. After making sure that the Wi-Fi relay works smoothly and is controlled from the mobile app, we can reinstall the whole series of devices. This will be the last firmware update via USB cable. The next updates, thanks to the use of Custom firmware on the SDK, will happen over the air.
The article that follows explains how firmware updates are prepared and how the update is done over the air. Keep an eye out for more!
- 2Smart Cloud IoT platform – https://cloud.2smart.com/
- Materials for creating Wi-Fi Relay at public repository – https://github.com/2SmartCloud/2smart-cloud-esp32-relay
All articles about IoT device creation and support
- Learn your way around the IoT platform – create your first device and control it from your smartphone without an MCU
- How to create a Wi-Fi switch to control via a mobile app and Telegram bot
- 4 stages of using the platform to create a new IoT device
- How to create an IoT device on a printed circuit board and take it from prototype to finished product
- How to write firmware for an IoT device based on an SDK
- How to update the firmware and mobile application of ready-made devices within 5 minutes
- Collection and analysis of statistics – a useful tool for product improvement