找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1198|回復(fù): 0
收起左側(cè)

BC26接入ONENET發(fā)溫濕度代碼

[復(fù)制鏈接]
ID:437641 發(fā)表于 2023-11-7 15:28 | 顯示全部樓層 |閱讀模式
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "usart.h"         
  5. #include "math.h"                        
  6. #include "stdio.h"
  7. #include "stm32f10x_flash.h"
  8. #include "stdlib.h"
  9. #include "string.h"
  10. #include "wdg.h"
  11. #include "timer.h"
  12. #include "stm32f10x_tim.h"
  13. #include "bc26.h"         
  14. #include "dht11.h"
  15. extern char  RxBuffer[100],RxCounter;

  16. void OPEN_BC26(void)
  17. {
  18.    char *strx;

  19.     printf("AT\r\n");
  20.     delay_ms(300);
  21.     strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
  22.     printf("AT\r\n");
  23.     delay_ms(300);
  24.     strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
  25.         IWDG_Feed();//喂狗
  26.    if(strx==NULL)
  27.         {
  28.         PWRKEY=1;//拉低
  29.         delay_ms(300);
  30.         delay_ms(300);
  31.         delay_ms(300);
  32.         delay_ms(300);        
  33.         PWRKEY=0;//拉高正常開機(jī)
  34.         IWDG_Feed();//喂狗
  35.         }
  36.     printf("AT\r\n");
  37.     delay_ms(300);
  38.     IWDG_Feed();//喂狗
  39.     strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK
  40.     printf("ATE0&W\r\n"); //關(guān)閉回顯
  41.     delay_ms(300);
  42.     LED=0;
  43.     IWDG_Feed();//喂狗
  44.     printf("AT+QMTDISC=0\r\n");//關(guān)閉連接
  45.     delay_ms(300);
  46.     printf("AT+QMTCLOSE=0\r\n");
  47.     delay_ms(300);
  48. }
  49. /***
  50. 此功能實(shí)現(xiàn)往阿里云發(fā)數(shù)據(jù),用戶需要更改三元素與推送主題一致。保持和自己的設(shè)備一樣
  51. ***/

  52. //適用于NB版本
  53. int main(void)
  54. {        
  55.     u8 temp = 26,humi = 58;
  56.                 u8 data_len,send_jason[200];
  57.     delay_init();                     //延時(shí)函數(shù)初始化         
  58.     NVIC_Configuration();          //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
  59.     LED_Init();                                  //初始化與LED連接的硬件接口
  60.     uart_init(115200);//串口1初始化,可連接PC進(jìn)行打印模塊返回?cái)?shù)據(jù)
  61.     uart2_init(115200);//對(duì)接BC26串口初始化
  62.     IWDG_Init(7,625);    //8S一次
  63. //     while(DHT11_Init())
  64. //     {}
  65. //    OPEN_BC26();//對(duì)BC26開機(jī)  
  66.     BC26_Init();//對(duì)設(shè)備初始化
  67.     MQTT_Init();
  68.    while(1)
  69.     {  
  70. //        DHT11_Read_Data(&temp,&humi);//讀取溫濕度數(shù)據(jù)
  71.                                 data_len=MqttOnenet_Savedata(send_jason,temp,humi);//獲取JSON數(shù)據(jù)準(zhǔn)備發(fā)往ONENET
  72.                                 printf("AT+QMTPUB=0,0,0,0,\"$dp\"\r\n");//發(fā)布消息
  73.                                 delay_ms(300);
  74.                           Uart2_SendDATA(send_jason,data_len);//發(fā)jason數(shù)據(jù)到ONENET
  75.                                 while((USART2->SR&0X40)==0){}//
  76.                                 USART2->DR = (u8) 0x1A;
  77.         delay_ms(500);
  78.                                 Clear_Buffer();        
  79.                                 LED=!LED;
  80.         IWDG_Feed();//喂狗
  81.     }         
  82. }
復(fù)制代碼

原理圖: 無
仿真: 無
代碼:: 06_BC26接入ONENET發(fā)溫濕度代碼.7z (198.12 KB, 下載次數(shù): 11)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表