Hey all - I'm trying to make a remote camera viewer using App Inventor. The camera is an infrared (thermal vision) module MLX90640, with a resolution of 32x24, so there's 768 pixels per frame. It's hooked up to an ESP32 which connects to my MQTT server.
I can already see the video in a web page on the local network, reasonably well, but to get it to work away from home - and to let it work for other people who don't have my VPN access to the target network - I'm hoping to make an app. I've done this before, but the application then only required a single character at a time... turns out there are limits to the size of MQTT messages! And 768 floating-point values in a plaintext array - about 4700ish characters? - is too big... (at least for the UrsPahoMqttClient, is there any other for MAI, BTW?)
So I thought why not convert the data to bytes on the ESP32 - a 256-value range is plenty for the temperatures I'm expecting, in fact I'd multiply them by 4 as I'm not expecting the temps to be above 64C! And 3/4ths of a kb per frame is quite manageable.
But the examples I've found on dealing with incoming ByteArrays haven't lead me to any working solution yet. (I'm getting a lot of "Bad list argument to ForEach")
Can someone take a look at my mess of "code" here and point me towards what I'm doing wrong - or, if there's an easier way to go about this...?
Well I've already made some progress - from the UrsPahoMqttclient docs:
" The ByteArray variable can be passed to an extension that can process byte arrays. Direct use by App Inventor standard blocks is not possible."
So, that explains a few things. But it's still appealing to me to send the data in bytes rather than as plaintext float values. Or if that's not possible, an MQTT add-on for App Inventor which can be set to a larger buffer for incoming messages?
Or is there a wholly other way to go - I looked at Firebase once, but my database years are too long ago for me to get back into the terminology let alone configuration.
It's essential for this to be able to work from mobile, and I've got an MQTT server running from home with DynamicDNS that has been stable for a long time, but it doesn't HAVE to be MQTT I guess. It does have to be straightforward to do safely because my head is full of ESP32 stuff already...
You might have missed the part where I said I got it working - you're indicating part of the code which helps convert the output of the ByteArray into something that can be made into a list.
Turns out you just need to take away the brackets, replace spaces with commas, and then feed it in as a CSV - works fine, despite what the MQTT add-on author said.
However, your reply was very useful to me because I didn't know the Companion had a "Do It" function - VERY helpful! (I should be paying more attention...)
As an addendum to anyone who happens across this thread in the future, I've also managed to work out a way to get a nice thermal imaging color palette into App Inventor. I was struggling with pasting strings of RGB values into globals, and converting them to Colors on startup (it was even more of a struggle because I was trying to use Gemini AI to make the lists for me and it has no clue...) but I found a better way.
I realized I can just make a List with enough Color blocks (any color from the defaults) - I used 64 of them, as seen in the pic - then Export the project and save locally. Then you just find the file in the archive which has that block - mine was in /src/appinventor/ai_//Screen1.scm - and open it as a text file.
The tricky part depends on your editor - but in mine, if you scale the window width JUST right, the markup which details those blocks lines up vertically. You'll want an editor which can cut and paste in Block Mode; on Windows there's Notepad++, I used Gealy (?) on Linux but had to disable the UI feature that makes Alt a modifier key that moves windows, so that its Block Edit feature could be used.
Then I just got a list of colors from a palette called Ironbow, popularized by Flir (infrared camera maker) - one of the places you can find that is https://jsfiddle.net/gjruwftd/2/ . I pasted the list into a spreadsheet to trim off excess characters and decimate it down to a size I wanted without having to manually delete 2/3rds of the lines or whatever, then just block-pasted it into the .scm file. Re-import the project file, cross fingers - it worked.
There may have been an easier way to do it - I mean, even typing the values in by hand would have taken less time than I required to do all the above - but in case someone else finds themselves in a similar situation, this may help!