开发板发送图片信息到服务器,【RT1052】开发板通过8266服务器向客户端发送数据...

【RT1052】开发板通过8266服务器向客户端发送数据

之前做的DEMO都是手机端发送数据到8266服务器再发送到开发板以实现手机控制开发板,本帖做另一个方向的DEMO即开发板通过8266服务器向手机网页客户端发送数据,发送的数据多样化,凡是从开发板端获取或计算出来的数据,均可发送至手机网页客户端,本DEMO以开发板的RX8010芯片为基础,发送日期和时间数据,发送的数据格式和协议可自定义,只需要协调开发板LPUART2串口发送的数据格式和8266串口接收的数据格式,让两者成功握手即可,常见方法为加入起始字节或结束字节,由于8266端也带有串口空闲判断,也可接收不定长数据,因此不需要加入结束字节。

在上帖网页服务器基础上添加四个标签即可,用于显示温度、湿度、日期和时间,在本DEMO中不使用DHT11而只使用RX8010,因此温湿度数据为预设的11℃,22%:

51e513925e4c196db8682dedaa63e8f8.gif

Screenshot_20181203-000140.jpg (194.9 KB, 下载次数: 9)

2018-12-3 00:19 上传

网页服务器代码如下:

void Main_Page_Handler()

{

unsigned char led_switch=0,input_text1_buffer_length;

String input_text1_buffer;

if (server.hasArg("radio1"))

{

if (server.arg("radio1")=="0")

{

led_switch=0x02;

radio1_flag=0;

}

else if(server.arg("radio1")=="1")

{

led_switch=0x01;

radio1_flag=1;

}

}

if (server.hasArg("input_text1"))

{

input_text1_buffer=server.arg("input_text1").c_str();

}

Serial.write(0x01);

Serial.write(led_switch);

Serial.write(input_text1_buffer.length());

Serial.print(input_text1_buffer);

Serial.write(0x0d);

Serial.write(0x0a);

String str;

str +=  "";

str +=  "

";

str += str_title;

str +=  "

";

str +=  "

632712687463f62c6813a82832d34247.gifaleGoldenRod\">";

str +=  "

";

str +=  "

";

str +=  str_radio1_title;

str +=  "";

if(radio1_flag)

{

str +=  "";

str +=  "";

str += str_radio1_1;

str +=  "";

str +=  "";

str +=  "";

str += str_radio1_2;

str +=  "

";

}

else

{

str +=  "";

str +=  "";

str += str_radio1_1;

str +=  "";

str +=  "";

str +=  "";

str += str_radio1_2;

str +=  "


";

}

str +=  "";

str +=  str_input1;

str +=  "

\"value=value.replace(/[\\u4E00-\\u9FA5]/g,'')\" >
";

str +=  "

str +=  str_submit;

str +=  " \"style=\" width:200px; height:80px; font-size:60px; \" name=\"button1_set\" οnclick=\"submit();\">
";

str +=  "";

str += str_temp_title;

str += str_temp;

str += str_temp_sym;

str +=  "
";

str +=  "";

str += str_humi_title;

str += str_humi;

str +=  "
";

str +=  "";

str += str_date_title;

str += str_date;

str +=  "
";

str +=  "";

str += str_time_title;

str += str_time ;

str +=  "
";

str += "

";

server.send(200,"text/html",str);

}

8266接收串口数据的判断函数:

String str_temp,str_humi,str_date,str_time;

char char_uart_buff[16];

void loop()

{

String comdata;

server.handleClient();

comdata = "";

while (Serial.available() > 0)

{

comdata += char(Serial.read());

delay(2);

}

if (comdata.length()>0&&comdata[0]==0x01)

{

Serial.println(comdata);

char_uart_buff[0]=comdata[1]/10+'0';

char_uart_buff[1]=comdata[1]%10+'0';

//temp

char_uart_buff[2]=comdata[2]/10+'0';

char_uart_buff[3]=comdata[2]%10+'0';

//humi

char_uart_buff[4]=comdata[3]/10+'0';

char_uart_buff[5]=comdata[3]%10+'0';

//year

char_uart_buff[6]=comdata[4]/10+'0';

char_uart_buff[7]=comdata[4]%10+'0';

//month

char_uart_buff[8]=comdata[5]/10+'0';

char_uart_buff[9]=comdata[5]%10+'0';

//mdate

char_uart_buff[10]=comdata[6]/10+'0';

char_uart_buff[11]=comdata[6]%10+'0';

//hour

char_uart_buff[12]=comdata[7]/10+'0';

char_uart_buff[13]=comdata[7]%10+'0';

//min

char_uart_buff[14]=comdata[8]/10+'0';

char_uart_buff[15]=comdata[8]%10+'0';

//sec

str_temp="";

str_humi="";

str_date="";

str_time="";

str_temp+=char_uart_buff[0];

str_temp+=char_uart_buff[1];

str_humi+=char_uart_buff[2];

str_humi+=char_uart_buff[3];

str_humi+='%';

str_date+=char_uart_buff[4];

str_date+=char_uart_buff[5];

str_date+='-';

str_date+=char_uart_buff[6];

str_date+=char_uart_buff[7];

str_date+='-';

str_date+=char_uart_buff[8];

str_date+=char_uart_buff[9];

str_time+=char_uart_buff[10];

str_time+=char_uart_buff[11];

str_time+=':';

str_time+=char_uart_buff[12];

str_time+=char_uart_buff[13];

str_time+=':';

str_time+=char_uart_buff[14];

str_time+=char_uart_buff[15];

}

}

1052开发板端发送数据的函数:

LPUART2_Send_Char(0x01);

LPUART2_Send_Char(11);

LPUART2_Send_Char(22);

LPUART2_Send_Char(year);

LPUART2_Send_Char(month);

LPUART2_Send_Char(mdate);

LPUART2_Send_Char(hour);

LPUART2_Send_Char(min);

LPUART2_Send_Char(sec);

固定格式,起始字节第0个字节为0x01,第1和第2个字节为温度和湿度,分别为11和22,然后依次是年、月、日、时、分、秒,静态页面如下:

由于8266端只使用了html的get方法,没有加入ajax控件,无法做到自动定时刷新,只能手动刷新显示时间:

51e513925e4c196db8682dedaa63e8f8.gif

12.gif (2.92 MB, 下载次数: 12)

2018-12-3 00:19 上传

51e513925e4c196db8682dedaa63e8f8.gif

Screenshot_20181203-000717.jpg (223.73 KB, 下载次数: 11)

2018-12-3 00:19 上传上传工程文件:

5486919a67fbcd51e560218d8b3dca4b.gif

工程文件.zip

(1.24 MB, 下载次数: 6)

2018-12-3 00:19 上传

点击文件名下载附件

下载积分: 威望 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值