Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8013

Python • Re: MQTT JSON use data outside function

$
0
0
How do I then get those two pieces of data out?

A simple answer is to pass the data out in a similar way as you've passed the data out to the print function.
For example, create a function called my_display(tm, dist) and pass the data to it just like you did with the print function in the on_message function.
print(time, distance)
my_display(time, distance)

and in your my_display function, which has now received time and distance info, then proceed to do nefarious stuff to get it to display on something in your "hack together some probably ugly but working code", though I expect it will turn out to be code of exquisite beauty. (beauty being in the eye of the beholder ;) )

Statistics: Posted by SirFico — Mon Jan 12, 2026 9:27 pm



Viewing all articles
Browse latest Browse all 8013

Trending Articles