update
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ def handle_image_display(image):
|
|
35 |
return img
|
36 |
|
37 |
with gr.Blocks() as demo:
|
38 |
-
gr.Markdown("# MyCobot280 Pi
|
39 |
|
40 |
gr.Markdown("""
|
41 |
This app is a public demo of ...
|
@@ -185,19 +185,19 @@ with gr.Blocks() as demo:
|
|
185 |
PORT = int(os.environ.get("PORT", 8883))
|
186 |
|
187 |
# Check if client is already connected and credentials haven't changed
|
188 |
-
if client_state is not None
|
189 |
credentials_changed = (
|
190 |
-
previous_credentials_state
|
191 |
-
previous_credentials_state
|
192 |
-
previous_credentials_state
|
193 |
-
previous_credentials_state
|
194 |
-
previous_credentials_state
|
195 |
)
|
196 |
if credentials_changed:
|
197 |
-
client_state.
|
198 |
-
client_state
|
199 |
|
200 |
-
if client_state
|
201 |
response_queue = queue.Queue()
|
202 |
client = create_paho_client()
|
203 |
try:
|
@@ -214,10 +214,10 @@ with gr.Blocks() as demo:
|
|
214 |
payload_md = ""
|
215 |
response_md = f"### Error\nFailed to connect to broker: {e}"
|
216 |
return payload_md, response_md, None, client_state, response_queue_state, previous_credentials_state
|
217 |
-
|
218 |
-
client_state
|
219 |
-
response_queue_state
|
220 |
-
previous_credentials_state
|
221 |
'username': HIVEMQ_USERNAME,
|
222 |
'password': HIVEMQ_PASSWORD,
|
223 |
'host': HIVEMQ_HOST,
|
@@ -225,8 +225,8 @@ with gr.Blocks() as demo:
|
|
225 |
'port': PORT
|
226 |
}
|
227 |
else:
|
228 |
-
client = client_state
|
229 |
-
response_queue = response_queue_state
|
230 |
|
231 |
# Prepare payload
|
232 |
payload = {"command": selected_command, "args": args}
|
@@ -253,7 +253,7 @@ with gr.Blocks() as demo:
|
|
253 |
else:
|
254 |
response_md = "### Response\nTimed out waiting for response. Is the on-device server running?"
|
255 |
return payload_md, response_md, None, client_state, response_queue_state, previous_credentials_state
|
256 |
-
|
257 |
# Now, set up the function to be called when the "Send Command" button is clicked
|
258 |
send_command_button.click(
|
259 |
fn=send_command,
|
|
|
35 |
return img
|
36 |
|
37 |
with gr.Blocks() as demo:
|
38 |
+
gr.Markdown("# MyCobot280 Pi Control Demo")
|
39 |
|
40 |
gr.Markdown("""
|
41 |
This app is a public demo of ...
|
|
|
185 |
PORT = int(os.environ.get("PORT", 8883))
|
186 |
|
187 |
# Check if client is already connected and credentials haven't changed
|
188 |
+
if client_state is not None:
|
189 |
credentials_changed = (
|
190 |
+
previous_credentials_state['username'] != HIVEMQ_USERNAME or
|
191 |
+
previous_credentials_state['password'] != HIVEMQ_PASSWORD or
|
192 |
+
previous_credentials_state['host'] != HIVEMQ_HOST or
|
193 |
+
previous_credentials_state['device_id'] != DEVICE_ID or
|
194 |
+
previous_credentials_state['port'] != PORT
|
195 |
)
|
196 |
if credentials_changed:
|
197 |
+
client_state.disconnect()
|
198 |
+
client_state = None
|
199 |
|
200 |
+
if client_state is None:
|
201 |
response_queue = queue.Queue()
|
202 |
client = create_paho_client()
|
203 |
try:
|
|
|
214 |
payload_md = ""
|
215 |
response_md = f"### Error\nFailed to connect to broker: {e}"
|
216 |
return payload_md, response_md, None, client_state, response_queue_state, previous_credentials_state
|
217 |
+
|
218 |
+
client_state = client
|
219 |
+
response_queue_state = response_queue
|
220 |
+
previous_credentials_state = {
|
221 |
'username': HIVEMQ_USERNAME,
|
222 |
'password': HIVEMQ_PASSWORD,
|
223 |
'host': HIVEMQ_HOST,
|
|
|
225 |
'port': PORT
|
226 |
}
|
227 |
else:
|
228 |
+
client = client_state
|
229 |
+
response_queue = response_queue_state
|
230 |
|
231 |
# Prepare payload
|
232 |
payload = {"command": selected_command, "args": args}
|
|
|
253 |
else:
|
254 |
response_md = "### Response\nTimed out waiting for response. Is the on-device server running?"
|
255 |
return payload_md, response_md, None, client_state, response_queue_state, previous_credentials_state
|
256 |
+
|
257 |
# Now, set up the function to be called when the "Send Command" button is clicked
|
258 |
send_command_button.click(
|
259 |
fn=send_command,
|