Wireless Lab 3

tags: Wireless

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
實驗結果

  1. 請讀取溫溼度感應器的資料,並使用OTAA送出資料,分別截圖join_ttn.py,send_ttn.py的結果
  2. 傳輸資料後用MQTT查看,並用base64解密截圖。
  3. 以組為單位(一個人上傳即可),將這些截圖結果貼成一個word檔案,命名為wireless-lab3-groupxx.docx,並上傳到LMS作業區。

DHT22

  1. 首先要將溫溼度感應器晶片插在Raspberry Pi上
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • sensor有三個腳位,請對照GPIO腳位圖

    • + : 接3.3V (#1)
    • out : 接GPIO4 (#7)
    • - : GND (#9)

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  1. 之後在Raspberry Pi上安裝DHT所需要的Library

    ​​​​$ sudo pip3 install Adafruit_DHT
    
  2. 使用下載Adafruit_Python_DHT程式碼

    ​​​​$ git clone https://github.com/adafruit/Adafruit_Python_DHT
    
  3. 測試

    ​​​​$ cd Adafruit_Python_DHT/examples
    ​​​​$ python3 AdafruitDHT.py 22 4
    
    • 參數一:22,表示使用Adafruit_DHT.DHT22
    • 參數二:4 ,表示data的接腳是接在GPIO4

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  4. 請想辦法與Lab2(OTAA)結合,可以查看Adafruit_DHT.py的程式,把一部分的程式移植到Lab2的程式裡

import sys import Adafruit_DHT # Parse command line parameters. sensor_args = { '11': Adafruit_DHT.DHT11, '22': Adafruit_DHT.DHT22, '2302': Adafruit_DHT.AM2302 } if len(sys.argv) == 3 and sys.argv[1] in sensor_args: sensor = sensor_args[sys.argv[1]] pin = sys.argv[2] else: print('Usage: sudo ./Adafruit_DHT.py [11|22|2302] <GPIO pin number>') print('Example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO pin #4') sys.exit(1) # Try to grab a sensor reading. Use the read_retry method which will retry up # to 15 times to get a sensor reading (waiting 2 seconds between each retry). # 主要偵測的function humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) # Un-comment the line below to convert the temperature to Fahrenheit. # temperature = temperature * 9/5.0 + 32 # Note that sometimes you won't get a reading and # the results will be null (because Linux can't # guarantee the timing of calls to read the sensor). # If this happens try again! if humidity is not None and temperature is not None: print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity)) else: print('Failed to get reading. Try again!') sys.exit(1)
  1. 可能的結果
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →