-
Notifications
You must be signed in to change notification settings - Fork 8
/
DHT11RinusW-call.py
32 lines (25 loc) · 918 Bytes
/
DHT11RinusW-call.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import time
import pycom
from machine import Pin
from LoraMAC import sendtoLoRa
from DHT22RinusW import DHT22
from DHT22RinusW import DHT11
def go_DHT():
dht_pin=Pin('P9', Pin.OPEN_DRAIN) # connect DHT22 sensor data line to pin P9/G16 on the expansion board
dht_pin(1) # drive pin high to initiate data conversion on DHT sensor
while (True):
temp, hum = DHT11(dht_pin)
# temp = temp * 9 // 5 + 320 # uncomment for Fahrenheit
temp_str = '{}.{}'.format(temp//10,temp%10)
hum_str = '{}.{}'.format(hum//10,hum%10)
# Print or upload it
print('temp = {}C; hum = {}%'.format(temp_str, hum_str))
if hum!=0xffff:
sendtoLoRa(dev_ID, temp, hum)
time.sleep(2)
pycom.heartbeat(False)
pycom.rgbled(0x1f0000) # turn LED blue
f=open('device_name.py') #get device name from file
dev_ID = f.read()
print(dev_ID)
go_DHT()