- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "math.h"
- #include "stdio.h"
- #include "stm32f10x_flash.h"
- #include "stdlib.h"
- #include "string.h"
- #include "wdg.h"
- #include "timer.h"
- #include "stm32f10x_tim.h"
- #include "bc26.h"
- #include "dht11.h"
- extern char RxBuffer[100],RxCounter;
- void OPEN_BC26(void)
- {
- char *strx;
-
- printf("AT\r\n");
- delay_ms(300);
- strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
- printf("AT\r\n");
- delay_ms(300);
- strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
- IWDG_Feed();//喂狗
- if(strx==NULL)
- {
- PWRKEY=1;//拉低
- delay_ms(300);
- delay_ms(300);
- delay_ms(300);
- delay_ms(300);
- PWRKEY=0;//拉高正常開機
- IWDG_Feed();//喂狗
- }
- printf("AT\r\n");
- delay_ms(300);
- IWDG_Feed();//喂狗
- strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
- printf("ATE0&W\r\n"); //關閉回顯
- delay_ms(300);
- LED=0;
- IWDG_Feed();//喂狗
- printf("AT+QMTDISC=0\r\n");//關閉連接
- delay_ms(300);
- printf("AT+QMTCLOSE=0\r\n");
- delay_ms(300);
- }
- /***
- 此功能實現往阿里云發數據,用戶需要更改三元素與推送主題一致。保持和自己的設備一樣
- ***/
- //適用于NB版本
- int main(void)
- {
- u8 temp = 26,humi = 58;
- u8 data_len,send_jason[200];
- delay_init(); //延時函數初始化
- NVIC_Configuration(); //設置NVIC中斷分組2:2位搶占優先級,2位響應優先級
- LED_Init(); //初始化與LED連接的硬件接口
- uart_init(115200);//串口1初始化,可連接PC進行打印模塊返回數據
- uart2_init(115200);//對接BC26串口初始化
- IWDG_Init(7,625); //8S一次
- // while(DHT11_Init())
- // {}
- // OPEN_BC26();//對BC26開機
- BC26_Init();//對設備初始化
- MQTT_Init();
- while(1)
- {
- // DHT11_Read_Data(&temp,&humi);//讀取溫濕度數據
- data_len=MqttOnenet_Savedata(send_jason,temp,humi);//獲取JSON數據準備發往ONENET
- printf("AT+QMTPUB=0,0,0,0,\"$dp\"\r\n");//發布消息
- delay_ms(300);
- Uart2_SendDATA(send_jason,data_len);//發jason數據到ONENET
- while((USART2->SR&0X40)==0){}//
- USART2->DR = (u8) 0x1A;
- delay_ms(500);
- Clear_Buffer();
- LED=!LED;
- IWDG_Feed();//喂狗
- }
- }
復制代碼
原理圖: 無
仿真: 無
代碼::
06_BC26接入ONENET發溫濕度代碼.7z
(198.12 KB, 下載次數: 11)
2023-11-7 15:44 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|