新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2016-1-12
- 在线时间
- 1 小时
|
1金钱
由于毕业设计需要又不怎么会做,老师也不指导,求各位大神教教 按照我的这个程序我的ESP8266的无线名字应该改正可是无论我怎么烧写 WIFI名都没有改变 虽然可以连接,但是当我用手机连接服务器就出现TCP初始化不成功 求大神指导 我的8266也是接的板的串口3的PB10 和PB11#include "stm32/bsp.h"
#include "stm32/led_key.h"
#include "stm32/usart.h"
#include "string.h"
extern "C"
{
#include "stm32/adc.h"
#include "ds18b20/ds18b20.h"
#include "DHT11/DHT11.h"
}
CBsp bsp;
char s[30]={0};
char s1[20]={0};
char s2[20]={0};
volatile unsigned char sign=0;
volatile unsigned char interger1=1;
//volatile unsigned char interger2=255;
volatile unsigned int decimal=0;
u8 temperature=0;
u8 humidity=0;
CAdc adc1(ADC_Channel_9);
//CAdc adc2(ADC_Channel_11);
CLed led1(LED1),led2(LED2),led3(LED3),led4(LED4);
CUsart usart3(USART3,9600);
//CUsart usart1(USART1,9600);
void esp8266_TCPServer()
{
usart3.USART_SendBuff("\r\n");
bsp.delay(2000);
usart3.USART_SendBuff("AT+CWMODE=3\r\n");//AT+CWMODE=2 设置成路由模式,改成3
bsp.delay(3000);
usart3.USART_SendBuff("AT+CWSAP=\"wenyoufu-59\",\"0123456789\",11,0\r\n");//AT+CWSAP="ESP8266","0123456789",11,0 设置路由
bsp.delay(3000);
usart3.USART_SendBuff("AT+RST\r\n");//AT+RST 重启
bsp.delay(8000);
usart3.USART_SendBuff("AT+CIPMUX=1\r\n");//AT+CIPMUX=1 设置成多连接
bsp.delay(3000);
usart3.USART_SendBuff("AT+CIPSERVER=1,5000\r\n");//AT+CIPSERVER=1,5000 开启TCP服务端口
bsp.delay(3000);
}
void test1(int ch)
{
if(ch=='a')led1.Off();
if(ch=='b')led1.On();
if(ch=='c')led2.Off();
if(ch=='d')led2.On();
if(ch=='$')led3.Off();
if(ch=='%')led3.On();
if(ch=='@')led4.Off();
if(ch=='#')led4.On();
}
/*int len(const char* buf)
{
int i=0;
while (*buf!='\0')i++;
return i;
}*/
int main()
{
bsp.Init();
usart3.setCallback(test1);
usart3.start();
esp8266_TCPServer();
//usart1.setCallback(test1);
//usart1.start();
DHT11_Init();
while(1)
{/*
led1.isOn()?led1.Off():led1.On();
bsp.delay(1000);*/
//led2.isOn()?led2.Off():led2.On();
//bsp.delay(1000);
//led3.isOn()?led3.Off():led3.On();
if(temperature>20)
{
led3.On();
if(temperature>30)
{
led2.On();
}
else
led2.Off();
}
else
led3.Off();
if(humidity>40)
{
led4.On();
}
else
led4.Off();
usart3.USART_SendBuff("AT+CIPMUX=1\r\n");//AT+CIPMUX=1 设置成多连接
bsp.delay(3000);
usart3.USART_SendBuff("AT+CIPSERVER=1,5000\r\n");//AT+CIPSERVER=1,5000 开启TCP服务端口
bsp.delay(3000);
bsp.delay(10000);
usart3.USART_SendChar('a');
//Read_Temperature(&sign,&interger1,&decimal);
DHT11_Read_Data(&temperature,&humidity);
//sprintf(s,"温度:%d=电压:%d\r\n",interger1,adc1.getValue());
sprintf(s,"%dC=%d%%\r\n",temperature,humidity);
//sprintf(s1,"AT+CIPSEND=0,%d\r\n",strlen(s));
sprintf(s1,"AT+CIPSEND=0,%d\r\n",strlen(s));
usart3.USART_SendBuff(s1);
bsp.delay(600);
usart3.USART_SendBuff(s);
}
return 0;
}
|
|