Skip to content

Commit

Permalink
post and get on the same port handle json
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedimarco00 committed Feb 13, 2024
1 parent 5987f3a commit 771e4d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
11 changes: 3 additions & 8 deletions river-monitoring-dashboard/river-monitoring-dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_post_data():
Input("send-autoMode", "n_clicks")
])
def send_manualMode(n_clicks):
url = "http://localhost:8051/api/postdata"
url = "http://localhost:8050/api/postdata"
if n_clicks is None:
return [""]
else:
Expand All @@ -85,15 +85,10 @@ def send_manualMode(n_clicks):
[Input("send-valveValue", "n_clicks")],
[State("valveValue", "value")])
def send_valveValue(n_clicks, valveValue):
url = "http://127.0.0.1:8050/api/postdata"
url = "http://localhost:8050/api/postdata"
if n_clicks > 0:
data = {
"valveValue": valveValue,
<<<<<<< HEAD:river-monitoring-dashboard/dashboard.py
"isManual": False
=======
"isManual": True
>>>>>>> 813bc22bd155b19aea2c45c010e24b02990f1526:river-monitoring-dashboard/river-monitoring-dashboard.py
"valveValue": valveValue
}
response = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})
print(response.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ private void handleAddNewData(RoutingContext routingContext) {
if (res == null) {
sendError(400, response);
} else {
int valveValue = res.getInteger("valveValue");
boolean isManual = res.getBoolean("isManual");
System.err.println("Valve value received from dashboard: " + valveValue + " and isManual: " + isManual);
try {
int valveValue = res.getInteger("valveValue");
broker.getSystemController().setValveValueFromDashboard(valveValue);
broker.getSystemController().setIsManual(true);
System.out.println("[OPERATOR] Valve Value set manually");
} catch (Exception ex) {

}

try {
boolean isManual = res.getBoolean("isManual");
broker.getSystemController().setIsManual(isManual);
} catch (Exception ex) {

}
response.setStatusCode(200).end();
broker.getSystemController().setValveValueFromDashboard(valveValue);
broker.getSystemController().setIsManual(isManual);
}
}

Expand Down

0 comments on commit 771e4d4

Please sign in to comment.