Improved mqtt

Back when I was making the multi person collab with MQTT blocks i noticed that you cant really send lists or costumes or really anything without making it super complex. Well that is no longer the case!!! with the blocks bellow you can send also lists and costumes without having to convert them in any format!!! I honestly feel this should be completely added to the MQTT system.

Mqtt image transfer script pic (1)

Mqtt image transfer script pic (2)

Your blocks don’t seem to be sending lists or costumes - just “hello”

Do you have modified blocks to do this or is this a feature request?

Maybe publish some more complete examples?

regards

Simon - MQTT Library maintainer

No this is the actual script. this is just a script pic of the blocks so people can use them and see what I mean. but here are some examples of what I mean.

Mqtt image transfer script pic (4)

Mqtt image transfer script pic (5)

I’ll have a look at them but currently the blocks do handle lists

oh binary mode does lists? so i made it do lists just regularly

Ok- now it’s daylight where I am - I can now see what your up to :slight_smile:

Using “magic numbers” to encode/decode different types of payload doesn’t immediately grab me

I think it should be possible to automatically detect if published payload is a costume, convert it to base64 and then decode it in the subscribe block without causing any compatibility problems

Although I introduced the auto encoding lists to JSON as an experiment, I was worried that automatically deciding to decode a JSON payload back into a list might cause issues with non-SNAP generated payloads.

I’ll have a play around and discuss with others who use MQTT :slight_smile:

1st go at avoiding using magic numbers

Not sure it’s worth going to the trouble of auto encoding/decoding different payloads

I think the programmer should just manually encode and decode different payload types.

Ok

This my current thinking.

It is easy to simply add sound and image encoding to the list encoding

And adding a single simple auto decoding reporter is the simplest way of decoding.

I’ve added sound and costume reporters to also simplify things

Maybe


“from base64” internally recognises the media types data:image, data:audio, and the performance penalty for decoding JSON seems to be neglectible.

I always avoid try/except programming except as a last resort - a personal preference :slight_smile:

And I can see that possibly more types of payload might be able to to be encoded/decoded so probably will keep the multiple ifs

[edit]Also going to look into doing the auto decoding within the mqttExtension.js itself

Wym. Like the js?

Yes.

I’ve managed to handle lists but costumes are proving difficult.

attempt to convert to base64. if it works and returns either an image or audio then we know if its an audio or image and we return that

My problem is not identifying image/sound base64 payloads but trying to return a costume/sound from the base64 data

return costume as an image file.

Like I said - I know what to do but not how to do :slight_smile:

its been done. look on forums

Please provide links

your right couldnt find anything. i made this tho.