Base64 encoded jpeg through mqtt

Hello folks.

I am trying to consume base64 encoded jpeg sent through mqtt.

However it seems that mqtt binding / Generic MQTT Thing with its image channel cannot resolve what the encoded image really is - it expects binary data, not base64 encoded.

I was trying to use “Incoming Value Transformations” of the image channel but it does nothing, like it was not used param in the channel at all.

How can I consume base64 encoded jpg from mqtt to have a valid image item?

How does your transformation look like ?
Did you try something like How to set the image content of an image item ?

Hi,

For more clafirication:

I have two sources of images through mqtt.

First source is iotlink which sends raw binary of the screenshot. And following WORKS:

Second source is BlueIris which sends jpeg encoded with Base64. This is not binary, but encoded on the mqtt level already. This is not recognized by a Mqtt image channel as a valid jpeg but rather as binary octet stream:

I have added a transformation (ATOB.js):


With code of ATOB.js:

atob(input)

but it seems that MQTT binding does not use “Incoming Value Transformations” channel config field for image type at all (I have checked it against invalid js file to confirm that).

How can I solve the problem in most elegant way with the second source?

That is possible.
Can you get a stringy raw version, using a string type channel?

Note that a transformation must return a string, too.

Yeah! It worked flawlessly!

  1. Created MQTT channel with type Text.
  2. Added image item.
  3. On the channel added transformation like
(function(i) {
    return 'data:image/jpeg;base64,'+ i;
})(input)

And the effect:

Thanks!

1 Like

I’m surprised, I was thinking diagnostic step, but that’ll do :smiley:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.