sgbaird commited on
Commit
642cda8
1 Parent(s): 758a4c9

chore: Fix bug preventing multiple RGB commands from being sent

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -43,9 +43,11 @@ R = st.slider("Select the Red value:", min_value=0, max_value=max_value, value=0
43
  G = st.slider("Select the Green value:", min_value=0, max_value=max_value, value=0)
44
  B = st.slider("Select the Blue value:", min_value=0, max_value=max_value, value=0)
45
 
46
- # Initialize session state for messages
47
  if "messages" not in st.session_state:
48
  st.session_state.messages = []
 
 
49
 
50
  # Queue to hold sensor data
51
  sensor_data_queue = queue.Queue()
@@ -88,10 +90,12 @@ def send_and_receive(client, command_topic, msg, queue_timeout=60):
88
 
89
 
90
  # Publish button
91
- if st.button("Send RGB Command"):
92
  if not PICO_ID or not HIVEMQ_HOST or not HIVEMQ_USERNAME or not HIVEMQ_PASSWORD:
93
  st.error("Please enter all required fields.")
94
  else:
 
 
95
  client = get_paho_client(
96
  sensor_data_topic,
97
  HIVEMQ_HOST,
@@ -106,6 +110,7 @@ if st.button("Send RGB Command"):
106
  client, command_topic, command_msg, queue_timeout=30
107
  )
108
 
 
109
  st.success("Command sent successfully!")
110
  st.write("Sensor Data Received:", sensor_data)
111
 
 
43
  G = st.slider("Select the Green value:", min_value=0, max_value=max_value, value=0)
44
  B = st.slider("Select the Blue value:", min_value=0, max_value=max_value, value=0)
45
 
46
+ # Initialize session state for messages and lock state
47
  if "messages" not in st.session_state:
48
  st.session_state.messages = []
49
+ if "locked" not in st.session_state:
50
+ st.session_state.locked = False
51
 
52
  # Queue to hold sensor data
53
  sensor_data_queue = queue.Queue()
 
90
 
91
 
92
  # Publish button
93
+ if st.button("Send RGB Command") and not st.session_state.locked:
94
  if not PICO_ID or not HIVEMQ_HOST or not HIVEMQ_USERNAME or not HIVEMQ_PASSWORD:
95
  st.error("Please enter all required fields.")
96
  else:
97
+ st.session_state.locked = True
98
+
99
  client = get_paho_client(
100
  sensor_data_topic,
101
  HIVEMQ_HOST,
 
110
  client, command_topic, command_msg, queue_timeout=30
111
  )
112
 
113
+ st.session_state.locked = False
114
  st.success("Command sent successfully!")
115
  st.write("Sensor Data Received:", sensor_data)
116