wifi 模块

#include"STC12C5A.H"
#include <string.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define Wifi_Buffer_Length 10
sbit LED=P2^; int ceshi=;
uchar temp;
uchar RX_Count=;
uchar Wifi_Buffer[Wifi_Buffer_Length];
bit flag;
void delay_15s() //@11.0592MHz
{
unsigned char i, j, k; _nop_();
_nop_();
i = ;
j = ;
k = ;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
} //延时函数
void delay_ms(uint c)
{
unsigned char i, j; _nop_();
_nop_();
_nop_();
i = ;
j = ;
while(c--)
{
do
{
while (--j);
} while (--i);
}
}
//波特率发生器
void UartInit(void) //115200bps@11.0592MHz
{
PCON &= 0x7F; //波特率不倍速
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x04; //独立波特率发生器时钟为Fosc,即1T
BRT = 0xFD; //设定独立波特率发生器重装值
AUXR |= 0x01; //串口1选择独立波特率发生器为波特率发生器
AUXR |= 0x10; //启动独立波特率发生器
ES=;
EA=;//需要打开总中断
}
//串口发送函数
void Send_Uart(uchar value)
{
ES=;//发送数据之前关闭中断
SBUF=value;
while(!TI);//等待发送完毕
TI=; //发送结束 软件置0
ES=;
}
//wifi模块设置函数
void ESP8266_Set(uchar *s)
{
while(*s!='\0')
{
Send_Uart(*s);
s++;
}
delay_ms();
}
void Send_String(uchar *s)
{
while(*s!='\0')
{
Send_Uart(*s);
s++;
}
delay_ms();
}
void wifi_send()
{
/* ESP8266_Set("AT+CWMODE=1");
ESP8266_Set("AT+RST");
ESP8266_Set("AT+CWJAP=\"qwe\",\"123456789\"");
ESP8266_Set("AT+CIPSTART=\"TCP\",\"10.25.97.164\",8001");
ESP8266_Set("AT+CIPMODE=1");
ESP8266_Set("AT+CIPSEND"); */ Send_String("AT+CIPSTART=\"TCP\",\"api.yeelink.net\",80\r\n");
Send_String("AT+CIPSEND=250\r\n");
Send_String("POST /v1.0/device/351905/sensor/396141/datapoints HTTP/1.1\r\n");
Send_String("Host: api.yeelink.net\r\n");
Send_String("Accept: */*\r\n") ;
Send_String("U-ApiKey: 71c27d52c090e00b65998a2d4dba73e8\r\n");
Send_String("Content-Length: 14\r\n");
Send_String("Content-Type: application/x-www-form-urlencoded\r\n");
Send_String("Connection: close\r\n");
Send_String("\r\n");
// display("{\"value\":");
// Send_Uart(temp/10);
//Send_Uart(temp%10) ;
Send_String("{\"value\":");
Send_Uart(0x30+ceshi/);
Send_Uart(0x30+ceshi%);
Send_String(" }\r\n");
Send_String("\r\n");
Send_String("\r\n");
ceshi++;
if(ceshi==)
ceshi=;
}
void wifi_accept()
{
Send_String("AT+CIPSTART=\"TCP\",\"api.yeelink.net\",80\r\n");
Send_String("AT+CIPSEND=250\r\n");
Send_String("GET /v1.0/device/351905/sensor/396173/datapoints HTTP/1.1\r\n");
Send_String("Host: api.yeelink.net\r\n");
Send_String("Accept: */*\r\n");
Send_String("U-ApiKey: 71c27d52c090e00b65998a2d4dba73e8\r\n");
Send_String("Content-Length: 0\r\n");
Send_String("Connection: close\r\n");
Send_String("\r\n");
Send_String("print get done.\r\n");
Send_String("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n");
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0xff ;
P2M1 = 0x00;
P3M0 = 0xff;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ESP8266_Set("AT+CWJAP=\"qwe\",\"123456789\"\r\n");
ESP8266_Set("AT+CWJAP=\"qwe\",\"123456789\"\r\n");
ESP8266_Set("AT+CWJAP=\"qwe\",\"123456789\"\r\n"); while()
{
wifi_send();
delay_15s();
wifi_accept();
delay_15s();
}
}
void ser() interrupt using
{
ES=;
temp=SBUF;
RI=;
if(temp=='l')
{
RX_Count=;
}
if(RX_Count<)
{
Wifi_Buffer[RX_Count++]=temp;
}
else if(Wifi_Buffer[]=='l'&&Wifi_Buffer[]=='u'&&Wifi_Buffer[]=='"')
{
Wifi_Buffer[RX_Count++]=temp;
if(temp=='\n')
{
if(Wifi_Buffer[]=='')
{
LED=;
}
else if(Wifi_Buffer[]=='')
{
LED=;
}
memset(Wifi_Buffer,,Wifi_Buffer_Length);//清空数组的数据
}
}
ES=; }

今天实验成功了,有点小兴奋

上一篇:Python 常见错误


下一篇:集群介绍 keepalived介绍 用keepalived配置高可用集群