赞
踩
一:ONENET平台配置
1.注册产品及添加设备
2.上传lua脚本
可从onenet平台上下载demo,脚本中最重要的两个函数,根据需要修改,本例子中,只是把上传的数据解析为Distance数据存在onenet平台上,没收到一包数据,就返回给终端一个received字符串。
3.创建应用
二:STM32代码开发
char esp8266_init() { char * ok = "OK"; char * at = "AT\r\n"; char * at_cwmode = "AT+CWMODE=1\r\n"; char * at_rst = "AT+RST\r\n"; char * at_cifsr = "AT+CIFSR\r\n"; char * at_cipmux = "AT+CIPMUX=0\r\n"; char * at_cipmode = "AT+CIPMODE=1\r\n"; char * at_cipstart = "AT+CIPSTART=\"TCP\",\"183.230.40.40\",1811\r\n"; char * at_cipsend = "AT+CIPSEND\r\n"; char at_cwjap[64]; memset(at_cwjap, 0, sizeof(at_cwjap)); strcat(at_cwjap,"AT+CWJAP=\""); strcat(at_cwjap,WIFI_SSID); strcat(at_cwjap,"\",\""); strcat(at_cwjap,WIFI_KEY); strcat(at_cwjap,"\"\r\n"); while(esp8266_send_at(at, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cwmode, ok)){ delay_ms(1000); } while(esp8266_send_at(at_rst, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cwjap, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cifsr, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cipmux, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cipmode, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cipstart, ok)){ delay_ms(1000); } while(esp8266_send_at(at_cipsend, ok)){ delay_ms(1000); } onenet_tcp_regist(); printf("Connect to onenet success\r\n"); return 0; }
2.解析onenet下发命令代码
void keep_connect_onenet() { char temp[12]; char info = 0; memset(temp, 0, sizeof(temp)); sprintf(temp, "%d", rand()%100); USART1_Send_Data(temp, strlen((const char *)temp)); //处理onenet下发的信息 delay_ms(500); if(URecv_Index){ if(strstr(URecv, "received")!=NULL){ printf("upload data to onenet ok\r\n"); info++; } if(strstr(URecv, "LED_ON")!=NULL){ printf("get onenet cmd LED_ON\r\n"); led_turn_on(); info++; } if(strstr(URecv, "LED_OFF")!=NULL){ printf("get onenet cmd LED_OFF\r\n"); led_turn_off(); info++; } if(info){ URecv_Index = 0; memset(URecv, 0, sizeof(URecv)); } } }
三 源码连接:https://download.csdn.net/download/oofish0519/12510989
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。