-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
135 lines (98 loc) · 4.18 KB
/
app.py
File metadata and controls
135 lines (98 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import gradio as gr
import requests
import json # or `import simplejson as json` if on Python < 2.6
def get_config(selected_sensor: gr.Dropdown):
# input is a str e.g.: s001 - 10.220.9.61 - Küche Bildshirm
values = selected_sensor.split(" - ")
print("request sent: ", f"http://{values[1]}:5000/get_config/")
response = requests.get(f"http://{values[1]}:5000/get_config/")
data = response.json()
IP_address = data["IP Address"]
Port = data["Port"]
Max_Timedelta = data["max_timedelta"]
Loop_Count = data["loop_count"]
Freq_send = data["Frequency_Send"]
Freq_update_config = data["Frequency_Update_Config"]
sleep_between_scanns = data["sleep_between_scans"]
len_value_list = data["len_value_list"]
filename_current_data = data["filename_current_data"]
api_command = data["api_command"]
id = data["ID"]
return data, IP_address, Port, Max_Timedelta, Loop_Count, Freq_send, Freq_update_config, sleep_between_scanns, len_value_list, filename_current_data, api_command, id
def send_config(IP_address, Port, Max_Timedelta, Loop_Count, Freq_send, Freq_update_config, sleep_between_scanns, len_value_list, filename_current_data, api_command, id, selected_sensor):
#check critical values
if IP_address == None:
raise ValueError("IP Address is None")
if id == None:
raise ValueError("ID is None")
data = {
"IP Address": IP_address,
"Port": int(Port),
"max_timedelta": int(Max_Timedelta),
"loop_count": int(Loop_Count),
"Frequency_Send": int(Freq_send),
"Frequency_Update_Config": int(Freq_update_config),
"sleep_between_scans": int(sleep_between_scanns),
"len_value_list": int(len_value_list),
"filename_current_data": filename_current_data,
"api_command": api_command,
"ID": id,
"Measured Powers": {
"MAC Adress": "value"
}
}
print("Data: \n", data)
values = selected_sensor.split(" - ")
response = requests.post(f"http://{values[1]}:5000/update_config/", json=data)
print("SENDING RESPONSE: ", response)
choices = [
"s001 - 10.220.9.61 - Küche Bildschirm",
"s002 - 10.220.9.67 - Hannah",
"s003 - 10.220.9.78 - Wohnzimmer",
"s004 - 10.220.9.110 - Küche Schrank",
"s005 - 10.220.9.83 - Bad"
]
with gr.Blocks() as app:
gr.Markdown("# 📡 Sensor Maintenance App")
with gr.Row():
with gr.Column():
selected_sensor = gr.Dropdown(choices)
config = gr.JSON(value=None)
with gr.Column():
IP_address = gr.Textbox(value=None, placeholder="IP Address to send to")
Port = gr.Number(value = 5000)
Max_Timedelta = gr.Number(value = 10)
Loop_Count = gr.Number(value= 100)
Freq_send = gr.Number(value = 5)
Freq_update_config = gr.Number(value=30)
sleep_between_scanns = gr.Number(value=0)
len_value_list = gr.Number(value=30)
filename_current_data = gr.Textbox(value= "data.json")
api_command = gr.Textbox("recieve_scan/")
id = gr.Textbox(value=None, placeholder="PUT SENSOR ID")
with gr.Row():
with gr.Column():
get_button = gr.Button("Get 📡")
with gr.Column():
send_button = gr.Button("Send 💨")
get_button.click(get_config, inputs=selected_sensor, outputs=[config, IP_address, Port, Max_Timedelta, Loop_Count, Freq_send, Freq_update_config, sleep_between_scanns, len_value_list, filename_current_data, api_command, id])
send_button.click(send_config, inputs=[IP_address, Port, Max_Timedelta, Loop_Count, Freq_send, Freq_update_config, sleep_between_scanns, len_value_list, filename_current_data, api_command, id, selected_sensor])
app.launch(inbrowser=True)
"""
{
IP Address: "10.220.9.82",
Port: 5000,
max_timedelta: 5,
loop_count: 100,
Frequency_Send: 3,
Frequency_Update_Config: 30,
sleep_between_scans: 0,
len_value_list: 20,
filename_current_data: "data.json",
api_command: "recieve_scan/",
ID: "s001",
Measured Powers: {
MAC Adress: "value"
}
}
"""