mqtt fun times
This commit is contained in:
parent
6bdeb122d7
commit
c8bb903967
114
main.py
114
main.py
|
@ -2,15 +2,15 @@ import uPyConfig
|
|||
|
||||
#hw = uPyConfig.esp32()
|
||||
hw = uPyConfig.esp8266(variant='d1-r2')
|
||||
import webrepl
|
||||
webrepl.start()
|
||||
#import webrepl
|
||||
#webrepl.start()
|
||||
#print family, variant and IP address (using oled, if available on-board)
|
||||
#import init_sample
|
||||
#init_sample.PrintHWInfo(hw)
|
||||
|
||||
# Main app
|
||||
from uPySensor import *
|
||||
hw.owc.__init__(hw.owc, 12)
|
||||
hw.onewire_init(2)
|
||||
bme280 = BME280 (hw.i2c.bus)
|
||||
lm75a = LM75A (hw.i2c.bus)
|
||||
sht21 = SHT21 (hw.i2c.bus)
|
||||
|
@ -22,102 +22,22 @@ server="10.13.37.18"
|
|||
client_id=ubinascii.hexlify(unique_id())
|
||||
mqttc=MQTTClient(client_id,server)
|
||||
mqttc.connect()
|
||||
from time import sleep_ms
|
||||
|
||||
def _bme280():
|
||||
bme280.update_sensor()
|
||||
mqttc.publish(b'home/temp/indoor/bme280/1', "%0.2f" % bme280.temperature)
|
||||
mqttc.publish(b'home/humidity/indoor/bme280/1', "%0.2f" % bme280.humidity)
|
||||
mqttc.publish(b'home/pressure/indoor/bme280/1', "%0.2f" % bme280.pressure)
|
||||
mqttc.publish(b'home/temp/indoor/bme280/1', b"%0.2f" % bme280.temperature)
|
||||
mqttc.publish(b'home/humidity/indoor/bme280/1', b"%0.2f" % bme280.humidity)
|
||||
mqttc.publish(b'home/pressure/indoor/bme280/1', b"%0.2f" % bme280.pressure)
|
||||
def _sht21():
|
||||
mqttc.publish(b'home/temp/indoor/sht21/1', "%0.3f" % sht21.read_tempC())
|
||||
mqttc.publish(b'home/humidity/indoor/sht21/1', "%0.3f" % sht21.read_hum())
|
||||
def _lm75a(): mqttc.publish(b'home/temp/indoor/lm75a/1', "%0.1f" % lm75a.read_tempC())
|
||||
mqttc.publish(b'home/temp/indoor/sht21/1', b"%0.3f" % sht21.read_tempC())
|
||||
mqttc.publish(b'home/humidity/indoor/sht21/1', b"%0.3f" % sht21.read_hum())
|
||||
def _ds18b20(): mqttc.publish(b'home/temp/outdoor/ds18b20/1', b"%0.3f" % ds18b20.read_tempC())
|
||||
def _lm75a(): mqttc.publish(b'home/temp/indoor/lm75a/1', b"%0.1f" % lm75a.read_tempC())
|
||||
|
||||
#from machine import Pin, TouchPad, SPI
|
||||
|
||||
#from uPaper import epaper, fbuf
|
||||
#from ST7735 import TFT
|
||||
#from time import sleep_ms
|
||||
|
||||
#display initialise
|
||||
#tft_spibus=2
|
||||
#tft_mosi=Pin(23)
|
||||
#tft_sck=Pin(5)
|
||||
#tft_dc=17
|
||||
#tft_rst=12
|
||||
#tft_cs=16
|
||||
#
|
||||
#spi=SPI(tft_spibus,baudrate=20000000,polarity=0,phase=0,mosi=tft_mosi,sck=tft_sck)
|
||||
#tft=TFT(spi,tft_dc,tft_rst,tft_cs)
|
||||
##turn display on, init green, blue, enable RGB, then init red.
|
||||
##i don't get it either, but this is the only way i've found to get the screen fully working
|
||||
##anything else either doesn't display correct colours, or it does but there's a bar on the side of the screen
|
||||
#tft.on()
|
||||
#tft.initg()
|
||||
#tft.initb()
|
||||
#tft.rgb(True)
|
||||
#tft.initr()
|
||||
#sleep_ms(200)
|
||||
#tft.fill(tft.RED)
|
||||
#sleep_ms(40)
|
||||
#tft.fill(tft.BLUE)
|
||||
#sleep_ms(40)
|
||||
#tft.fill(tft.GREEN)
|
||||
#sleep_ms(40)
|
||||
#tft.fill(tft.PURPLE)
|
||||
#sleep_ms(40)
|
||||
#tft.fill(tft.WHITE)
|
||||
#sleep_ms(800)
|
||||
#
|
||||
#from fonts import terminal
|
||||
#from network import WLAN as wlan, STA_IF as staif
|
||||
#
|
||||
#tft.text((4,6),hw.family,tft.BLACK,terminal.data)
|
||||
#tft.text((4,16),hw.variant,tft.BLACK,terminal.data)
|
||||
#tft.text((4,26),wlan(staif).ifconfig()[0],tft.BLACK,terminal.data)
|
||||
#
|
||||
#w=32
|
||||
#h=25
|
||||
#
|
||||
#buttonA=Pin(35,Pin.IN)
|
||||
#buttonB=Pin(34,Pin.IN)
|
||||
#buttonC=Pin(39,Pin.IN)
|
||||
#stateA=1
|
||||
#stateB=1
|
||||
#stateC=1
|
||||
#
|
||||
#import machine
|
||||
#
|
||||
#def buttonInterrupt(p):
|
||||
# print(p)
|
||||
# if p==buttonA:
|
||||
# stateA=p.value()
|
||||
# buttonChange(0)
|
||||
# elif p==buttonB:
|
||||
# stateB=p.value()
|
||||
# buttonChange(1)
|
||||
# elif p==buttonC:
|
||||
# stateC=p.value()
|
||||
# buttonChange(2)
|
||||
# else:
|
||||
# print("unrecognised button")
|
||||
#
|
||||
#def buttonChange(i):
|
||||
# left=2+(w*i)+i
|
||||
# c=tft.RED
|
||||
# if i==0: c=(tft.GREEN if stateA==0 else tft.RED)
|
||||
# elif i==1: c=(tft.GREEN if stateB==0 else tft.RED)
|
||||
# elif i==2: c=(tft.GREEN if stateC==0 else tft.RED)
|
||||
# else: return
|
||||
# tft.rect((left,128-h),(w,h),c)
|
||||
#
|
||||
#buttonChange(0)
|
||||
#buttonChange(1)
|
||||
#buttonChange(2)
|
||||
#buttonA.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||
#buttonA.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||
#buttonB.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||
#buttonB.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||
#buttonC.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||
#buttonC.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||
#
|
||||
while True:
|
||||
_bme280()
|
||||
_sht21()
|
||||
_ds18b20()
|
||||
_lm75a()
|
||||
sleep_ms(30000)
|
Loading…
Reference in New Issue