web iot espressif
Dependencies: WIZWebtInterface mbed
Diff: main.cpp
- Revision:
- 1:900e3ba27ddb
- Parent:
- 0:25d52c6a3448
- Child:
- 2:0523b50f44fd
--- a/main.cpp Fri Nov 04 01:02:50 2016 +0000 +++ b/main.cpp Fri Nov 04 01:09:31 2016 +0000 @@ -56,7 +56,7 @@ void receive_dht11(); unsigned char receive_byte(); -void delay(unsigned char ms) //延时模块// +void delay(unsigned char ms) { unsigned int y; while(ms--) @@ -214,22 +214,6 @@ status_led = 0; } } - //status_led = myOutD12.read(); - /*if(!status_led) - { - sprintf(httpHeader,"<H1>Led state:OPEN </H1>"); - client.send(httpHeader,strlen(httpHeader)); - myOutD12.write(1); - }else - { - sprintf(httpHeader,"<H1>Led state:CLOCE </H1>"); - client.send(httpHeader,strlen(httpHeader)); - myOutD12.write(0); - } - - - sprintf(httpHeader,"<form action=\"http://%s/%s\"><input type=\"submit\" value=\"ON/OFF\"></form>", seaver_ip, led_control); - client.send(httpHeader,strlen(httpHeader));*/ sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"1\">"); client.send(httpHeader,strlen(httpHeader)); @@ -301,20 +285,20 @@ } } -unsigned char receive_byte()//接收一个字节// +unsigned char receive_byte() { unsigned char i,temp; - for(i=0;i<8;i++)//接收8bit的数据 + for(i=0;i<8;i++) { U8FLAG = 2; - while(!myIOD10.read() && U8FLAG++);//等待50us的低电平开始信号结束 + while(!myIOD10.read() && U8FLAG++); Delay_us(30); - temp=0;//时间为 26us-28us数据'0' + temp=0; if(myIOD10.read()==1) - temp=1;//如果 26us-28us'1' + temp=1; U8FLAG = 2; - while(myIOD10.read() && U8FLAG++);//'0'为 26us-28us'1'为 70us - //超时则跳出for循环 + while(myIOD10.read() && U8FLAG++); + if(U8FLAG==1)break; data_byte<<=1;// data_byte|=temp; @@ -322,33 +306,33 @@ return data_byte; } -void receive_dht11()//接收数据// +void receive_dht11() { unsigned char T_H,T_L,R_H,R_L,check,num_check; - // REQUEST SAMPLE + myIOD10.output(); myIOD10.write(0); - delay(20);//wait(0.020f); + delay(20); myIOD10.write(1); - Delay_us(25);//wait(26/1000*0.001f); + Delay_us(25); myIOD10.write(1); myIOD10.input(); - if(!myIOD10.read())//判断从机是否有低电平响应信号// + if(!myIOD10.read()) { - while(!myIOD10.read());//判断从机发出 80us 的低电平响应信号是否结束// - while(myIOD10.read());//判断从机发出 80us - R_H=receive_byte();//湿度高位 - R_L=receive_byte();//湿度低位 - T_H=receive_byte();//温度高位 - T_L=receive_byte();//温度低位 - check=receive_byte();//校验位 + while(!myIOD10.read()); + while(myIOD10.read()); + R_H=receive_byte(); + R_L=receive_byte(); + T_H=receive_byte(); + T_L=receive_byte(); + check=receive_byte(); uart.printf("--R_H--%d---R_L---%d--T_H--%d---T_L---%d\r\n", R_H,R_L,T_H,T_L); Delay_us(20); num_check=R_H+R_L+T_H+T_L;uart.printf("--num_check--%d---check---%d\r\n", num_check,check); - if(num_check==check)//判断读到的四个数据之和是否与校验位相同 + if(num_check==check) { RH=R_H; RL=R_L; @@ -358,10 +342,10 @@ } } - /*uart.printf("humidity [H] -out--%d\r\n", RH); + uart.printf("humidity [H] -out--%d\r\n", RH); uart.printf("humidity [L] -out--%d\r\n", RL); uart.printf("temperature [H] -out--%d\r\n", TH); - uart.printf("temperature [L] -out--%d\r\n", TL);*/ + uart.printf("temperature [L] -out--%d\r\n", TL); receive_dht11Timeout.attach(&receive_dht11,0.2f); } \ No newline at end of file