{
test_q=xQueueCreate(Q_NUM,sizeof(void*));
xTaskCreate(test_task,(signedportCHAR*)"test_task",512,NULL,(1),&test_task_hdl);
//512meanstheheapsizeofthistask,512*4byte.
//NULLisapointerofparametertotest_task.
//(1)isthepriorityoftest_task.
//test_task_hdlisthepointerofthetaskoftest_task.
}
3.3. Networking Protocol Example
The networking protocol of ESP8266_RTOS_SDK is the programming of socket, including
the following examples:
• Example of UDP transmission
•
Example of TCP connection
- ESP8266 functions as TCP client
- ESP8266 functions as TCP server
3.3.1. UDP Transmission
1. Set the local port number of UDP. Below is an example of setting the port number as
1200.
#defineUDP_LOCAL_PORT1200
2. Create a socket.
LOCALint32sock_fd;
structsockaddr_inserver_addr;
memset(&server_addr,0,sizeof(server_addr));
server_addr.sin_family=AF_INET;
server_addr.sin_addr.s_addr=INADDR_ANY;
server_addr.sin_port=htons(UDP_LOCAL_PORT);
server_addr.sin_len=sizeof(server_addr);
do{
sock_fd=socket(AF_INET,SOCK_DGRAM,0);
if(sock_fd==-1){
printf("ESP8266UDPtask>failedtocreatesock!\n");
vTaskDelay(1000/portTICK_RATE_MS);
}
}while(sock_fd==-1);