-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4225489
commit c3f8237
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# bme680-mqtt-micropython | ||
Publish data from the bme680 sensor over MQTT using micropython. Makes use of https://github.com/gkluoe/bme680/blob/master/library/bme680/i2c.py | ||
and https://github.com/pimoroni/bme680. | ||
and https://github.com/pimoroni/bme680. Note that I init my wifi connection in a boot.py. | ||
|
||
<img src="https://github.com/robmarkcole/bme680-mqtt-micropython/blob/master/BME680-wipy.JPG"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
import bme680 | ||
from i2c import I2CAdapter | ||
from mqtt import MQTTClient | ||
import time | ||
|
||
def settimeout(duration): | ||
pass | ||
|
||
client = MQTTClient("wipy", "192.168.0.30", port=1883) | ||
client.settimeout = settimeout | ||
client.connect() | ||
|
||
i2c_dev = I2CAdapter() | ||
sensor = bme680.BME680(i2c_device=i2c_dev) | ||
|
||
# These oversampling settings can be tweaked to | ||
# change the balance between accuracy and noise in | ||
# the data. | ||
sensor.set_humidity_oversample(bme680.OS_2X) | ||
sensor.set_pressure_oversample(bme680.OS_4X) | ||
sensor.set_temperature_oversample(bme680.OS_8X) | ||
sensor.set_filter(bme680.FILTER_SIZE_3) | ||
|
||
print("Polling:") | ||
try: | ||
while True: | ||
if sensor.get_sensor_data(): | ||
|
||
output = "{} C, {} hPa, {} RH, {} RES,".format( | ||
sensor.data.temperature, | ||
sensor.data.pressure, | ||
sensor.data.humidity, | ||
sensor.data.gas_resistance) | ||
|
||
print(output) | ||
client.publish("test", output) | ||
time.sleep(1) | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
import bme680 | ||
from i2c import I2CAdapter | ||
import time | ||
|
||
i2c_dev = I2CAdapter() | ||
sensor = bme680.BME680(i2c_device=i2c_dev) | ||
|
||
# These oversampling settings can be tweaked to | ||
# change the balance between accuracy and noise in | ||
# the data. | ||
sensor.set_humidity_oversample(bme680.OS_2X) | ||
sensor.set_pressure_oversample(bme680.OS_4X) | ||
sensor.set_temperature_oversample(bme680.OS_8X) | ||
sensor.set_filter(bme680.FILTER_SIZE_3) | ||
|
||
print("Polling:") | ||
try: | ||
while True: | ||
if sensor.get_sensor_data(): | ||
|
||
output = "{} C, {} hPa, {} RH, {} RES,".format( | ||
sensor.data.temperature, | ||
sensor.data.pressure, | ||
sensor.data.humidity, | ||
sensor.data.gas_resistance) | ||
|
||
print(output) | ||
time.sleep(1) | ||
except KeyboardInterrupt: | ||
pass |