mq add done

This commit is contained in:
hg
2015-05-13 21:07:59 +02:00
parent b27f964e20
commit 98506ca883

View File

@ -92,18 +92,39 @@ String MqttConfig::exec(String params) {
if ((tokenStr != 0) && (*tokenStr != 0) &&
(addressStr != 0) && (*addressStr != 0) &&
(periodStr != 0) && (*periodStr != 0)) {
*out << "Token: " << tokenStr << endl;
*out << "Address: " << addressStr << endl;
*out << "Period: " << periodStr << endl;
int token = atoi(tokenStr);
bool validToken = ! ((token <= 0) || (token > 250));
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";
} 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 {
*out << "not enough arguments" << endl;
res = "failure";
}
// configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple);
} else if (params.startsWith("del ")) {
// delete an mbus client, params: index
int space = params.indexOf(' ');