Skip to content
Branch: master
Find file Copy path
Find file Copy path
0 contributors

Users who have contributed to this file

33 lines (26 sloc) 1.06 KB
import machine
# git clone
import bme280
import time
from umqtt.simple import MQTTClient
# Requires the use of as
# Configure the following two lines. Username & API key from
conf = {'deviceid':'ESP8266','user':'USERNAMEHERE','apikey':'APIKEYHERE'}
# Setup the connection to the BME280
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
bme = bme280.BME280(i2c=i2c)
while True:
# Setup the MQTT connection to Adafruit
c = MQTTClient(conf['deviceid'], server="", user=conf['user'], password=conf['apikey'], port=1883)
# Grab the latest enviromental values
envi = bme.values
# Publish all the values via MQTT
c.publish(conf['user']+"/feeds/temp", envi[0])
c.publish(conf['user']+"/feeds/pres", envi[1])
c.publish(conf['user']+"/feeds/humid", envi[2])
# Disconnect from MQTT And goto sleep
time.sleep_ms(10000) #10k mili = 10 seconds
You can’t perform that action at this time.