Spaces:
Sleeping
Sleeping
ok everything is fixed yay
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ st.markdown("""
|
|
41 |
""")
|
42 |
|
43 |
# Checkbox to use own credentials
|
44 |
-
use_own_creds = st.checkbox("Use
|
45 |
|
46 |
if use_own_creds:
|
47 |
HIVEMQ_USERNAME = st.text_input("HIVEMQ Username", type="password")
|
@@ -122,9 +122,8 @@ elif st.session_state.selected_command == "control/gripper":
|
|
122 |
with st.form("mqtt_form"):
|
123 |
submitted = st.form_submit_button("Send Command")
|
124 |
if submitted:
|
125 |
-
|
126 |
if st.session_state['client'] is not None:
|
127 |
-
# Check if credentials have changed
|
128 |
credentials_changed = (
|
129 |
st.session_state.get('HIVEMQ_USERNAME') != HIVEMQ_USERNAME or
|
130 |
st.session_state.get('HIVEMQ_PASSWORD') != HIVEMQ_PASSWORD or
|
@@ -132,12 +131,13 @@ with st.form("mqtt_form"):
|
|
132 |
st.session_state.get('DEVICE_ID') != DEVICE_ID or
|
133 |
st.session_state.get('PORT') != PORT
|
134 |
)
|
|
|
135 |
if credentials_changed:
|
136 |
-
# Disconnect old client and create new one
|
137 |
st.session_state['client'].disconnect()
|
138 |
-
st.session_state['client'] = None
|
|
|
|
|
139 |
if st.session_state['client'] is None:
|
140 |
-
# Create new client
|
141 |
st.session_state['response_queue'] = queue.Queue()
|
142 |
st.session_state['client'] = create_paho_client()
|
143 |
setup_paho_client(
|
@@ -149,7 +149,7 @@ with st.form("mqtt_form"):
|
|
149 |
DEVICE_ID,
|
150 |
st.session_state['response_queue']
|
151 |
)
|
152 |
-
#
|
153 |
st.session_state['HIVEMQ_USERNAME'] = HIVEMQ_USERNAME
|
154 |
st.session_state['HIVEMQ_PASSWORD'] = HIVEMQ_PASSWORD
|
155 |
st.session_state['HIVEMQ_HOST'] = HIVEMQ_HOST
|
|
|
41 |
""")
|
42 |
|
43 |
# Checkbox to use own credentials
|
44 |
+
use_own_creds = st.checkbox("Use custom broker", value=False)
|
45 |
|
46 |
if use_own_creds:
|
47 |
HIVEMQ_USERNAME = st.text_input("HIVEMQ Username", type="password")
|
|
|
122 |
with st.form("mqtt_form"):
|
123 |
submitted = st.form_submit_button("Send Command")
|
124 |
if submitted:
|
125 |
+
# check for creds changing
|
126 |
if st.session_state['client'] is not None:
|
|
|
127 |
credentials_changed = (
|
128 |
st.session_state.get('HIVEMQ_USERNAME') != HIVEMQ_USERNAME or
|
129 |
st.session_state.get('HIVEMQ_PASSWORD') != HIVEMQ_PASSWORD or
|
|
|
131 |
st.session_state.get('DEVICE_ID') != DEVICE_ID or
|
132 |
st.session_state.get('PORT') != PORT
|
133 |
)
|
134 |
+
# if creds change force client to reinit
|
135 |
if credentials_changed:
|
|
|
136 |
st.session_state['client'].disconnect()
|
137 |
+
st.session_state['client'] = None
|
138 |
+
|
139 |
+
# reinit client
|
140 |
if st.session_state['client'] is None:
|
|
|
141 |
st.session_state['response_queue'] = queue.Queue()
|
142 |
st.session_state['client'] = create_paho_client()
|
143 |
setup_paho_client(
|
|
|
149 |
DEVICE_ID,
|
150 |
st.session_state['response_queue']
|
151 |
)
|
152 |
+
# put creds in session_state so we can check if they change
|
153 |
st.session_state['HIVEMQ_USERNAME'] = HIVEMQ_USERNAME
|
154 |
st.session_state['HIVEMQ_PASSWORD'] = HIVEMQ_PASSWORD
|
155 |
st.session_state['HIVEMQ_HOST'] = HIVEMQ_HOST
|