Ai-Thinker Technology

OneNET SDK Development

Please poke the full range of modules to purchase:Anxinke official Taobao shop

OneNET SDK Development

ESP8266 OneNET SDK uses EDP protocol, which can realize ESP8266 and OneNET platforms.

Let's use ESP8266 OneNET SDK to develop an example of bulb light.

Register OneNET platform account

* Log in to

* Register a platform account

Enter the developer center

* Click to create product

* Fill in product parameters

We choose wifi, open protocol, EDP protocol, and named it smart bulb light.

* The creation is complete.

The product ID and APIKey in the above column are two important parameters, and these two parameters need to be filled in the SDK.

The picture is a platform parameter under my own account. Do not fill in my parameter, otherwise you cannot log in to the platform to control the device.

SDK development

1. Unzip

2. Read the source code

* The app/onenet directory is the source code of OneNET, which mainly includes HTTP protocol and EDP protocol. The encryption part has not yet passed the test, and the _ENCRYPT macro definition must be closed when compiling.

* Fcmd is used for serial port debugging. If there is an unclear api, you can directly enter the function name in the serial port debugging assistant to test directly. Add the function you want to test in fcmd_cfg.h.

* The fsm directory. In order to ensure the readability and modifiability of the source code, a simple message loop state machine framework was written on the basis of esp8266 sdk. Divided into two tasks, driver_task and network_task. The state machine entry functions are driver_actor and network_actor respectively. The Network task maintains the jump of the network status and the start and stop of the onenet service. fsm provides timers, message distribution, and state jump functions.

* Main directory. Onenet_app.c in this directory is several callback functions for receiving data of onenet service, in which data points are received and processed and the RGBWS state of the bulb light is controlled.

* Upgrade catalog. Firmware upgrade interface, now the url address is the address of Anxinke server, users can modify to point to their own server. The function os_post_message(1,9,0) can be upgraded in the serial port, provided that the networked device is connected to the network.

* Modify the parameters of the onenet project. The project parameters can be modified in network_task.c, which are saved in flash.

The api of the onenet project parameter.

API related to onenet app parameters.

Just change USER_MASTER_APIKEY and USER_PRODUCT_ID to the parameters under your own project.

The project parameters of onenet are stored in sector 0x79.

Onenet's app parameters are stored in sector 0x7c.

Compile and download

* Open cygwin, cd to the root directory of the project, and execute the ./ 1 command to compile.

* Open esp8266 download tool, and download the firmware according to the following address. We can use nodemcu to test and download this firmware.

When downloading the firmware for the first time, you need to erase both the onenet project parameter area and the onenet app parameter area. You can use CombineBin to merge the firmware so that other sectors will be filled with 0xFF.

Power Distribution Network

Open the serial port debugging assistant and watch the print log.

Among them, start_continue represents the number of continuous restarts, which will be cleared to 0 after 3s.

* Restart the network distribution 3 times

* During the connection process, you will see the process of registration, login, and heartbeat in sequence. This is the process of communication between the device and onenet, and the device is now connected to onenet. The device_id will be printed out in the log printing.

Create web application interface

1. Find the device_id and enter the device interface.

2. Send commands to the device

Device received command

3. Use graphical interface to control equipment

4. Use app to control equipment

The app interface and the platform interface are actually similar. You can see all the projects, and all the equipment under the project.

Device cloud APP QR code download