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

Fix JSON result on invalid channel

parent c8cde2a0
No related branches found
No related tags found
1 merge request!5Perform power down sequence from port expander trigger
......@@ -105,9 +105,6 @@ bool MPOD::message(const SNMP::Message *message) {
found++;
break;
case OID::OUTPUTSWITCH:
// Use private helper function to extract integer value
Serial.print("Output Switch Length: ");
Serial.println(varbind->getLength());
_on = getIntegerFromVarBind(varbind);
found++;
break;
......
......@@ -34,7 +34,7 @@ class MPOD {
UNKNOWN,
COUNT = UNKNOWN,
};
static inline const char *NAMES[] = {
// These are incomplete SNMP commands needing to be
// formatted with the channel id after the final dot
......@@ -46,7 +46,7 @@ class MPOD {
"1.3.6.1.4.1.19947.1.3.2.1.12.",
"1.3.6.1.4.1.19947.1.3.2.1.13.",
};
// Returns index of OID equals to name
// Returns UNKNOWN if none
static unsigned int match(const char *name) {
......@@ -58,8 +58,8 @@ class MPOD {
return UNKNOWN;
}
};
MPOD();
MPOD();
SNMP::Message* read(const uint16_t);
SNMP::Message* setChannelState(const uint16_t, const bool);
SNMP::Message* setTargetVoltage(const uint16_t, const float);
......
......@@ -274,10 +274,9 @@ void pollMPODChannel() {
}
}
String ret;
if (!channel) {
ret = "\"reason\": \"Invalid channel\"";
} else {
String ret = "\"Invalid channel\"";
if (channel) {
SNMP::Message *snmp_msg = mpod.read(channel);
snmp.send(snmp_msg, pproc.ipAddr, SNMP::Port::SNMP);
delete snmp_msg;
......@@ -285,20 +284,22 @@ void pollMPODChannel() {
delay(MPOD_UPDATE_LATENCY);
snmp.loop(); // Force loop to update now
if (mpod.getChannel()) {
if (mpod.getChannel()) { // Valid channel requested
ret = mpod.toJSON();
} else {
ret = "\"reason\": \"Invalid channel\"";
channel = 0;
}
}
String http_msg = "{\n";
http_msg += "\"success\": ";
http_msg += channel ? 1 : 0;
http_msg += ",\n";
http_msg += "\"arguments\": {";
http_msg += "\"channel\": ";
http_msg += channel;
http_msg += "},\n"; // arguments
http_msg += "\"status\": ";
http_msg += ret;
http_msg += ",\"success\": ";
http_msg += channel ? 1 : 0;
http_msg += "\n}";
http_msg += "}";
restServer.send(channel ? 200 : 406, "text/json", http_msg);
}
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