找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6404|回復(fù): 4
打印 上一主題 下一主題
收起左側(cè)

基于DL-LN33無線網(wǎng)絡(luò)的STM32環(huán)境監(jiān)測系統(tǒng)設(shè)計資料與源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:312279 發(fā)表于 2018-4-20 11:11 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
基于無線網(wǎng)絡(luò)的環(huán)境監(jiān)測系統(tǒng)

    系統(tǒng)主要包括了數(shù)據(jù)采集節(jié)點和環(huán)境管理計算機。采用STM32F103單片機和溫度、濕度、光照強度等傳感器組成節(jié)點環(huán)境采集系統(tǒng);主計算機通過通過USB串口和zigbee無線模塊組成數(shù)據(jù)處理系統(tǒng)。各個節(jié)點通過zigbee無線網(wǎng)絡(luò)組網(wǎng)。如下圖所示:

圖1 環(huán)境無線監(jiān)控系統(tǒng)示意圖

節(jié)點系統(tǒng):

     節(jié)點系統(tǒng)采用STM32F103單片機+溫濕度傳感器(DHT11DHT22)+光照強度傳感器(TSL2561/BH1750)+無線模塊(DL-LN33)。節(jié)點系統(tǒng)定時將數(shù)據(jù)采集并發(fā)給主機。

主機:

      主機由計算機和無線模塊組成。數(shù)據(jù)采集到計算機后,通過可視化軟件顯示并記錄于數(shù)據(jù)庫。如下圖所示:


圖2 可視化軟件

     可視化軟件采用Visual Studio 2010開發(fā)。使用C#語言,windowsForm應(yīng)用程序。軟件主要涉及了串口通信,曲線圖,sqlce數(shù)據(jù)庫等。

樣機視圖如下:



圖3 樣機視圖

通信協(xié)議:


序號

定義

內(nèi)容

說明

備注

0

0xFE

幀頭



1

0x0A

包長

數(shù)據(jù)長+4=10


2

0x90

源端口號



3

0x91

目的端口號



4

0xXX

遠程地址L



5

0xXX

遠程地址H



6

0xXX

溫度數(shù)據(jù)

0~150,T=N-50;


7

0xXX

濕度數(shù)據(jù)

0~100


8、9

0xXXXX(H1,H2)

光強0

L=H1*250+H2,0<=H1,H2<=250

可見光+紅外光

10、11

0xXXXX(H1,H2)

光強1

L=H1*250+H2,0<=H1,H2<=250

紅外光

12

0xFF

幀尾




