umqtt

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

umqtt

Post by johnv » Sun Jan 19, 2020 8:22 pm

hi, i installed mosquitto to the raspberry pi,

and umqtt is up and running on the esp8266,

but frankly i have no idee how to publish sensor data, and i seem unable to find any documentation or somesort,

i can write text messages from pub to sub

mosquitto_pub -m ... -t ...
mosquitto_sub -t ...

but i want to learn to publish sensor data; (do i do this wit a print function or something),

help please; i'm kinda lost on this one,

cheers!

User avatar
pythoncoder
Posts: 3925
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: umqtt

Post by pythoncoder » Mon Jan 20, 2020 9:24 am

MQTT sends and receives strings so you need to convert between your data and strings. Any online Python tutorial will explain how this is done. The following is an example of one approach:

Code: Select all

>>> my_sensor = 98.4
>>> message = '{:4.1f}'.format(my_sensor)
>>> print(message)
98.4
>>> 
>>> type(message)
<class 'str'>
Peter Hinch

johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

Re: umqtt

Post by johnv » Mon Jan 20, 2020 11:03 am

Tnx mate!

Post Reply