I have an idea to send a picture in .jpg format using MQTT to M5StickC from one device (PC / smartphone / etc) and display it on the StickCscreen.
the process should look something like this:
on sending device side
- aquire image
- resize and convert to jpg
- encode with base64 and publish via mqtt to server
on receive m5stickc side
- subscribe data from mqtt server
- decode image with base64 and save to variable
- display image from variable on screen
I have a problem with 6 point
I skip points 1-4 that I won't have a problem with and I will deal with them later.
What I was able to get:
decode the received text as jpg and save it to a variable and to a file. And read it from the file and display it. Very frequent saving to flash memory will burden it tremendously and will shorten its life, so I want to skip writing. Unfortunately, I can't find any function to skip saving to the file and display the image directly from the variable. I was looking for a solution to my problem and the only thing I found was an analogous library for arduino where there is an identical function as in the micropyton and the one I am looking for, but on my hardware the compilation of code in arduino takes forever, which greatly extends the coding / programming / debugging process. I found a function / class in the micropyton
tft.pixel(x, y [,color])
but then I would have to send images as individual bitmap points and practically draw pixel by pixel but it would complicate my software for points 1-3 and extend the drawing time on the screen
working main part of the code:
text = '/9j/4AAQSkZJRgABAQAAAQABAAD ... ( ~ 3-5 kB encoded jpg file) ... '
temp = binascii.a2b_base64(text) # decode base64 ascii stream to binary jpg stream
f = open("res/temp.jpg", "wb")
f.write(temp) # save stream to file
image0 = M5Img(0, 0, "res/temp.jpg", False) # create image object and load saved stream as jpg file