#asyncio & MQTT

1 messages Β· Page 1 of 1 (latest)

sage crown
#

It has to be something with MQTT - this code works. I poll AIO every 30 seconds for the last value and then updates and scrolls the message. So at least I have a backup plan for my project. πŸ™‚

noble ruin
#

had some IRL things, and since I have the ye olde schoole M4 MatrixPortal, switched over the code to ESP32SPI, waiting for song change πŸ˜‰

sage crown
#

oh, I can push changes, too

#

sorry I missed this

noble ruin
#

can you change song again? I had to reload

sage crown
#

done, had to take the dog out of course

noble ruin
#

had to fix the payload_data vs. json_data, reloaded

sage crown
#

updated

noble ruin
#

I gotta get my own feed, this is gonna get redonk

sage crown
#

sorry :/

noble ruin
#

not your fault, I just hate to keep bugging you everytime I have a syntax error o_O I'm stumped by this one, and don't want to be

sage crown
#

I don't mind, I'm the one getting help. πŸ™‚

noble ruin
#

if this keeps going, I'll figure out something... any frequently-changing MQTT feed ought to do

#

can you change song again?

sage crown
#

yup, I wish I it would notifiy me in a thread

noble ruin
#

I'm trying to publish from another async def to feed myself data πŸ˜‰

sage crown
#

gotcha

flint ravine
#

I've missed a bit of this, but you're having issues with MQTT?

Does your MQTT-based code call the loop() method?

MQTT has keepalive messages that the client has to send the broker periodically (default varies by client but generally a few seconds) or the broker will close the connection.

The loop() method makes sure that they're sent often enough.

So any sleeping or other delays that don't give the loop() method a chance to run will cause the connection to get closed.

#

Sorry if this is ground you've already covered or not relevant to the issue you're seeing

sage crown
#

No, appreciate the insight, thanks!

noble ruin
#

how often does .loop() have to be called?

flint ravine
#

it depends on the keepalive time that the client uses

#

but generally, often πŸ™‚

noble ruin
#

the connection isn't dying,, it some other weird interplay between async and mqtt

flint ravine
#

if you're trying to receive data, .loop() handles that as well

noble ruin
#

a variable assignment isn't sticking

#

well, I have a simplified version working, not sure what's different except I'm creating my own feed data... publishing then callback to message()

#

I did increase the interval and used force

#

let me see if I can narrow down the differences

sage crown
#

awesome, thank you

noble ruin
#

i broke something, always times out now (not sure if socket_timeout works right on esp32spi)

sage crown
#

no problem, appreciate all the help

noble ruin
#

oh, wow, had accidentally copied an old lib with the cert problem

#

(after CIRCUITPY crashed and wiped itself)

sage crown
#

doh

noble ruin
#

OK, I'll post what I have... structure is a mess and it's ESP2SPI, but the async part is the key I think

sage crown
#

awesome, thanks. I need to head upstairs to make dinner for the family, I'll take a look tonight.

noble ruin
#

I'll repost if I clean it up more or get it more like what you have

noble ruin
#

some tweaking probably needed... the color changes don't sync exactly to a text update, and sometimes the update seems to jump a bunch of pixels

but maybe we can figure out the nuance of difference between the code files that makes it stop working

sage crown
#

I'm struggling to put it back together - straight copy / paste works though! So now I know it's just me. πŸ™‚

noble ruin
#

I can't find why yours doesn't work, there's something subtle to it

#

I added a second line of text, but I'm still not doing JSON, can't imagine that would matter, but anything goes at this point

sage crown
#

well, that's the weird thing. I have it working, except as soon as I put my message code in to parse and display the json, it shows Loading again, but then doesn't show the updated text, it's the old artist

#

I don't have to do JSON, that might be the next part is ripping that out and just sending a string and splitting it

sage crown
#

It's the JSON - I passed the payload, made sure it was a string and split it, and it works!

#

And I very much like your exception handling, thank you for that and everything else

noble ruin
#

glad you figured it out, I never would have guessed JSON vs. string could explain the behavior

sage crown
#

if you hadn't done all that work I would have never guessed - thanks so much

noble ruin
#

you’re welcome, i learned a lot too… maybe I’ll do an MQTT project now πŸ™‚

noble ruin
#

publishing and receiving JSON working OK, key pieces are in publish and message, still not sure what nuance of difference between what works and what doesn't