Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Esp32 Dimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cpresser
Esp32 Dimmer
Commits
74e2fe93
Commit
74e2fe93
authored
2 years ago
by
Carsten Presser
Browse files
Options
Downloads
Patches
Plain Diff
Fix CO2 sensor stuff
parent
fa2dea2a
Branches
master
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
software/main.py
+31
-30
31 additions, 30 deletions
software/main.py
software/pasCO2.py
+5
-1
5 additions, 1 deletion
software/pasCO2.py
with
36 additions
and
31 deletions
software/main.py
+
31
−
30
View file @
74e2fe93
...
...
@@ -8,10 +8,11 @@ import math
import
pca9685
import
mqtt
import
bme280
import
pasCO2
import
adt7410
import
timer
TMR
=
timer
.
Softtimer
(
5
0
,
tid
=
3
)
TMR
=
timer
.
Softtimer
(
10
0
,
tid
=
3
)
UID
=
ubinascii
.
hexlify
(
machine
.
unique_id
()).
decode
()
MQTT
=
mqtt
.
MQTTClient
(
"
Sensor_{}
"
.
format
(
UID
),
"
mqtt.intern.ca.rstenpresser.de
"
)
#I2C = machine.I2C(1, scl=machine.Pin(19), sda=machine.Pin(18), freq=400000) #blue pcb
...
...
@@ -19,8 +20,9 @@ I2C = machine.I2C(0, freq=400000) #green pcb
PCA
=
pca9685
.
PCA9685
(
I2C
)
BME
=
None
ADT
=
None
CO2
=
None
BME
_PUBLISH_INTERVAL
=
60000
ENV
_PUBLISH_INTERVAL
=
60000
red
=
machine
.
Pin
(
12
,
machine
.
Pin
.
OUT
)
#green pcb
#red = machine.Pin(13, machine.Pin.OUT) #blue pcb
...
...
@@ -83,7 +85,7 @@ class MQTT_SensorCombine():
"
unit_of_meas
"
:
unit
}
self
.
MQTT
.
publish
(
self
.
base
+
"
_
"
+
claz
+
"
/config
"
,
json
.
dumps
(
cfg
))
print
(
self
.
base
+
"
/config
"
)
print
(
self
.
base
+
"
_
"
+
claz
+
"
/config
"
)
def
publish
(
self
,
val_map
):
self
.
MQTT
.
publish
(
self
.
base
+
"
/state
"
,
json
.
dumps
(
val_map
))
...
...
@@ -241,27 +243,28 @@ def pwm_set(channel, color, value = 0, bright = 0):
v
=
int
(
value
*
bright
/
255
)
PCA
.
duty
(
chan
,
g8
[
v
])
def
publish_
bme280
():
def
publish_
env
():
try
:
if
BME
!=
None
:
(
temperature
,
pressure
,
humidity
)
=
BME
.
values
except
:
pass
else
:
sensorBME
.
publish
({
"
temperature
"
:
temperature
,
"
pressure
"
:
pressure
,
"
humidity
"
:
humidity
})
#print("{}\t{}\t{}".format(temperature, pressure, humidity))
finally
:
TMR
.
add
(
BME_PUBLISH_INTERVAL
,
publish_bme280
)
def
publish_adt7410
():
try
:
temperature
=
ADT
.
values
print
(
"
BME280:
\t
Temp={}
\t
Pressure={}
\t
Humidity={}
"
.
format
(
temperature
,
pressure
,
humidity
))
if
CO2
!=
None
:
if
"
pressure
"
in
locals
():
CO2
.
set_pressure
(
int
(
pressure
))
(
ppm
)
=
CO2
.
values
sensorCO2
.
publish
({
"
carbon_dioxide
"
:
ppm
})
print
(
"
PAS Co2:
\t
PPM={}
"
.
format
(
ppm
))
if
ADT
!=
None
:
(
temp
)
=
ADT
.
values
sensorADT
.
publish
({
"
temperature
"
:
temp
})
print
(
"
ADT7140:
\t
Temp={}
"
.
format
(
temp
))
except
:
pass
else
:
print
(
temperature
)
sensorADT
.
publish
({
"
temperature
"
:
temperature
})
pass
finally
:
TMR
.
add
(
BME
_PUBLISH_INTERVAL
,
publish_
adt7410
)
TMR
.
add
(
ENV
_PUBLISH_INTERVAL
,
publish_
env
)
# red and green are inverted.
# show that we are not ready by lighting up red
...
...
@@ -322,28 +325,26 @@ if False:
for
idd
,
ma
in
btn_map
.
items
():
ma
[
'
button
'
].
irq
(
button_callback
,
trigger
=
machine
.
Pin
.
IRQ_FALLING
|
machine
.
Pin
.
IRQ_RISING
)
# add Bosch BME280 if found
if
118
in
I2C
.
scan
():
# the BME280 lib already set force mode (LSB in 0xF4 register)
BME
=
bme280
.
BME280
(
i2c
=
I2C
,
mode
=
bme280
.
BME280_OSAMPLE_1
)
# configure temp sensor
if
BME
!=
None
:
sensorBME
=
MQTT_SensorCombine
(
MQTT
,
UID
,
"
bme280
"
,
{
"
temperature
"
:
"
C
"
,
"
pressure
"
:
"
hPa
"
,
"
humidity
"
:
"
%
"
})
publish_bme280
()
# add ADT7410 if found
# add Infinion PAS Co2 Sensor if found
if
40
in
I2C
.
scan
():
CO2
=
pasCO2
.
PASCo2
(
i2c
=
I2C
)
sensorCO2
=
MQTT_SensorCombine
(
MQTT
,
UID
,
"
pasCo2
"
,
{
"
carbon_dioxide
"
:
"
ppm
"
})
# add Analog ADT7410 temperature sensor if found
if
72
in
I2C
.
scan
():
ADT
=
adt7410
.
ADT7410
(
i2c
=
I2C
)
# configure temp sensor
if
ADT
!=
None
:
sensorADT
=
MQTT_SensorCombine
(
MQTT
,
UID
,
"
adt7410
"
,
{
"
temperature
"
:
"
C
"
})
publish_adt7410
()
sensorADT
=
MQTT_SensorCombine
(
MQTT
,
UID
,
"
ADT7140
"
,
{
"
temperature
"
:
"
C
"
})
TMR
.
_start
()
# if any sensor was found, publish them
if
CO2
!=
None
or
BME
!=
None
or
ADT
!=
None
:
TMR
.
add
(
1000
,
publish_env
)
TMR
.
_start
()
# main loop does nothing
while
True
:
...
...
This diff is collapsed.
Click to expand it.
software/pasCO2.py
+
5
−
1
View file @
74e2fe93
...
...
@@ -16,8 +16,12 @@ class PASCo2:
#self.i2c.writeto_mem(self.address, 0x02, bytearray([0x00, 0x0A])) # cont. period
status
=
self
.
i2c
.
readfrom_mem
(
self
.
address
,
0x01
,
1
)
print
(
"
status = 0x%02x
"
%
int
(
status
[
0
]))
#
print("status = 0x%02x" % int(status[0]))
def
set_pressure
(
self
,
pressure
):
highbyte
=
int
(
pressure
/
256
)
lowbyte
=
int
(
pressure
%
256
)
self
.
i2c
.
writeto_mem
(
self
.
address
,
0x0B
,
bytearray
([
highbyte
,
lowbyte
]))
def
read_data
(
self
,
result
=
None
,
delay
=
1000
):
"""
Reads the data from the sensor
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment