Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
enviroplus
paho-mqtt
enviroplus==0.0.6
paho-mqtt==1.6.1
54 changes: 40 additions & 14 deletions src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,40 @@ def __read_pms_continuously(self):


def take_readings(self):
gas_data = gas.read_all()
readings = {
"proximity": ltr559.get_proximity(),
"lux": ltr559.get_lux(),
"temperature": self.bme280.get_temperature(),
"pressure": self.bme280.get_pressure(),
"humidity": self.bme280.get_humidity(),
"gas/oxidising": gas_data.oxidising,
"gas/reducing": gas_data.reducing,
"gas/nh3": gas_data.nh3,
}
readings = {}

try:
readings["proximity"] = ltr559.get_proximity()
except OSError:
print("Error reading proximity sensor data")

try:
readings["lux"] = ltr559.get_lux()
except OSError:
print("Error reading lux sensor data")

try:
readings["temperature"] = self.bme280.get_temperature()
except OSError:
print("Error reading temperature sensor data")

try:
readings["pressure"] = self.bme280.get_pressure()
except OSError:
print("Error reading pressure sensor data")

try:
readings["humidity"] = self.bme280.get_humidity()
except OSError:
print("Error reading humidity sensor data")

try:
gas_data = gas.read_all()
readings["gas/oxidising"] = gas_data.oxidising
readings["gas/reducing"] = gas_data.reducing
readings["gas/nh3"] = gas_data.nh3
except OSError:
print("Error reading gas sensor data")

readings.update(self.latest_pms_readings)

Expand All @@ -100,9 +123,12 @@ def update(self, publish_readings=True):

if publish_readings:
for topic in self.samples[0].keys():
value_sum = sum([d[topic] for d in self.samples])
value_avg = value_sum / len(self.samples)
self.publish(topic, value_avg)
try:
value_sum = sum([d[topic] for d in self.samples])
value_avg = value_sum / len(self.samples)
self.publish(topic, value_avg)
except KeyError:
print(f"Error publishing data for {topic}")


def destroy(self):
Expand Down