手机上的调试助手我设置为UDP服务器,设置好端口,然后IP就是手机的IP地址。
ESP8266的配置如下:
wifi_set_broadcast_if(0x01);
//*******************************************************************************
user_udp_espconn.proto.udp = (esp_udp *) os_zalloc(sizeof(esp_udp));//分配空间
user_udp_espconn.type = ESPCONN_UDP; //设置类型为UDP协议
user_udp_espconn.proto.udp->local_port = 2000; //本地端口:可随机设置(需大于1024)
user_udp_espconn.proto.udp->remote_port = 10500; //目标端口:保持唯一性
const char udp_remote_ip[4] = {192,168,0,102}; //目标IP地址
os_memcpy(user_udp_espconn.proto.udp->remote_ip, udp_remote_ip, 4);
//*******************************************************************************
espconn_regist_recvcb(&user_udp_espconn, user_udp_recv_cb); //接收
espconn_regist_sentcb(&user_udp_espconn, user_udp_sent_cb); //发送
espconn_create(&user_udp_espconn); //建立 UDP 传输
espconn_sent(&user_udp_espconn, "连接服务器", strlen("连接服务器"));
//*******************************************************************************
void ICACHE_FLASH_ATTR user_udp_sent_cb(void *arg) //发送
{
os_printf("\r\n发送成功!\r\n");
}
现在的问题是,手机上的UDP服务器一直没有接收到数据,并且提示“没有客户端连接”,但是8266的串口发送出来的数据提示“发送成功”。
是我的IP地址设置不对还是什么问题。
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.