This allows the vendor to add new functionality to the firmware and fix possible bugs at any time. At this stage, we decided to apply both major and minor updates. Changes will be made to the firmware code and the interface of the mobile application.
Device firmware update
For an example of such an update, let's use the correction of the text that the mobile app user receives when the relay is physically turned on and off with a button on the corpus. Before the update, the notifications read "Relay on" and "Relay off". After the update, the text will change to "Relay was turning on" and "Relay was turning off".
Fixing bugs, adding new functionality, or improving existing functionality.
The procedure of any larger code update will be similar to the one described below.
1 - Prepare a test device (a Wi-Fi relay on a breadboard in our example.) Running devices on printed circuit boards will receive a ready-to-use update after the new firmware version has been published on the platform.
2 - In the “Products” tab of the vendor's cabinet, select the device which Custom firmware you want to update.
3 - Click the "Update firmware" link.
4 - Click "Update firmware".
5 - In the firmware sources on your computer, find the files that need to be corrected and make the necessary changes.
To fix the notification text, we worked with the file located at Firmware/lib/relay_node/property/relay_state.cpp.
6 - After fixing the code in the correct files, don't forget to make changes to /src/main.h. Specify the new version of the device in the “Device Version” field (in our case correct "1" to "2").
7 - Flash the test device with the new firmware version via USB cable.
Note! If the firmware has already been written to the microcontroller, do not forget to remove it according to the documentation.
8 - After completing the flashing process, the device will create a Wi-Fi hotspot with a name that matches that of the device. Connect your computer or smartphone to this Wi-Fi hotspot.
9 - Follow the link http://192.168.4.1/ to open the web interface of your device.
10 - Copy the values from the Connection Information screen into the fields on the Credentials tab:
- In the “Login” field - the value "User Login".
- In the “Token field” - the value "Access Token".
- In the “Hostname” field (under the Advanced spoiler) enter the value "cloud.2smart.com".
- In the “Device ID” field, copy the value "Test device ID".
After completing the fields, click Save.
11 - Assure that your computer is still connected to the device's Wi-Fi hotspot. Click the “Wi-Fi” tab and then click “Scan”.
12 - Select your Wi-Fi network in the list and enter the password to access it. This is necessary so your Sandbox device can connect to the test environment of the 2Smart Cloud platform.
Note! Devices based on the ESP32 microcontroller support only Wi-Fi networks with a frequency range of 2.4 GHz!
13 - Now switch to your Wi-Fi network and open the device page in the vendor's account. After successfully connecting the prototype to the internet, the device status will change to “Ready”.
14 - Click the " Preview State" link and check that the Firmware Version sensor displays the new firmware version’s value.
15 - Double-check that the firmware update has given the desired result (notification text has changed). Test the operation of the device similar to the initial testing of the prototype.
16 - Build a new version of the firmware on your computer in .bin format.
17 - Click the "Update Firmware" link and upload the ready-made firmware file to the platform.
18 - Click "Publish".
19 - Confirm your desire to publish a new version of the product.
20 - Devices with older firmware versions will receive the update automatically after checking for updates. The user can also click the “Push” button on the “Firmware” tab of the device interface in the app to get the update immediately.
21 - When the device has been updated, the new firmware version will be displayed in the mobile application interface.
22 - You can see the changes made to the firmware by entering the notifications section of the mobile app. By pressing the physical “on/off” button on the relay body, you will receive messages with the new text.
Colleagues and friends who used the Wi-Fi relay confirmed that the new version of the firmware came automatically within 24 hours.
Mobile app interface update
Having discovered that the widget library was updated on the 2Smart Cloud platform, a decision was made to update the interface of the mobile application for controlling the Wi-Fi relay. By adding a graph widget for the Wi-Fi signal level sensor, we can see statistics on how this level has changed over time.
Editing the application interface is no different from creating it when adding a new product:
1 - Click on the link “Edit layout” on the product page in the vendor's cabinet.
2 - Click "Add widget".
3 - Choose the widget of your liking. (In our case, it was "Number".)
4 - Configuring the widget. Select the display of sensor data “WiFi Signal”.
5 - In the emulator of the mobile application, confirm that you received the desired display of the “history of changes” in the signal strength of the Wi-Fi network on the graph.
6 - Click "Save".
7 - Click "Publish".
8 - Agree to the publication of minor product updates.
9 - The only thing left to do for users, is to restart the 2Smart Cloud mobile app on their smartphone to see the changes made to the interface.
Once the firmware has been updated, it might be of interest to monitor how the actual devices are updated. In addition to the usual feedback, you can do this using the statistics section in the vendor's 2Smart Cloud cabinet.
The final article of our series is dedicated to working with statistics.
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