Hi,
I found many posts about using MQTT with Streamlit, most of them are outdated, recommending solutions that fails at the first import, a few of them use unmaintainable and undocumented logics.
What I would like to do:
- Subscribe to a topic with my paho-mqtt client,
- Receive update with an on_message callback function
- Update the UI from that function
def on_message(client, userdata, message):
st.write(message.payload.decode())
Why is it a challenge :
- The on_message is ran in a different thread
- I canāt seem to update the session_state nor any of ui element from this thread
- Solutions posted around either involve reloading the full stuff periodically, either do not work anymore
- I get the console flooded by this error:
2024-07-15 16:28:10.639 Thread 'paho-mqtt-client-TEST_DEVICE': missing ScriptRunContext
2024-07-15 16:28:10.639 Thread 'paho-mqtt-client-TEST_DEVICE': missing ScriptRunContext
2024-07-15 16:28:10.639 Thread 'paho-mqtt-client-TEST_DEVICE': missing ScriptRunContext
How should I proceed ?
outdated posts:
unmaintainable logic: