Dear all,
I follow with my sharing of the solution.
Now I found a way to use the official BSEL library, thus have a better control of the BME680 chip.
Compile the bsec_bme680_python software:
Code: Select all
pip install statistics
git clone https://github.com/rstoermer/bsec_bme680_python
cd bsec_bme680_python/
./make.sh
You can verify if the software is running through:
Then I modified the Python software (bsec_bme680.py) to user the JSON instead of the MTTQ protocol:
Code: Select all
#!/usr/bin/env python
import subprocess
from statistics import median
import urllib2
import json
import logging
idx_bme680_IAQ = 1
idx_bme680_THB = 2
domoticz_url = 'http://raspberrypi:8080'
url_data_base = '/json.htm?type=command¶m=udevice&idx='
url_data1 = '&nvalue='
url_data2 = '&nvalue=0&svalue='
#Open C File
proc = subprocess.Popen(['/home/pi/bsec_bme680_python/bsec_bme680'], shell=True, stdout=subprocess.PIPE)
listIAQ_Accuracy = []
listPressure = []
listGas = []
listTemperature = []
listIAQ = []
listHumidity = []
listStatus = []
for line in iter(proc.stdout.readline, ''):
lineJSON = json.loads(line.decode("utf-8")) # process line-by-line
lineDict = dict(lineJSON)
#Avoid to collect the valies with low IAQ score (IAQ score from 0=low to 3=high)
if int(lineDict['IAQ_Accuracy']) > 1:
listIAQ_Accuracy.append(int(lineDict['IAQ_Accuracy']))
listPressure.append(float(lineDict['Pressure']))
listGas.append(int(lineDict['Gas']))
listTemperature.append(float(lineDict['Temperature']))
listIAQ.append(float(lineDict['IAQ']))
listHumidity.append(float(lineDict['Humidity']))
listStatus.append(int(lineDict['Status']))
if len(listIAQ_Accuracy) == 20:
#generate the median for each value
IAQ_Accuracy = median(listIAQ_Accuracy)
Pressure = median(listPressure)
Gas = median(listGas)
Temperature = median(listTemperature)
IAQ = median(listIAQ)
Humidity = median(listHumidity)
Status = median(listStatus)
#clear lists
del listIAQ_Accuracy[:]
del listPressure[:]
del listGas[:]
del listTemperature[:]
del listIAQ[:]
del listHumidity[:]
del listStatus[:]
#Temperature Offset
Temperature = Temperature + 2
if Humidity < 40:
HUM_STAT = '2'
elif Humidity < 60:
HUM_STAT = '1'
else:
HUM_STAT = '3'
url1 = domoticz_url+url_data_base+str(idx_bme680_IAQ)+url_data2+str(round(IAQ, 0))
url2 = domoticz_url+url_data_base+str(idx_bme680_THB)+url_data2+str(round(Temperature, 1))+";"+str(round(Humidity, 1))+";"+HUM_STAT+";"+str(round(Pressure, 1))+";0"
try:
logging.info("Transmitting.")
print("Transmitting.")
print(url1)
print(url2)
req1 = urllib2.Request(url1)
response1 = urllib2.urlopen(req1)
logging.info(url1)
logging.info(response1)
req2 = urllib2.Request(url2)
response2 = urllib2.urlopen(req2)
logging.info(url2)
logging.info(response2)
except:
logging.info("Socket error.")
pass
and then used it through the service like before.
File: /lib/systemd/system/BME680_AIQ.service
Code: Select all
[Unit]
Description=BME680 Air Quality Service
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python bsec_bme680.py
WorkingDirectory=/home/pi/bsec_bme680_python
Restart=on-abort
[Install]
WantedBy=multi-user.target
To get the values you need a Custom device for the AQI value, and a Temp+Hum+Baro for the other values.