我用的正点原子还有esp8266连接onenetMQTT
设备ID:587432807
产品 id:324600
密码:appskd
u8 MODE[]="AT+CWMODE=1\r\n";//esp8266工作模式
u8 Router[]="AT+CWJAP=\"mingtian\",\"crc708715\"\r\n";//加入wifi
u8 RST[]="AT+RST\r\n";
u8 CIPIP[]="AT+CIPSTART=\"TCP\",\"183.230.40.39\",\"6002\"\r\n";//TCP连接onenet
u8 M_Connection[]="AT+CIPMODE=1\r\n"//使能透传
u8 CIPMUX[]="AT+CIPMUX=0\r\n";//单连接
u8 SERVER[]="AT+CIPSEND\r\n";//开启透传
u8 buf[]={0x10,0x25,0x00,0x04,0x4D,0x51,0x54,0x54,0x04,0xC2,0x00,0x78,0x00,0x09,0x35,0x38,0x37,0x34,0x33,0x32,0x38,0x30,0x37,
0x00,0x06,0x33,0x32,0x34,0x36,0x30,0x30,0x00,0x06,0x61,0x70,0x70,0x73,0x6B,0x64};//mqtt连接报文
void wifi_init(void)
{
uart_init(115200);
delay_ms(5000);
Usart3sends(MODE,sizeof(MODE));
delay_ms(5000);
Usart3sends(RST,sizeof(RST));
delay_ms(5000);
Usart3sends(CIPMUX,sizeof(CIPMUX));
delay_ms(5000);
Usart3sends(Router,sizeof(Router));
delay_ms(5000);
Usart3sends(CIPIP,sizeof(CIPIP));
delay_ms(5000);
Usart3sends(M_Connection,sizeof(M_Connection));
delay_ms(5000);
delay_us(10000);
Usart3sends(SERVER,sizeof(SERVER));
printf("7");
delay_ms(50000);
Usart3sends(buf,sizeof(buf));
delay_ms(1000);
}
void Usart3send(u8 ch)
{
while ((USART3->SR&0X40)==0);
USART3->DR=(u8)ch;
}
void Usart3sends(u8 *Str,u16 Strlen)
{u16 k=0;
do
{Usart3send(*(Str+k));
k++;
}
while(k<Strlen);
}
|