Using MQTT to interface with hardware, cameras etc, streamlit UI

I have been using the MQTT protocol to send images to a streamlit app over a network, and over time this has proven to be robust and straightforward to maintain. MQTT is commonly used in the IOT world to interface with and collect data from remote hardware, sensors etc, and there are already many interfaces for devices using MQTT. I have a background in science, building large experiments in the lab. These experiments are often assembled by grad students with minimal software development experience, and I believe python/streamlit/MQTT would enable them to get results far quicker and at much lower cost than the traditional approaches (c++, labview etc). Therefore I thought I would start this thread to highlight some best-practice examples of using MQTT to control hardware, with a streamlit UI of course! I found this great example maskcam below, where streamlit and MQTT are used to control and read state from an AI camera. Hopefully this will inspire others to interface with hardware using streamlit as the UI

maskcam-frontend

7 Likes

Oh wow this looks absolutely stunningly awesome @robmarkcole !

Not gonna lie, I’d love a blogpost about this if you have time to write one :slight_smile: ?

Have a nice day,
Fanilo

2 Likes

+1 on the @andfanilo note - would love to read a blog post on this and share it with the community on blog.streamlit.io :heart_eyes:

2 Likes

@robmarkcole that is such a well executed pipeline and you are 100% correct in your assessment of the challenges with grad students writing software. I had the same experience (except my lab was computational, you’d expect better but scientists care about results and often skimp on the architecture).

I’d love to assist in helping disseminate information about designing such systems, a blog post sounds like a great start but ultimately I’d love solid templates and boilerplates. I’ve found that my best success with adoption of stuff like this at university came when I basically boiled everything down to a couple “make” commands that removed as much friction as possible.

@mathematicalmichael one route is to create an awesome repo that aggregates resources on this topic, linking to functioning code. Something like awesome-streamlit-on-hardware perhaps, or even just add a section to awesome-streamlit or awesome-mqtt?

@andfanilo I am totally up for writing a blog post, and starting a blog has been high on my todo for a while now! I think once we have a few more examples of mqtt/streamlit/hardware this article will write itself

A nice demo of streamlit and hardware, not using MQTT but instead publishing data over the serial port (could be forwarded over mqtt however):

https://towardsdatascience.com/build-a-diy-mini-radar-using-arduino-python-and-streamlit-12a368ae03a4

The author did the same with a temperature sensor: https://towardsdatascience.com/how-to-build-a-real-time-scada-system-using-python-and-arduino-7b3acaf86d39

2 Likes

Yes absolutely, with Streamlit the limit is what you want it to be. I’ve had great experiences rendering SCADA dashboards and interfacing with a multitude of hardware including but not limited to motors using Streamlit!

1 Like

More hardware, this time an ultrasound probe!