forked from jiemde/lorawan-weather-station
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (40 loc) · 1.05 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from config import dev_eui, app_eui, app_key
from lora import LORA
from davis7911 import DAVIS7911
from machine import I2C
from bme280 import BME280
from time import sleep
def setup():
global n, sensor_davis, sensor_bme280, sleep_time
# Initial sleep time
sleep_time = 30
# Connect to LoRaWAN
n = LORA()
n.connect(dev_eui, app_eui, app_key)
# Connect Sensors
try:
i2c = I2C(0)
sensor_bme280 = BME280(i2c = i2c)
sensor_davis = DAVIS7911()
except Exception as e:
print("Error: ", e)
print("Setup... done")
if __name__ == "__main__":
# Setup network & sensors
setup()
while True:
sleep(sleep_time)
data = ""
# Measure
try:
bme280_data = sensor_bme280.read_compensated_data()
t = bme280_data[0] / 100
p = bme280_data[1] / 25600
h = bme280_data[2] / 1024
s = sensor_davis.get_windspeed()
d = sensor_davis.get_dir()
data = "%s %s %s %.1f %s" % (t, p, h, s, d)
except Exception as e:
print("Measure error: ", e)
# Send packet
response = n.send(data)