embedded 原文存档
esp8266 NONOS SDK AP UDP客户端
基于ESP8266_NONOS_SDK-2.2.0
代码和esp8266作为 UDP 服务端代码几乎相同,唯一区别的下面函数多了远程端口和远程ip地址,也就是说让8266知道远程服务器的端口和ip
/blog/esp8266-nonos-sdk-ap-udp服务端/
`void ICACHE_FLASH_ATTR ESP8266_NetCon_init(void) { ST_NetCon.type=ESPCONN_UDP;//通信协议UDP ST_NetCon.proto.udp=&ST_UDP; ST_NetCon.proto.udp->local_port=8266;//设置本地端口,客户端 ST_NetCon.proto.udp->remote_port=8888;//设置远程端口,服务端 ST_NetCon.proto.udp->remote_ip[0]=192;//设置远程ip端口,服务端 ST_NetCon.proto.udp->remote_ip[1]=168; ST_NetCon.proto.udp->remote_ip[2]=4; ST_NetCon.proto.udp->remote_ip[3]=2; espconn_regist_sentcb(&ST_NetCon,ESP8266_WIFI_Send_cb); espconn_regist_recvcb(&ST_NetCon,ESP8266_WIFI_Rev_cb); espconn_create(&ST_NetCon);//初始化UDP通信 espconn_send(&ST_NetCon,"hello i am esp8266",os_strlen("hello i am esp8266"));//主动向server发送消息 }`
主函数里面定时设置为30秒OS_Timer_1_Init(30000,1);