After some attempts, I now have the following ad in the PaperUI
this presentation is very confusing. How should the
payload msg look so I use the different readings
can represent individually
at the moment it looks like this
“{” Location “:” home / weather “,” temperature “: 23.6,” pressure “: 1030.73,” humidity “: 46.67}”
if I now have the client message with the
“Incoming value transformation” selection wants to evaluate as follows
“JSONPATH: device.status.temperature $.”
does the message sent by the client have to have an appropriate format?
My boot.py file looks like this
from umqtt.robust import MQTTClient
import bme280
import network
import machine
from time import sleep
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print('woke from a deep sleep')
# define environment variables
LOCATION = "home/weather"
MQTT_BROKER = "192.168.2.103"
MQTT_TOPIC = "sensors/"+LOCATION
WLAN_SSID = "WLAN"
WLAN_PASS = "xxxxxxxxxxx"
c = MQTTClient("espressiv"+LOCATION,MQTT_BROKER)
# WLAN connection
def do_connect():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
wlan.connect(WLAN_SSID,WLAN_PASS)
while not wlan.isconnected():
pass
def do_disconnect():
wlan = network.WLAN(network.STA_IF)
wlan.disconnect()
wlan.active(False)
# publish topic to mqtt-broker
def write_mqtt(topic,temperature,pressure,humidity):
payload = b'{"location":"' + LOCATION + '","temperature":' + temperature + ',"pressure":' + pressure + ',"humidity":' + humidity + '}'
try:
c.connect()
c.publish(b""+topic,payload)
c.disconnect()
except Exception as e:
print(str(e))
# initialize BME280
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
bme = bme280.BME280(i2c=i2c)
# establish connection
do_connect()
# initialize RTC
#p = machine.Pin(12,machine.Pin.OUT)
#rtc = machine.RTC()
#rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
# read temperature, pressure, humidity
t,p,h = bme.values
write_mqtt(MQTT_TOPIC,t[:-1],p[:-3],h[:-1]) # cut the last character, else it's no number!
#import machine as m
#r = m.RTC()
#r.irq(trigger=r.ALARM0, wake=m.DEEPSLEEP)
#r.alarm(r.ALARM0, 300000)
# set RTC.ALARM0 to fire after 5 minutes (waking the device)
#rtc.alarm(rtc.ALARM0, 300000)
do_disconnect()
# put the device to sleep for 10 seconds
machine.deepsleep(60000)
m.deepsleep()
I hope to recognize that what my questions are about. Perhaps in the forum someone who is familiar with “mircoPython” and knows how to format paylod so that the readings individually as chanel
can be read out.