mq add done
This commit is contained in:
@ -92,18 +92,39 @@ String MqttConfig::exec(String params) {
|
|||||||
if ((tokenStr != 0) && (*tokenStr != 0) &&
|
if ((tokenStr != 0) && (*tokenStr != 0) &&
|
||||||
(addressStr != 0) && (*addressStr != 0) &&
|
(addressStr != 0) && (*addressStr != 0) &&
|
||||||
(periodStr != 0) && (*periodStr != 0)) {
|
(periodStr != 0) && (*periodStr != 0)) {
|
||||||
*out << "Token: " << tokenStr << endl;
|
int token = atoi(tokenStr);
|
||||||
*out << "Address: " << addressStr << endl;
|
bool validToken = ! ((token <= 0) || (token > 250));
|
||||||
*out << "Period: " << periodStr << endl;
|
int address = atoi(addressStr);
|
||||||
|
bool validAddress = ! ((address <= 0) || (address > 250));
|
||||||
|
int period = atoi(periodStr);
|
||||||
|
bool validPeriod = ! ((period < 10) || (period > 3600));
|
||||||
|
|
||||||
|
if (validToken && validAddress && validPeriod) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
while (mc->m_mbusDevTuple[i].address != 0) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
mc->m_mbusDevTuple[i] = { (uint8_t)token, (uint8_t)address, (uint16_t)period };
|
||||||
|
configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple);
|
||||||
res = "done";
|
res = "done";
|
||||||
|
} else {
|
||||||
|
if (! validToken) {
|
||||||
|
*out << "Invalid token " << tokenStr << endl;
|
||||||
|
}
|
||||||
|
if (! validAddress) {
|
||||||
|
*out << "Invalid address " << addressStr << endl;
|
||||||
|
}
|
||||||
|
if (! validPeriod) {
|
||||||
|
*out << "Invalid period " << periodStr << endl;
|
||||||
|
}
|
||||||
|
res = "failure";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*out << "not enough arguments" << endl;
|
*out << "not enough arguments" << endl;
|
||||||
res = "failure";
|
res = "failure";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple);
|
|
||||||
} else if (params.startsWith("del ")) {
|
} else if (params.startsWith("del ")) {
|
||||||
// delete an mbus client, params: index
|
// delete an mbus client, params: index
|
||||||
int space = params.indexOf(' ');
|
int space = params.indexOf(' ');
|
||||||
|
Reference in New Issue
Block a user