單片機源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "key.h"
  5. #include "usart.h"
  6. #include "lcd.h"
  7. #include "spi.h"
  8. #include "flash.h"
  9. //#include "ds18b20.h"
  10. #include "timer.h"
  11. //#include"tls2561.h"
  12. #include "BH1750.h"
  13. #include"myiic.h"
  14. #include "DTH11.h"
  15.        
  16.   extern unsigned int timercount;                
  17. extern u8 timerProcess        ;
  18.   extern u8 receiveM;

  19. uint lux_out[2];
  20.          uint (*lux)[2]         ;
  21. int main(void)
  22. {         
  23.          int dis_data=0;
  24.          u8 Mm=0;
  25.                  u8 temperature=0;              
  26.         u8 humidity=0;  
  27.          uchar datao=0;
  28.     //u8 outdatabuff[13]={0xFE, 0x0A, 0x90, 0x91, 0x65,0x12 ,0x00,0x00,0,0,0,0,0xFF}         ;       
  29.                    u8 outdatabuff[13]={0xFE, 0x0A, 0x90, 0x91, 0x16,0x0D ,0x00,0x00,0,0,0,0,0xFF}         ;       
  30.         //  u8 outdatabuff[13]={0xFE, 0x0A, 0x90, 0x91, 0x65,0x12 ,0x00,0x00,0,0,0,0,0xFF}         ;       
  31. //         short temp;   
  32.         lux_out[0]=lux_out[1]=65535;
  33.         SystemInit(); //系統(tǒng)時鐘設(shè)置
  34.         delay_init(72);             //延時初始化
  35.         NVIC_Configuration();
  36.         uart_init(115200);//串口1初始化
  37.         LED_Init();//LED初始化
  38. //        LCD_Init();//初始化液晶
  39.   Timerx_Init(5000,7199);//10Khz的計數(shù)頻率,計數(shù)到5000為500ms
  40.         IIC_Init();       
  41.         delay_ms(5);
  42.          //        POINT_COLOR=RED;//設(shè)置字體為紅色          
  43.         //LCD_ShowString(60,50,"Mini STM32");       
  44.         //LCD_ShowString(60,70,"DS18B20 TEST");       
  45.         //LCD_ShowString(60,90,"ATOM@ALIENTEK");
  46.         //LCD_ShowString(60,110,"2011/1/1");
  47.         //while(DS18B20_Init())//初始化DS18B20,兼檢測18B20
  48.         //{
  49.                 //LCD_ShowString(60,130,"DS18B20 Check Failed!");
  50.                 //delay_ms(500);                  
  51.                 //LCD_ShowString(60,130,"Please Check!        ");
  52.                 //delay_ms(500);
  53.         //        LED0=!LED0;//DS0閃爍
  54.         //}
  55. //   LCD_ShowString(60,130,"DS18B20 Ready!     ");         
  56. //        POINT_COLOR=BLUE;//設(shè)置字體為藍色          
  57. //        LCD_ShowString(60,150, "Temperate:   . C");         
  58.         LED1=0;
  59.         while(DHT11_Init())        //DHT11初始化       
  60.         {
  61.                
  62.                 delay_ms(100);
  63.                 LED0=!LED0;
  64.                 Mm++;
  65.                 if(Mm>10) break;
  66.                
  67.         }       
  68.   Mm=0;       
  69. //        TSL2561_Write(CONTROL,0x03); //設(shè)置TSL2561未開啟狀態(tài)
  70.         Init_BH1750();       //初始化BH1750
  71.         delay_ms(200);
  72.         Single_Write_BH1750(0x01);   // power on
  73. //        while(datao!=0x03)       
  74. //        {
  75. //               
  76. //                datao=TSL2561_Read(CONTROL);
  77. //                delay_ms(200);
  78. //                LED0=!LED0;
  79. //                Mm++;
  80. //                if(Mm>5) break;
  81. //        }
  82.         Mm=0;
  83. //        printf("TSL2561 Inial Success!\n");
  84. //        printf("%d\n",TSL2561_Read(CONTROL));       
  85.                 lux=(uint(*)[2])malloc(2*sizeof(uint));
  86.                                 if(!lux)
  87.                                 {
  88.                                 //        printf("malloc failed!/n");
  89.                                 }
  90.         while(1)
  91.         {          
  92.        
  93.                 if(timerProcess)
  94.                 {
  95.                         if(timercount%5==0)
  96.                         {                                                                                               
  97. //                                lux=Read_Light(); //讀取光強
  98. //                                lux_out[0]=(*lux)[0];
  99. //                                lux_out[1]=(*lux)[1];
  100. //                        //        printf("Temp:%dHUM:%dGQ:%d,%d\n",temperature,humidity,(*lux)[0],(*lux)[1]);
  101. //                                free(lux);
  102.                        

  103.                         }
  104.                        
  105.                         if(timercount%10==0)
  106.                         {                                                                                               
  107.                         //        LED0=0;
  108.                                 //DHT11_Read_Data(&temperature,&humidity);                //讀取溫濕度值       
  109.                                
  110.                                 //LED0=0;
  111.                                 DHT11_Read_Data(&temperature,&humidity);                //讀取溫濕度值       
  112. //                                lux=Read_Light(); //讀取光強
  113. //                                lux_out[0]=(*lux)[0];
  114. //                                lux_out[1]=(*lux)[1];
  115. //                                free(lux);
  116.                                 //        Single_Write_BH1750(0x01);   // power on
  117.          Single_Write_BH1750(0x11);   // H- resolution mode
  118.                                  // Delay_mms(800);            //延時180ms
  119.                                 delay_ms(800);
  120.                                 mread();       //連續(xù)讀出數(shù)據(jù),存儲在BUF中
  121.                                  dis_data=BUF[0];
  122.         dis_data=(dis_data<<8)+BUF[1]; //合成數(shù)據(jù)
  123.         //        printf("Temp:%dHUM:%dGQ:%d,%d\n",temperature,humidity,lux_out[0],lux_out[1]);
  124.                                 if(temperature>100)temperature=100;
  125.                                 if(humidity>100)humidity=100;
  126.                                 outdatabuff[6]=temperature+50;
  127.                                 outdatabuff[7]=humidity;
  128. //                                outdatabuff[8]=(lux_out[0]/256)%256;
  129. //                                outdatabuff[9]=lux_out[0]%256;
  130. //                                outdatabuff[10]=(lux_out[1]/256)%256;
  131. //                                outdatabuff[11]=lux_out[1]%256;
  132.                                 outdatabuff[8]=(dis_data/250)%250;
  133.                                 outdatabuff[9]=dis_data%250;
  134.                                 //outdatabuff[10]=(lux_out[1]/256)%256;
  135.                                 //outdatabuff[11]=lux_out[1]%256;
  136.                                 LED1=!LED1;
  137.                                 for( Mm=0;Mm<13;Mm++)
  138.                                 {
  139.                                         USART1->DR=outdatabuff[Mm];
  140.                                         while((USART1->SR&0X40)==0);//等待發(fā)送結(jié)束
  141.                                 }       
  142.                                
  143.                                
  144.                         }               
  145.                         else
  146.                         {
  147.                         //        LED0=1;
  148.                         }
  149.                         timerProcess=0;
  150.                 }
  151.                 if(receiveM)
  152.                 {
  153.                        
  154.                         receiveM=0;
  155.                 }

  156.                
  157.         }       
  158. }

復(fù)制代碼

所有資料51hei提供下載:
STM32F103C8_ZNYJC_GY30.zip (394.17 KB, 下載次數(shù): 118)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:314648 發(fā)表于 2018-4-23 20:11 | 只看該作者
好厲害
回復(fù)

使用道具 舉報

板凳
ID:314648 發(fā)表于 2018-4-24 09:29 | 只看該作者
大神,我想問一下,網(wǎng)頁與底層程序的接口在哪。比如說我新增一個光敏模塊,怎么在網(wǎng)頁上顯示出來?
回復(fù)

使用道具 舉報

地板
ID:18591 發(fā)表于 2019-1-20 20:57 | 只看該作者

下載學(xué)習(xí),謝謝分享
回復(fù)

使用道具 舉報

5#
ID:262587 發(fā)表于 2019-1-31 21:09 | 只看該作者
樓主,這個好像只有單片機節(jié)點的程序,有沒有主機節(jié)點的程序(上位機程序)?
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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