Skip to content
Snippets Groups Projects
Commit d43e67f5 authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Test power down endpoint

parent 6b2a2143
No related branches found
No related tags found
No related merge requests found
Pipeline #164867 passed
......@@ -26,6 +26,7 @@ void initializeRoutes() {
restServer.on("/poll", pollMPODChannel);
restServer.on("/power", powerGroup);
restServer.on("/alloff", powerAllOff);
restServer.begin();
Serial.println("REST Server Started");
......@@ -217,6 +218,43 @@ void powerGroup() {
restServer.send(success ? 200 : 406, "text/json", http_msg);
}
void powerAllOff() {
String group;
String groups;
bool success = false;
for (uint8_t i = 0; i < restServer.args(); i++) {
// Check for token to prevent accidental power down
if (restServer.argName(i) == "token" && restServer.arg(i) == "CWH") {
success = true;
}
}
if (success) {
for (uint8_t groupIdx = pproc.stagesCount; groupIdx >= 0; groupIdx--) {
group = pproc.stages[groupIdx].name;
groups += group;
groups += ",";
success = pproc.powerOff(group);
if (!success) {
break;
}
}
}
String http_msg = "{\n";
http_msg += "\"arguments\":{";
http_msg += "\"groups\":\"" + groups + "\",";
http_msg += "\"success\":" + String(success);
if (success) {
http_msg += ",\n\"status\":\n";
http_msg += pproc.toJSON();
}
http_msg += "\n}";
restServer.send(success ? 200 : 406, "text/json", http_msg);
}
void pollMPODChannel() {
uint16_t channel = 0;
for (uint8_t i = 0; i < restServer.args(); i++) {
......
......@@ -12,3 +12,4 @@ void sendSNMP(); // /send?ch=107&output=on
void panel(); // / show a status page
void pollMPODChannel(); // /poll?ch=1
void powerGroup(); // /power?group=ASICS&output=on
void powerAllOff(); // /alloff?token=CWH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment