EasyManua.ls Logo

Espressif Systems ESP8266EX - Networking Protocol Example; UDP Transmission

Espressif Systems ESP8266EX
41 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
!
3. Sample Codes
{
󰲧󰲧󰲧󰲧test_q󰲧=󰲧xQueueCreate(Q_NUM,sizeof(void󰲧*));
󰲧󰲧󰲧󰲧xTaskCreate(test_task,(signed󰲧portCHAR󰲧*)"test_task",󰲧512,󰲧NULL,󰲧(1),󰲧&test_task_hdl󰲧);
//󰲧512󰲧means󰲧the󰲧heap󰲧size󰲧of󰲧this󰲧task,󰲧512󰲧*󰲧4󰲧byte.󰲧
//󰲧NULL󰲧is󰲧a󰲧pointer󰲧of󰲧parameter󰲧to󰲧test_task.
//󰲧(1)󰲧is󰲧the󰲧priority󰲧of󰲧test_task.
//󰲧test_task_hdl󰲧is󰲧the󰲧pointer󰲧of󰲧the󰲧task󰲧of󰲧test_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.
#define󰲧UDP_LOCAL_PORT󰲧󰲧1200
2. Create a socket.
LOCAL󰲧int32󰲧sock_fd;
struct󰲧sockaddr_in󰲧server_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("ESP8266󰲧UDP󰲧task󰲧>󰲧failed󰲧to󰲧create󰲧sock!\n");
󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧󰲧vTaskDelay(1000/portTICK_RATE_MS);
󰲧󰲧󰲧󰲧󰲧}
}while(sock_fd󰲧==󰲧-1);
Espressif
! /!17 37
2017.05

Other manuals for Espressif Systems ESP8266EX

Related product manuals