ÀûÓÃESP8266»ñÈ¡ÍøÂçͬ²½Ê±¼ä£¨±±¾©Ê±¼ä£©
±¾ÎÄÐèÒª¶ÁÕßÓÐÒ»µãESP8266µÄ»ù´¡ÖªÊ¶£¬±ÈÈçESP8266µÄģʽÉèÖã¬APÁ¬½Ó£¬ÁªÍø¡£
1. ÌṩÍøÂçʱ¼äµÄÍøÕ¾
ÒªÏë»ñÈ¡ÍøÂçʱ¼äÊ×ÏÈÒªÓÐÌṩÍøÂçʱ¼äµÄÍøÕ¾£¬Ãâ·ÑÌṩÍøÂçʱ¼äµÄÍøÕ¾Óкܶ࣬
ÕâÀïÒÔhttp://api.k780.comΪÀý×Ó»ñÈ¡ÍøÂçʱ¼ä¡£
2. ESP8266µÄ¹¤×÷ģʽ
ESP8266µÄ¹¤×÷ģʽÉèÖÃΪ£ºSTA¡£´«ÊäÐÒéÑ¡ÔñTCP,ÅäÖÃΪClient£¨¿Í»§¶Ë£©¡£
¹¤×÷µÄ·½Ê½ÊÇESP8266Á¬½Óµ½Ò»¸ö¿ÉÒÔÁ¬ÉÏInternetµÄ·ÓÉÆ÷£¬Í¨¹ýÕâ¸ö·ÓÉÆ÷Á¬½Óµ½Internet£¬
·ÃÎÊhttp://api.k780.comÒÔ»ñÈ¡ÍøÂçʱ¼ä¡£
3. ´Óhttp://api.k780.com»ñÈ¡µÄÊý¾ÝÖÐÌáȡʱ¼ä
ÏÈÀ´¿´Ò»ÏÂÕâ¸öÍøÕ¾¸øESP8266ÌṩµÄÊý¾ÝÊÇʲô¡£
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
Apr 2018 09:11:18 GMT
Content-Type: text/html
Content-Length: 166
Connection: close
´ÓÕâЩÊý¾ÝÖпÉÒÔ¿´³öºìÉ«×ÖÌåµÄ¾ÍÊÇÎÒÃÇÏëÒªµÄÊý¾Ý¡£¶øÇÒÕâ¸öʱ¼äÊÇÖÐÑëʱÇøµÄʱ¼ä£¬
Ҫת»»³É±±¾©Ê±¼äÐèÒª+8£¬ÒÔÉÏÃæµÄʱ¼äΪÀý×Ó09:11:18 µÈÓÚ±±¾©Ê±¼ä17:11:18¡£
ÌáÈ¡µÄ·½·¨ÊÇÀûÓÃstrstrº¯ÊýÕÒµ½GMTµÄλÖã¬È»ºó½«Ö¸Õëµ÷Õûµ½Ê±¼äµÄʮλÊý×ÖÉÏ£¬½Ó×ÅÒ»¸ö
»ñȡʱ¼äµÄascllÂëÈ»ºóת»»³ÉÊý×Ö£¬ÔÙת»»³É±±¾©Ê±¼ä¡£
»ñÈ¡ÍøÕ¾Êý¾ÝµÄ·½·¨ÊÇ£º¿ªÆô͸´«Ä£Ê½ºó£¬·¢ËÍ"http://api.k780.com:88/?app=life.time&appkey=10003
&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json"¡£
M4ƽ̨ÉϵĴúÂëʵÏÖ
Ö÷º¯Êý
int main() { SDErrEnum_Typ sderr; u32 t = 0; u16 i = 0; //u16 *pgbk = (u16*)g_sdcard_rcv_send_buff_5k; u8 *ssid = (u8*)"SP3-20171119FAU-72970";//ÕâÀïÊÇÄã·ÓÉÆ÷µÄSSID(Ãû×Ö) u8 *password = (u8*)"xxxxxx";//ÕâÀïÊÇÄãµÄ·ÓÉÆ÷ÃÜÂë u8 cmdbuff[100]; u8 *p = cmdbuff; NetWorkTime_TypeDef nwt;//±£´æÍøÂçʱ¼äµÄ½á¹¹Ìå FATFS fs; FRESULT fres; sderr = sderr; SystickInit(21); LedInit(); KeyInit(); UartInit(115200); UART3Init(115200); t = QuitTrans(); printf("%d\r\n",t); EspSendCmd((u8*)"AT",(u8*)"OK",50); EspSendCmd((u8*)"AT+CWMODE=1",(u8*)"OK",50); EspSendCmd((u8*)"AT+RST",(u8*)"OK",50);//¸´Î»esp8266 delay_ms(3000); EspSendCmd((u8*)"AT+CWMODE?",(u8*)"OK",50); sprintf((char*)p,"AT+CWJAP=\"%s\",\"%s\"",ssid,password);//Á¬½Ó·ÓÉÆ÷ //sprintf((char*)p,"AT+CWLAP"); while(EspSendCmd(p,(u8*)"WIFI GOT IP",300)) { ; } while(EspSendCmd((u8*)"AT+CWJAP?",(u8*)"OK",50)) { ; } EspSendCmd((u8*)"AT+CIPMUX?",(u8*)"OK",50); while(EspSendCmd((u8*)"AT+CIPSTART=?",(u8*)"OK",50)) { ; } GetNetWorkTime(&nwt,(u8*)"GMT",200);//»ñÈ¡ÍøÂçʱ¼ä printf("%d:%d:%d\r\n",nwt.hour,nwt.min,nwt.sec); //´òÓ¡»ñÈ¡µ½µÄÍøÂçʱ¼ä
LCDInit();
LCDFill(0,0,100,100,0);
while(1) { t++; if(t%50 == 0) { LED1 = !LED1; } key_delay(); } }
|
»ñÈ¡ÍøÂçʱ¼äµÄº¯Êý
u8 QuitTrans() { delay_ms(200); UART3Printf("+++"); delay_ms(200);//±ØÐë¼ÓÑÓʱ·ñÔòÎÞ·¨Í˳ö͸´« return EspSendCmd((u8*)"AT",(u8*)"OK",50);//²âÊÔÊÇ·ñÍ˳öÁË͸´«£¨Èç¹ûÍ˳öÁËATÖ¸Áî¾ÍÉúЧÁË£© }
u8 GetNetWorkTime(NetWorkTime_TypeDef *nwt,u8 *resp,u16 overtime_10ms) { u8 res = 0xFF; u8 temp[100] = {0}; u8 *p = temp; u8 *pend; sprintf((char*)p,"AT+CIPSTART=\"%s\",\"%s\",80","TCP",\ "api.k780.com"); while(EspSendCmd((u8*)p,(u8*)"OK",50)) //Á¬½ÓÍøÕ¾ { ; } EspSendCmd((u8*)"AT+CIPMODE=1",(u8*)"OK",50);//¿ªÆô͸´«Ä£Ê½ EspSendCmd((u8*)"AT+CIPSEND",(u8*)"OK",50); UART3Printf("http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json"); if(resp && overtime_10ms) { while(overtime_10ms--) { delay_ms(10); if(g_uart3_rx_sta & 0x8000) { g_uart3_rx_buff[g_uart3_rx_sta & 0x7ff] = 0; printf("%s\r\n",g_uart3_rx_buff); if(strstr((char*)g_uart3_rx_buff,(char*)resp)) //ʱ¼äת»» { pend = (u8*)strstr((char*)g_uart3_rx_buff,(char*)resp); p = pend - 9; nwt->hour = ((*p - 48)*10 + (*(p+1) - 48) + 8) % 24; nwt->min = ((*(p+3) - 48)*10 + (*(p+4) - 48)) % 60; nwt->sec = ((*(p+6) - 48)*10 + (*(p+7) - 48)) % 60; res = 0; g_uart3_rx_sta = 0; break; } g_uart3_rx_sta = 0; } } if(overtime_10ms == 0) { printf("send cmd ot\r\n"); //²âÊÔÓà } } QuitTrans(); EspSendCmd((u8*)"AT+CIPMODE=0",(u8*)"OK",50);//Í˳ö͸´«Ä£Ê½»Øµ½Õý³£Ä£Ê½ EspSendCmd((u8*)"AT+CIPCLOSE",(u8*)"OK",50);//¹Ø±ÕTCPÁ¬½Ó return res; }
|
Á¬½ÓÍøÕ¾³É¹¦
»ñÈ¡µ½µÄÍøÂçʱ¼ä