Article Directory
foreword
I won't talk about the steps of registering ONENET and the source program at the beginning. There are many tutorials and routines on the Internet.
Here we mainly introduce the things that need to be changed in the program when using esp8266 to access ONENET IoT.
mind Mapping
1. Onenet.c file
1. Product ID
ONENET
program
#define PROID "495815" //产品ID
2. Authentication information
ONENET
program
#define AUTH_INFO "111222333" //鉴权信息
3. Device ID
ONENET
program
#define DEVID "920389269" //设备ID
2. esp8266.c file
1. WIFI name and password
program
#define ESP8266_WIFI_INFO "AT+CWJAP=\"ONENET\",\"lyycz1314\"\r\n"
Note:
1. Here is the name and password of the WIFI connected to your computer . At that time, because there was no serial port debugging assistant, I didn't know that this part could not be connected all the time. 2. Replace ONENET with the name and lyycz1314 with the password. 3. If it doesn’t work, you can use your mobile phone to open a hotspot. 4. It seems that changing the name and password when the computer is connected to the hidden network does not work .
2. IP and port
#define ESP8266_ONENET_INFO "AT+CIPSTART=\"TCP\",\"183.230.40.39\",6002\r\n"
Note:
There is generally no need to change here, the IP and port here correspond to ONENET.
3. Packed data function (in onenet.c)
u8 velue0 = 0;
u8 velue1 = 0;
unsigned char OneNet_FillBuf(char *buf)
{
char text[32];
memset(text, 0, sizeof(text));
strcpy(buf, ",;");
memset(text, 0, sizeof(text));
sprintf(text, "value0,%d;", velue0);
strcat(buf, text);
memset(text, 0, sizeof(text));
sprintf(text, "value1,%d;", velue1);
strcat(buf, text);
return strlen(buf);
}
To transfer data is to replace the variable with the constant value here.
If the variable is not in the onenet.c file, it can be defined with extern .
For example:
extern int32_t velue2;