language:

Ai-Thinker Technology

Trace: OneNET AT Command

OneNET AT Command



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

OneNET AT Command

Overview

Describe the extended command set function and usage method of the WIFI module.

The extended instruction set is mainly used in the OneNet open platform of China Mobile Internet of Things to realize device data upload and command control.

The original AT command, Wifi function AT command, TCP/IP toolbox AT command, etc. of the module remain unchanged.

Module expansion command function requirements

Introduction to module extension instruction design

The module extension instruction is designed to realize data communication between terminal equipment and platform server. The terminal equipment mainly

Composed of WIFI module and MCU main control module, the function of module extension command is mainly to connect the platform to the protocol (Http protocol

And EDP protocol) implant WIFI modules, and then encapsulate them to provide users with an open command interface. Users use these

Commands can easily realize the data communication between the terminal device and the platform server, the platform server, WIFI module and MCU

The relationship between the three main control modules is shown in the figure below.

Figure 1 Relationship diagram of platform server, WIFI module and MCU main control module

Module extension instruction design ideas

The design of the module extension instruction is mainly designed around the data communication between the terminal equipment and the platform, which mainly includes the following processes and steps.

  • Step 1: Main Apikey parameter curing—terminal device developer registers company management user account on OneNET platform,

And create a new project under this account. A project corresponds to a MasterKey (also called master Apikey) on the platform. The master Apikey applied for by the platform is sent to the WIFI module through the serial port tool or the program code on the MCU. The WIFI module will This parameter is programmed in a fixed address space.

  • Step 2: Platform device definition—The WIFI module uses the main Apikey to apply for the device ID and device Apikey of the device on the platform, and also saves the successfully applied parameters. The subsequent WIFI module can use the device saved by itself

ID and device Apikey complete data communication with the platform server.

  • Step 3: Establish a device connection—The data communication of the WIFI module adopts the EDP protocol, and the EDP protocol is built on

Based on TCP/IP, to complete the device connection, you must first make sure that the WIFI module is connected to an available AP, then the WIFI module and the platform server establish a TCP connection, and finally use the device ID and device Apikey to encapsulate the EDP connection message to establish the device connection.

  • Step 4: Data upload — The WIFI module receives the data from the main control MCU, then encapsulates it into an EDP message, and sends it to the platform server.
  • Step 5: Command control—The WIFI module receives the EDP command control message from the platform server, parses the message content, and then sends it to the master MCU.

The data flow between the platform server, WIFI module and MCU main control module is shown in the figure below.

Figure 2 Data flow chart of platform server, WIFI module and MCU main control module

Naming rules and instructions for module extension commands

The extended command maintains the original AT command naming style and adopts the AT+CIOT method.

Main functions and classifications realized by module extension instructions

The module expansion commands are temporarily designed to be 18, and more functions can be expanded in the future.

  • Basic parameter query setting function
  • Platform business definition function (RESTful API using HTTP protocol)
  • Platform device connection function (using EDPSDK provided by the platform)
  • Platform data upload function (using EDPSDK provided by the platform)
  • Platform command control function (using EDPSDK provided by the platform)

Detailed description of WIFI module extension instructions

List of WIFI module extension commands

WIFI module extension AT command
Command Description
AT+CIOT Query curing parameters;
AT+CIOTMKEY Query the master Apikey;
AT+CIOTMKEYA Set master Apikey;
AT+CIOTINIT Start parameter creation;
AT+CIOTID Query device operation commands;
AT+CIOTIDC Delete device operation command;
AT+CIOTKEY Query device Apikey operation command;
AT+CIOTKEYC Delete device Apikey operation command;
AT+CIOTSTATUS Query the connection status of the WIFI module and the IoT platform;
AT+CIOTSTART Start sending data to the IoT platform;
AT+CIOTDAT Send small data to IoT platform;
AT+CIOTBINSET Set the information of binary file upload;
AT+CIOTBINSEND Send binary file content;
AT+CIOTBINEND End binary file;
AT+CIOTQUIT Stop data transmission to the IoT platform;
AT+CIOTSEND One-time transmission of small data to the IoT platform;
AT+CIOTPING Heartbeat command;
+IOTCMD Control commands sent by the IoT platform;

