anktechsol commited on
Commit
f5b99c4
·
verified ·
1 Parent(s): 8ebd58d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import time
4
+
5
+ def mqtt_simulator(topic, qos, message):
6
+ time.sleep(0.5)
7
+ msg_id = random.randint(1000, 9999)
8
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
9
+ status = random.choice(["Published", "Published", "Published", "Queued"])
10
+
11
+ result = f"""### MQTT Message {status}
12
+
13
+ **Topic**: `{topic}`
14
+ **QoS Level**: {qos}
15
+ **Message ID**: {msg_id}
16
+ **Timestamp**: {timestamp}
17
+
18
+ **Message Content**:
19
+ ```
20
+ {message}
21
+ ```
22
+
23
+ 🔗 **Anktechsol** - IoT Solutions Expert
24
+ [Learn more](https://anktechsol.com)"""
25
+ return result
26
+
27
+ with gr.Blocks(title="MQTT Protocol Demo") as demo:
28
+ gr.Markdown("# 📡 MQTT Protocol Demonstration")
29
+ gr.Markdown("Interactive MQTT messaging demo - **Anktechsol**")
30
+
31
+ with gr.Row():
32
+ with gr.Column():
33
+ topic = gr.Textbox(label="Topic", value="iot/sensors/temperature", placeholder="Enter MQTT topic")
34
+ qos = gr.Radio(["0 - At most once", "1 - At least once", "2 - Exactly once"], label="QoS Level", value="1 - At least once")
35
+ message = gr.Textbox(label="Message Payload", value='{"temp":25.4,"humidity":60}', lines=3)
36
+ btn = gr.Button("Publish Message")
37
+
38
+ with gr.Column():
39
+ output = gr.Markdown()
40
+
41
+ btn.click(mqtt_simulator, inputs=[topic, qos, message], outputs=output)
42
+
43
+ gr.Markdown("""---
44
+ ### About MQTT & Anktechsol
45
+ MQTT is a lightweight messaging protocol for IoT. Expert IoT consulting at [anktechsol.com](https://anktechsol.com)""")
46
+
47
+ demo.launch()