ESP8266 NONOSDK Web Server 服务注意事项
一、问题
- 在用WEB访问时,无法收到回复,排查后发现是因为访问时,建立了多条链接,但程序上,只用了最原始那一个espconn,导致发到错误的链路上
- 在recv回调中,马上返回大数据,偶尔会有丢失
二、解决方法
recv后,保存当前的espconn,之后数据返回到目前这个conn
void ICACHE_FLASH_ATTR static server_recv(void *arg,char *pdata,unsigned short len){//os_printf("收到PC发来的数据:%s.\r\n",pdata);//espconn_sent((struct espconn *)arg,"已经收到\r\n",strlen("已经收到\r\n"));//串口数据透传//GPIO_OUTPUT_SET(GPIO_ID_PIN(12),1); //os_printf("server data = %d %02x %02x %02x %02x \r\n",len,pdata[0],pdata[1],pdata[2],pdata[3]);//uart0_tx_buffer(pdata,len);//GPIO_OUTPUT_SET(GPIO_ID_PIN(12),0); connect_conn = arg;webserver_recv(&web_conn,pdata,len);}
/******************************************************************************* FunctionName : data_send* Description : processing the data as http format and send to the client or server* Parameters : arg -- argument to set for client or server* responseOK -- true or false* psend -- The send data* Returns : *******************************************************************************/ static void ICACHE_FLASH_ATTR data_send(void *arg, bool responseOK, char *psend) {uint16 length = 0;char *pbuf = NULL;char httphead[256];struct espconn *ptrespconn = arg;int *pfd=arg;int fd=*pfd;os_memset(httphead, 0, 256);if (responseOK) {os_sprintf(httphead,"HTTP/1.0 200 OK\r\nContent-Length: %d\r\nServer: lwIP/1.4.0\r\n",psend ? strlen(psend): 0);if (psend) {os_sprintf(httphead + strlen(httphead),"Content-type: text/html; charset=utf-8\r\nPragma: no-cache\r\n\r\n");length = strlen(httphead) + strlen(psend);pbuf = (char *)os_zalloc(length + 1);os_memcpy(pbuf, httphead, strlen(httphead));os_memcpy(pbuf + strlen(httphead), psend, strlen(psend));} else {os_sprintf(httphead + strlen(httphead), "\n");length = strlen(httphead);}} else {os_sprintf(httphead, "HTTP/1.0 400 BadRequest\r\nContent-Length: 0\r\nServer: lwIP/1.4.0\r\n\n");length = strlen(httphead);}if (psend) {//new_tcp_send(fd,pbuf,length);espconn_sent(ptrespconn, pbuf, length);os_printf("send\r\n\r\n%s\r\n\r\n",pbuf);} else {//new_tcp_send(fd,httphead,length);espconn_sent(ptrespconn, httphead, length);}if (pbuf) {os_free(pbuf);pbuf = NULL;} }
定时器100ms后再发送数据
void web_send_timer_cb() {//static uint8_t time = 0;data_send(connect_conn, true, html);os_free(html);html = NULL;//os_timer_arm(&web_send_timer,200,0);/*if(time++==1){time = 0;os_timer_disarm(&web_send_timer);os_free(html);html = NULL;}*/}
html = (char *)os_zalloc(WEBCONFIG_SIZE);if(html == NULL){os_printf("os_zalloc error!\r\n");goto _temp_exit;}#if 1os_memset(html,0,WEBCONFIG_SIZE);os_strcpy(html,(char *)WEB_CONFIG);#else ret = spi_flash_read(964*1024, (uint32 *)html, WEBCONFIG_SIZE); // start address:0x10000 + 0xC0000if(ret != SPI_FLASH_RESULT_OK){os_printf("spi_flash_read err:%d\r\n", ret);os_free(html);html = NULL;goto _temp_exit;}#endifhtml[WEBCONFIG_SIZE] = 0; // put 0 to the endos_timer_disarm(&web_send_timer);os_timer_setfn(&web_send_timer, web_send_timer_cb , NULL); //a demo to process the data in uart rx bufferos_timer_arm(&web_send_timer,100,0);
ESP8266 NONOSDK Web Server 服务注意事项相关推荐
- 利用 python 的 http.server 包快速搭建web server 服务
文章目录 利用 python 的 http.server 包快速搭建web server 服务 一.背景说明 二.一行代码解决搭建轻量级 web server 三.其外其他的配置可以参考下列网址 利用 ...
- python建立一个简单的server_使用Python创建一个简易的Web Server
Python 2.x中自带了SimpleHTTPServer模块,到Python3.x中,该模块被合并到了http.server模块中.使用该模块,可以快速创建一个简易的Web服务器. 我们在C:\U ...
- C# .net基于Http实现web server(web服务)
C# .net基于Http实现web server(web服务) 原文:C# .net基于Http实现web server(web服务) 什么是 web server? 百度百科是这么解释的: We ...
- ESP8266开发之旅 WebServer篇⑥ DS18B20 Web Server
文章目录 1.前言 2.Installing Libraries for DS18B20 3.代码 4.测试结果 授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享 ...
- 网络云存储技术Windows server 2012 (项目二十 基于NLB的企业Web站点服务部署)
网络云存储技术Windows server 2012 (项目二十 基于NLB的企业Web站点服务部署) 前言 网络存储技术,是以互联网为载体实现数据的传输与存储,它采用面向网络的存储体系结构,使数据处 ...
- goahead如何使用cgi服务_GoAhead Web Server的特性及技术
最近一段时间,一直在搞嵌入式开发,公司一产品需要升级改造,结果发现应用的是Linux平台和GoAhead的web服务器,所以经过多方的了解,现把总结内容总结一下,大家一起和我来学习GoAhead吧. ...
- ESP8266 NodeMCU Web 服务器:在仪表盘中显示传感器读数
了解如何使用 ESP8266 NodeMCU 构建网络服务器以在仪表盘中显示传感器读数.例如,我们将以两种不同的仪表显示 BME280 传感器的温度和湿度:线性和径向.您可以轻松修改项目以绘制任何其他 ...
- 用thttpd做Web Server
httpd是busybox中自带的web server,功能弱,不支持认证和CGI.thttpd和boa都支持认证CGI,功能比较全,Boa是一个单任务的小型http服务器,设计的小型系统不要数据库操 ...
- Nginx负载均衡:分布式/热备Web Server的搭建
Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...
最新文章
- TOJ4537: n阶行列式
- 手机重写alert方法(去除网址和关闭网页按钮)
- Qt Creator语义突出显示
- 1.5 引入解释性变量
- 我的Android进阶之旅------Android中高低API版本兼容使用@TargetApi或者@SuppressLint(NewApi)...
- 十进制大数的加法运算
- linux下汇编语言开发总结
- vs2008 代码对齐方式
- 对 String 字符串的理解
- 微橙人人店 php,最新微橙人人店分销3.5.7整站源码,全开源任意二开,新增及修复多项功能,附升级补丁...
- mysql 保存富文本的类型_富文本编辑器内容在mysql数据库以什么类型保..._网络编辑_帮考网...
- C语言数组——一维数组实例详解
- 数字盲打怎么练_如何提高盲打速度?键盘指法练习方法
- 操作系统-软件架构设计
- ERROR 1146 (42S02): Table '库名.表名' doesn't exist
- 【Django】 终端打印出错信息
- 使用Python的PyPD创建PDF文档
- 【JVM学习篇】剖析JVM类加载机制
- 1658 页的《Java 面试突击核心讲》在牛客网火了,完整版 PDF 开放下载!
- 毕业设计 基于STM32单片机的二轮平衡小车