TCPserver配置步骤:
1.将ESP8266配置为AP模式
参考day4
2.配置相关结构体
type中成员proto必须先申请内存再使用
TPCserver需配置参数;
type:设置为0x10(TCP模式)
proto.tcp->local_port:设置端口号(本机)
3.建立TCP接口
将上面创建结构体地址传入函数即可
4.设置超时时间
5.注册TCP成功连接回调函数
回调函数的形参必须与手册中相同,回调函数调用后,TCP通信建立
代码如下,实现客户端发送”K“亮灯,发送“G”关灯,串口显示连接主机信息
/*******************************结构体定义**********************************/
struct softap_config wif; //WIFI AP配置结构体
struct espconn TCP_s; //TCP配置结构体
/***********************************************************************/
os_timer_t tim1;
void ICACHE_FLASH_ATTR delay(u32 C_time) //毫秒延时函数
{
for(;C_time>0;C_time--)
os_delay_us(1000);
}
void esprr(void *arg,char *pusrdata,unsigned short len)
{
struct espconn *U_arg = arg;
remot_info * P_port_info = NULL;
char ch[32] = "接收成功";
os_printf("接收数据:%s\n",pusrdata); //串口显示接收信息
espconn