Adding a new effect for the LED strip controller or Wi-Fi lamp
To adapt the ready-made firmware code for yourself and add new controller effects, first of all, you need to create a new product in the 2Smart Cloud developer cabinet:
1. On the “Products” tab, click “Add Product”.
2. Select the microcontroller – ESP32.
3. Click "Add Firmware" and select the Custom option.
4. Click the "Connection Info" link and leave the window with the product connection parameters open.
5. Download the LED controller or Wi-Fi lamp project from the repository. Open it in the terminal, and make the necessary changes in a text editor:
- add the effect method to lib/lenta/lenta.h, add the effect name to LedStripStates:
- in modes_, assign the name for the mobile application to the name of the effect:
- in lib/lenta/lenta.cpp add the method body with a description of the entire logic of the effect. If necessary, add auxiliary methods.
Attention! Remember that diode lighting is also a mode task., for which you need to use the LEDS.show(); command.
- in HandleCurrentState, add the mode to switch:
6. Open the Firmware/src/main.h file and make the following changes:
- copy the product ID from the "Connection Info" window in the vendor's account and paste it into the firmwareName and ProductID fields,
- specify the name of your device's access point instead of the default one in the deviceName area,
- if you create a new product, make sure that its device_version is set to 1.
7. Connect the controller to the computer with a USB cable and flash it. Don't forget to disable the feed first!
Use the following commands to install the firmware:
pio run -t uploadfs
pio run -t upload
8. After completing the firmware installation, the device activates its Wi-Fi access point. When connecting to it, you will be able to access the controller's web interface and configure it to connect to the platform:
- link to the access point of the controller – “2Smart Led Strip” or “2Smart Lamp” (the name can also be changed to your own in the main.h file) and enter the link http://192.168.4.1 in the address bar of the browser to enter the web interface device, use the login and password “admin”,
- on the Credentials tab, specify your product parameters from the “Connection Info” window opened in the vendor's cabinet:
- 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 Broker port field, enter the value "11883”,
- copy the value "Test device ID" in the Device ID field.
- after filling in all the fields, click Save and go to the Wi-Fi tab of the controller's web interface. Click Scan to search for available Wi-Fi networks:
- select your access point from the list of found access points and enter your password:
9. If all the settings are correct, the device will connect to the platform, and its status will change to Ready.
Setting up and publishing a product
1. Click "Add Layout" and customize the appearance of the mobile application. For more information about setting up the interface, see the article about creating a temperature sensor or the series of articles about creating a "smart" Wi-Fi relay.
2. Test device control from the application emulator or directly from your smartphone - just log into the application with the same login and password as in the developer's cabinet.
3. After successful testing, the device is ready to be published on the platform. It remains to upload the firmware to the platform server and publish the product.
You can find the finished firmware file in the Firmware/.pio/build/esp32dev/firmware.bin folder (do not forget to enable the display of hidden files in the explorer to find the directory).
4. Click "Upload firmware" in the vendor's office and upload the .bin file.
5. After uploading the firmware, click "Publish". After the product is published, it will be available for binding to the mobile application by all users. The standard procedure is enough to pair the device to the mobile application.