Skip to content

Commit

Permalink
Print data of both sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
feuerrot committed Aug 6, 2019
1 parent 3036858 commit 8dda5e8
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions main.py
Expand Up @@ -14,6 +14,7 @@
SCD = scd30.SCD30(I2C)
LED = max7219.max7219()
LED.set_intensity(max7219.INTENSITY_15)
field = 0

def init_wifi():
nic = network.WLAN(network.STA_IF)
Expand Down Expand Up @@ -42,12 +43,15 @@ def publish_bme280():
tmr.add(1000, publish_bme280)

def read_scd30():
success = SCD.read()
try:
SCD.read()
except SyntaxError as e:
pass
finally:
tmr.add(2000, read_scd30)
print(success)
except Exception as e:
print("read_scd30 exception: {}".format(e))
tmr.add(200, read_scd30)
return
else:
tmr.add(2100, read_scd30)

def publish_scd30():
try:
Expand All @@ -64,14 +68,26 @@ def publish_scd30():
tmr.add(2000, publish_scd30)

def print_scd30():
try:
(co2, temperature, humidity) = SCD.values()
except Exception as e:
pass
else:
LED.write_string("CO2{: >5}".format(int(co2)))
finally:
tmr.add(2000, print_scd30)
global field
data = SCD.values
if data:
if field == 0:
LED.write_string("CO2{: >5}".format(int(data["co2"])))
elif field == 1:
LED.write_string("{}°C{}°C".format(
int(data["temperature"]),
int(BME.values[0])
))
elif field == 2:
LED.write_string("{}°o{}°o".format(
int(data["humidity"]),
int(BME.values[2])
))
elif field == 3:
LED.write_string("{: >4} hPA".format(int(BME.values[1])))

field = (field+1)%4
tmr.add(2000, print_scd30)

print("Boot complete")
#m = mqtt.MQTTClient("Sensor_{}".format(UID), "mqtt.space.aachen.ccc.de")
Expand All @@ -82,5 +98,6 @@ def print_scd30():

#tmr.add(1000, publish_bme280)
#tmr.add(2333, publish_scd30)
tmr.add(2100, print_scd30)
tmr.add(2100, read_scd30)
tmr.add(1000, print_scd30)
tmr._start()

0 comments on commit 8dda5e8

Please sign in to comment.