The AT command version on this page is v1.3, please download the onenet_at_v1.3 firmware.

The AT command version v1.4 has changed some commands, deleted some AT commands, and added new AT commands.

Onenet_at_v1.4 firmware command modification onenet_at_command_v1.4.pdf

Error code definition

Error code description Error code
WLAN error -100
Network error -101
No master key -102
No equipment ID -103
No equipment key -104
The device is offline -105
Invalid operation -106
File sending error -107
Parameter error -108
Device connection failed -109
Failed to send data -110
Device disconnection failed -111
Device parameter initialization failed -112

Instruction format description

(1) Format description

<>: indicates the part that must be included
[]: indicates an optional part

(2) Command message format

AT+<CMD>[op][para-1,para-2,para-3,......]<CR>
a) AT+: Command message prefix
b) CMD: command string
c) [op]: Command operator, which refers to parameter setting or query. It can be: 1, "=": means parameter setting 2, "none": means parameter query
d) [para-n]: Input for parameter setting, "?" for query command
e) <CR>: end character, carriage return, ASCII code 0x0d

(3) Response message format

+<RSP>=[para-1,para-2,para-3,......]<CR><LF>
a) +: Response message prefix
b) RSP: the corresponding string, including:
  1. "OK": indicates success
  2. "ERR": indicates failure
c) [para-n]: The parameter returned during query, or the error code when an error occurs
d) <CR>: ASCII code 0x0d
e) <LF>: ASCII code 0x0a

AT command

AT+CIOT

Description: Query whether the main APIKEY of the WIFI module, the device ID and the device APIKEY have been solidified.

Function: Query whether the parameter exists
Query command format: Correct response:
AT+CIOT?<CR> +OK<CR><LF>
There are three cases of error response:
+ERR=-102<CR><LF>
+ERR=-103<CR><LF>
+ERR=-104<CR><LF>
Parameters: None

Note: The module needs to solidify the main APIKEY, device ID and device APIKEY three parameters, the current length of APIKEY is 28

Length in bytes, but it may be extended in the future; the length of the device ID is also extended.

AT+CIOTMKEY

Note: Query whether the main APIKEY of the WIFI module has been solidified.

Function: Query whether the master key exists
Query command format: Correct response:
AT+CIOTMKEY?<CR> +OK<CR><LF>
Error response:
+ERR=-102<CR><LF>
Parameters: None

AT+CIOTMKEYA

Description: Set the main APIKEY parameter of the WIFI module. If the main APIKEY already exists locally, executing this command will overwrite

For the existing master APIKEY, delete the device ID and device APIKEY created by the original master APIKEY.

Function: set and solidify the master key
Command format: Correct response:
AT+CIOTMKEYA=[mkey]<CR> +OK=[mkey]<CR><LF>
Error response:
+ERR<CR><LF>
Parameters: mkey-based APIKEY

AT+CIOTINIT

Note: AT+CIOTINIT is used to start the creation of device ID and device Apikey parameters or the verification of the validity of the parameters.

Before setting up the parameters, the master Apikey must be solidified, and the WIFI module uses the master Apikey to apply for the device ID from the platform server

Create the device, and then create the device Apikey. After the parameters are successfully created, the WIFI module needs to

The parameters are solidified in its own parameter storage area.

If the local master Apikey, device ID and device Apikey all exist, you only need to go to the platform server to query the device ID and

Whether the device Apikey exists. (The platform query parameter is to ensure that the corresponding device on the platform is not deleted), if the platform checks

If the query fails, you must clear the device ID and device APIKEY, and then use the main APIKEY to recreate the device on the platform to obtain

