황원재 황원재 2022-12-01
test
@816d5914842b84a238bc5e761c397115ae54e4ba
 
221020/edgex/Temp_Hum_Sensor.py (added)
+++ 221020/edgex/Temp_Hum_Sensor.py
@@ -0,0 +1,37 @@
+import sys, time, requests, json
+import Adafruit_DHT
+
+sensor = Adafruit_DHT.DHT11
+pin = 11
+
+#edgexip = "192.168.0.131"
+
+try:
+
+    while True :
+
+        rawHum, rawTemp = Adafruit_DHT.read_retry(sensor, pin)
+
+        if rawHum is not None and rawTemp is not None :
+            #print("Temperature = {0:0.1f}*C Humidity = {1:0.1f}%".format(rawHum, rawTemp))
+            
+#            urlTemp = 'http://%s:49986/api/v1/resource/Temp_and_Humidity_sensor_cluster_01/temperature' % edgexip
+#            urlHum  = 'http://%s:49986/api/v1/resource/Temp_and_Humidity_sensor_cluster_01/humidity' % edgexip
+
+            humval = str(rawHum)
+            tempval = str(rawTemp)
+
+#            headers = {'content-type': 'application/json'}
+#            response = requests.post(urlTemp, data=json.dumps(int(rawTemp)), headers=headers,verify=False)
+#            response = requests.post(urlHum, data=json.dumps(int(rawHum)), headers=headers,verify=False)
+
+            print("Temp: %s\N{DEGREE SIGN}C, humidity: %s%%" % (tempval, humval))
+
+        else :
+            print('Read error')
+            time.sleep(100)
+except KeyboardInterrupt:
+    print("Terminated by Keyboard")
+
+finally:
+    print("End of Program")
Add a comment
List