PM2.5_wifi.zip
文件大小: 60k
源码售价: 10 个金币 积分规则     积分充值
资源说明:PM2.5检测实现,WiFi模块esp8266实现: #include "esp8266.h" #include "pm.h" char Cache[40]; char Result[2]; char data*data wifi="2021"; char data*data wifiword="20212021"; char data*data TCP="183.230.40.40"; char data*data TCP_port="1811"; char data*data key="*251177#test#test*"; int state; int state_OK=1; int i=0; //计数 void Wifi_state(int state1){ switch(state1){ case 0: Wifi_Com("AT+CWMODE=1");Wifi_OK();break; case 1: Wifi_Com("AT+RST");Wifi_OK();break; case 2: Wifi_Com("AT+CIPMUX=0");Wifi_OK();break; case 3: Wifi_Hotspot(wifi,wifiword);Wifi_OK();break; case 4: Wifi_Com("AT+CIPMODE=1");Wifi_OK();break; case 5: Wifi_Tcp(TCP,TCP_port);Wifi_OK();break; case 6: Wifi_Com("AT+CIPSEND");delayms(2000);Wifi_dat(key);delayms(5000);state++;break; } if(state<7){ Wifi_state(state); }else{ if(state==7){ Wifi_dat("+++");delayms(1000);Wifi_Com("AT+CIPSEND");delayms(2000);Wifi_dat(30);delayms(2000);Wifi_dat(30);delayms(5000); } return; } } void Wifi_OK(){ //判断OK unsigned long int i=0; while(state_OK){ i++; if(i==1000000){ state=0; return; } } state_OK=1; state++; } void Wifi_dat(char* dat){ send(dat); } void Wifi_Tcp(char* TCP,char* TCP_port){ //连接TCP sprintf((char*)Cache,"AT+CIPSTART=\"TCP\",\"%s\",%s",TCP,TCP_port); send(Cache); send("\r\n"); Cache_clear(); } void Wifi_Hotspot(char* wifi,char* wifiword){ //连接WIFI delayms(2000); sprintf((char*)Cache,"AT+CWJAP=\"%s\",\"%s\"",wifi,wifiword); send(Cache); send("\r\n"); Cache_clear(); } void Wifi_Com(char* Com){ //发送命令 sprintf((char*)Cache,"%s",Com); send(Cache); send("\r\n"); Cache_clear(); } void Cache_clear(){ int j; for(j=0;j<40;j++){ Cache[j]=0; } } void sbu() interrupt 4{ uchar num; if(RI==0) return; ES=0; RI=0; num=SBUF; Result[i]=num; i=(i+1)%2; if((num=='K')&&(Result[i]=='O')){ //OK, i=K i-1=O; 0=O 1=K 0=K 1=O state_OK=0; } ES=1; } void send(uchar *p){ int i=0; do{ SBUF=p[i++]; while(TI==0); TI=0; } while(p[i]!=0); } void UartInit(void) //115200bps@11.0592MHz { SCON = 0x50; //8位数据,可变波特率 AUXR |= 0x40; //定时器1时钟为Fosc,即1T AUXR &= 0xFE; //串口1选择定时器1为波特率发生器 TMOD &= 0x0F; //设定定时器1为16位自动重装方式 TL1 = 0xE8; //设定定时初值 TH1 = 0xFF; //设定定时初值 ET1 = 0; //禁止定时器1中断 TR1 = 1; //启动定时器1 }
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。