Take the new device ID and device APIKEY, and then perform curing.

Function: Start parameter creation
Command format: Correct response:
AT+CIOTINIT<CR> +OK<CR><LF>
Error response:
+ERR=-100<CR><LF>
+ERR=-101<CR><LF>
+ERR=-102<CR><LF>
+ERR=-112<CR><LF>
Parameters: None

AT+CIOTID

Description: Query device ID

Function: Query whether the device ID exists
Query command format: Correct response:
AT+CIOTID?<CR> +OK=[dev_id]<CR><LF>
Error response:
+ERR=-103<CR><LF>
Parameter: dev_id

AT+CIOTIDC

Note: To delete a device ID, you must delete the corresponding device APIKEY.

Function: Delete device ID
Command format: Correct response:
AT+CIOTIDC<CR> +OK<CR><LF>
Error response:
+ERR<CR><LF>
Parameters: None

AT+CIOTKEY

Description: Query device APIKEY

Function: query equipment apikey
Query command format: Correct response:
AT+CIOTKEY?<CR> +OK=[apikey]<CR><LF>
Correct response:
+ERR=-104<CR><LF>
Parameters: apikey equipment APIKEY

AT+CIOTKEYC

Note: Delete the device APIKEY without deleting the device ID.

Function: Delete device APIKEY
Command format: Correct response:
AT+CIOTKEYC<CR> +OK<CR><LF>
Error response:
+ERR<CR><LF>
Parameters: None

AT+CIOTSTATUS

Description: The command function is to query the connection status of the device.

Function: Query device connection status
Command format: Response:
AT+CIOTSTATUS<CR> +OK=state<CR><LF>
Parameter: state
² device_up, device login
² Device_down, the device is not logged in

AT+CIOTSTART

Description: The command function is to establish a device connection and start data transmission.

Function: establish device connection, start data sending
Command format: Correct response:
AT+CIOTSTART=[encrypt]<CR> +OK<CR><LF>
Error response:
+ERR=-108<CR><LF>
+ERR=-109<CR><LF>
Parameter: encrypt
0, do not use encryption
1, Use encryption

AT+CIOTDAT

Description: The command function is to transfer small data long

Function: Send data
Command format: Correct response:
AT+CIOTDAT=[num,key_1,time_1,value_1…key_n,time_n,value_n]<CR> +OK<CR><LF>
Error response:
+ERR=-108<CR><LF>
+ERR=-110<CR><LF>
Parameters:
Num: the number of data records
key: Data sampling name
time: Data sampling time
value: Data sampling value
Description:
Time format: such as 2016-01-01 00:00:00 Year, month and day are separated by ‘-’ Hour, minute and second are separated by ‘:’
If there is no sampling time, leave the time item blank, and the format is AT+CIOTSTART=[kay,,value]<CR>

AT+CIOTBINSET

Description: Set the header information sent by the binary file. Due to the limitation of the data buffer size, the binary file is generally

When uploading, first pass the EDP header to the server, and then upload the binary file data in pieces.

File upload. (AT+CIOTBINSET, AT+CIOTBINSEND and AT+CIOTBINEND used in combination)

Function: Set Binary File
Command format: Correct response:
AT+CIOTDATBINSET=[des,bin_lens]<CR> +OK<CR><LF>
Error response:
+ERR=-108<CR><LF>
Parameters:
des: The data stream of the binary file ID
bin_lens: total file length
Explanation:

AT+CIOTBINSEND

Note: When sending binary file data, you only need to judge that the current length is equal to the number of data when checking the parameters.

Function: Send binary files
Command format: Correct response:
AT+CIOTBINSEND=[bin_len,bin_data]<CR> +OK<CR><LF>
Error response:
+ERR=-108<CR><LF>
Parameters:
bin_len: the length of the data sent this time
bin_data: data (data format is hexadecimal format, such as 01AA55 represents data OX01, OXAA, OX55)

