- Hands-On Edge Analytics with Azure IoT
- Colin Dow
- 289字
- 2021-06-24 16:21:59
DHT11 temperature and humidity sensor
The DHT11 temperature and humidity sensor is a low-cost device used in IoT applications. There are API libraries for this sensor from such sources as Adafruit Industries, which makes it easy to implement the DHT11 into an IoT or edge analytics application.
The following is a Fritzing diagram of how a DHT11 temperature and humidity sensor could be hooked up in an edge analytics application:
The following is a code example using the DHT11 and the Python programming language. The code was written for the Raspberry Pi and is taken from my first book, Internet of Things Programming Projects (Packt Publishing). This code uses the Adafruit DHT library to measure temperature and humidity and send this information to a cloud-based dashboard using the MQTT protocol:
from time import sleep
import Adafruit_DHT
import paho.mqtt.client as mqtt
import json
host = 'demo.thingsboard.io'
access_token = '<<access token>>'
dht_sensor = Adafruit_DHT.DHT11
pin = 19
sensor_data = {'temperature': 0, 'humidity': 0}
client = mqtt.Client()
client.username_pw_set(access_token)
while True:
humidity, temperature = Adafruit_DHT
.read_retry(dht_sensor, pin)
print(u"Temperature: {:g}\u00b0C, Humidity{:g}%".format(temperature, \
humidity))
sensor_data['temperature'] = temperature
sensor_data['humidity'] = humidity
client.connect(host, 1883, 20)
client.publish('v1/devices/me/telemetry',
json.dumps(sensor_data), 1)
client.disconnect()
sleep(10)
The preceding code was written for an IoT application, not an edge analytics one. However, it does point out how easily information from a sensor may be read and utilized.
- 讓每張照片都成為佳作的Photoshop后期技法
- Maya極速引擎:材質篇
- Spark大數據技術與應用
- 分析力!專業Excel的制作與分析實用法則
- Spatial Analytics with ArcGIS
- 大數據導論
- 開放自動化系統應用與實戰:基于標準建模語言IEC 61499
- 大話數據科學:大數據與機器學習實戰(基于R語言)
- AVR單片機C語言程序設計實例精粹
- TensorFlow 2.0卷積神經網絡實戰
- OSGi原理與最佳實踐
- Outlook時間管理秘笈
- Hands-On Data Analysis with NumPy and pandas
- 超限學習機:理論、技術與應用
- 編程大講壇:Visual Basic核心開發技術從入門到精通