Click here to download LED lamp sample code for rapid development of SoC scheme
GizLamp is a simple and common smart product, whose hardware circuitry and the program are not complicated. We will use the Gokit3(S) development board and Gizwits IoT Cloud to demonstrate how to upgrade a traditional light bulb into a low-cost smart light which supports remote control.
This document takes the GizLamp project as an example to demonstrate how to quickly connect the device to Gizwits IoT Cloud to achieve hardware intelligence with a Gokit3 (S) development board based on the SoC scheme on the ESP8266 module.
The Gizwits developer account is used for device connection, device management, OTA service, MCU development and other functions.
Registration link: https://dev.gizwits.com/en/developer/
After registration and logging into the Gizwits Developer Center, click the “Create New Product” button in the upper right corner of the Developer Center. Then type the new product name “GizLamp”, and select “Wi-Fi/Mobile” network access plan as shown below.
The Data Point refers to the functionality abstraction of a device product, which describes the product’s capabilities and its parameters. After Data Points are created, the data format of the device and the cloud communication can be determined, and the device and Gizwits IoT Cloud can mutually recognize the data exchanged between the device and Gizwits IoT Cloud.
For more details, click “Data Point tutorial” in the upper right corner of Data Point page of Developer Center.
Take the project “GizLamp” as an example to briefly describe the relationship between the cloud Data Points and the functions of the product. This project “GizLamp” needs to implement the function of turning on and off the lamp remotely, so you should create a “Boolean” Data Point in the cloud to complete this task, as shown below:
After adding the Data Point, click “Apply” as the figure below.
In order to lower the development barrier, shorten the development cycle, and reduce the development investment, Gizwits has rolled out Gizwits MCU Code Auto-Generator, which generates the device-side code for the corresponding product based on Data Points defined for the product. The automatically generated MCU code implements the packet encapsulation and parsing of the Gizwits communication protocol, the conversion logic of sensor data and communication data. All of these functions are integrated into a simple API set. When the device receives data from the cloud or the App, the program converts the data into corresponding events and notifies the application layer. You only needs to add the sensor control functions to the corresponding event handlers to complete the product development.
After creating the product Data Point, click “MCU Development” on the left navigation pane and select “SoC Scheme. Currently the default “Hardware Platform” for the SoC scheme is ESP8266. Scroll down to the bottom to click “Generate Code” and wait for about 30 seconds to generate the gizLamp code package based on ESP8266. Then download the package. So that the downloaded file name is too long and contains ProductKey of the product, rename the downloaded file name to “GizLamp” as shown below:
Note: Gizwits MCU Code Auto-Generator currently only supports ESP8266 for the SoC scheme.
In the SoC source code generated automatically by Gizwits IoT Cloud, you only need to care about the files under “GizLamp\app”.
To add 8266 peripherals,
To process commands sent from App through the cloud,
In this SoC source code, you just focus on above points. The module communication and the underlying drivers do not need developers to process and modify.
“WeChat Pet House for Gokit3(S) ESP8266 V03000003” is a case implemented by Gizwits engineers using Gokit3(S) board based on the ESP8266 hardware platform. The source code of this case includes peripheral drivers for infrared sensor, temperature and humidity sensor, small motor, RGB light, key, etc., which can be directly used on any Gokit3(S) board, or can be ported to other ESP8266 boards for use. The source code is as follows:
Note: For an in-depth understanding of the source code of WeChat Pet House case, you can refer to the following link:
Source code exploration of WeChat Pet House
After completing the above preparation for the SoC code files, modify the corresponding c file below.
Use Sublime software to open the entire project, and modify two files as follows:
The following picture shows where to modify the code.
Other instructions for the automatically generated SoC source code
The code snippets for Key1 and Key2.
1) Key1
Used to reset Wi-Fi module or drop it into production mode
2) Key2
Used to trigger the module enter AirlLink or SoftAP configuration mode
First add the following header file in user_main.c
1 | #include "driver/hal_rgb_led.h" |
Then add the following two function calls in the “//user init” section of user_init() function to initialize the RGB light on Gokit3. The definitions of these two functions can be found in hal_rgb_led.c
1 | //LED initialization function calls |
Then add the following header file in gizwits_product.c
1 | #include "driver/hal_rgb_led.h" |
Then add the following function calls in the “//user handle” section of gizwitsEventProcess() function to drive the RGB light on Gokit3 to turn it on and off. To control the RGB light color combination, you can also modify the parameters of the rgbControl() function, each of which is set to a integer in the range of “0~254”. The rgbControl function can be found in the “hal_rgb_led.c” file.
1 | //LED control function calls |
After completing the above actions, conduct the SoC code compiling environment setup as follows.
See Set up development environment
Note: It is recommended to use Virtualbox and Espressif official development environment for secondary development.
See Code compilation
See Download firmware
For product debug, see here.
For product release, see here.
After the above steps finished, the entire project development is complete. If you need more open source projects and want to discuss with other developers, you can visit Gizwits Developer Community: http://club.gizwits.com/forum.php
Click here to download UART0 tutorial for ESP8266-SoC scheme.