Note: Correct response + OK means WIFI successfully sent this data network.

AT+CIOTBINEND

Description: Set the end mark of binary file sending and return the status of file sending.

Function: end binary file
Command format: Correct response:
AT+CIOTBINEND<CR> +OK=<CR><LF>
Error response:
+ERR=-107<CR><LF>
Parameters: None

AT+CIOTQUIT

Description: The function realized by the instruction is to disconnect the device and stop data sending.

Function: Disconnect device connection
Command format: Correct response:
AT+CIOTQUIT<CR> +OK<CR><LF>
Error response:
+ERR=-111<CR><LF>
Parameters: None

Note: The EDP protocol does not disconnect the device connection request message. AT+CIOTQUIT must realize the function of disconnecting the device and directly disconnect the TCP connection with the server to achieve the purpose of disconnecting the device.

AT+CIOTSEND

Description: Send small data, the function is equivalent to the instruction set (AT+CIOTSTART; AT+CIOTDAT; AT+CIOTQUIT) instruction

The internal execution process is as follows:

Function: Send sample data
Command format: Correct response:
AT+CIOTDAT=[encrypt,num,kay_1,time_1,value_1…kay_n,time_n,value_n]<CR> +OK<CR><LF>
Error response:
+ERR=-108<CR><LF>
+ERR=-109<CR><LF>
+ERR=-110<CR><LF>
+ERR=-111<CR><LF>
Parameters:
encrypt: Whether to encrypt
num: Number of data records
0, no encryption
1, encryption
key: Data sampling name
time: Data sampling time
value: Data sampling value
Description:
Time format: e.g. 2016-01-01 00:00:00 year, month and day separated by'-' hour, minute and second separated by':', if there is no sampling time, the time item is left blank, the format is AT+CIOTSEND=[encrypt ,kay,,value]<CR>

AT+CIOTPING

Function: Heartbeat
Command format: Correct response:
AT+CIOTPING<CR> +OK<CR><LF>
Error response:
+ERR<CR><LF>
Parameters: None

+IOTCMD

Note: This command is sent by the WIFI module to the MCU, when the WIFI module receives the control command sent by the IoT platform

When, send “+IOTCMD=[datalen,data]” to the serial port, where “+IOTCMD:” is just an identifier for the MCU, which means

This is a control command issued by the platform.

The platform server sends control commands to the device
Event format: Parameters:
+IOTCMD=[datalen,data]<CR><LF> datalen: data length of control command
data: control command content

Instruction usage example

Single upload small data

(1) AT+CIOT? //Query master APIKEY existence
(2) AT+CIOTINIT //Create device parameters, the platform queries the device parameters—that is, the validity verification of the parameters
(3) AT+CIOTSEND //Upload one piece of data at a time

Upload small data cyclically

(1) AT+CIOT? //Query master APIKEY existence
(2) AT+CIOTINIT //Create device parameters, the platform queries the device parameters—that is, the validity verification of the parameters
(3) AT+CIOTSTART //Start data transmission
(4) AT+CIOTDAT //Upload small data
......
(5) AT+CIOTDAT //Upload small data
(6) AT+CIOTQUIT //Stop data sending

Upload binary file

(1) AT+CIOT? //Query master APIKEY existence
(2) AT+CIOTINIT //Create device parameters, the platform queries the device parameters—that is, the validity verification of the parameters
(3) AT+CIOTSTART //Start data transmission
// Upload the first file
(4) AT+CIOTBINSET //Set the binary file
(4) AT+CIOTBINSEND //Send binary file
(5) AT+CIOTBINEND //End binary file
//Upload the Nth file
//Upload the first file
(6) AT+CIOTBINSET //Set the binary file
(7) AT+CIOTBINSEND //Send binary files
(8) AT+CIOTBINEND //End binary file
(9) AT+CIOTQUIT //Stop data sending