Skip to content

Commit

Permalink
ssid and pw max length and check, sort instances on name
Browse files Browse the repository at this point in the history
SysModNetwork
- ssid max 31, password max 63 + check not null

SysModUI: initPassword: add maxlenght

SysModInstances:
- sort on name (instead of ip)
- (temp) hide some prints
  • Loading branch information
ewoudwijma committed May 16, 2024
1 parent ba84c8b commit 32f292f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ lib_deps =
build_flags =
-D APP=StarBase
-D PIOENV=$PIOENV
-D VERSION=24051208 ; Date and time (GMT!)
-D VERSION=24051519 ; Date and time (GMT!), update at every commit!!
-D CONFIG_ASYNC_TCP_USE_WDT=0
-D LFS_THREADSAFE ; enables use of semaphores in LittleFS driver
-D STARBASE_DEVMODE
Expand Down
39 changes: 21 additions & 18 deletions src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class SysModInstances:public SysModule {
// else
// mdl->setValue(message["id"].as<const char *>(), message["value"]);

ppf("handleNotifications i:%d json message %s\n", instanceUDP.remoteIP()[3], buffer);
// ppf("handleNotifications i:%d json message %s\n", instanceUDP.remoteIP()[3], buffer);

}
else {
Expand All @@ -450,20 +450,23 @@ class SysModInstances:public SysModule {
}

//remove inactive instances
bool erased = false;
for (std::vector<InstanceInfo>::iterator instance=instances.begin(); instance!=instances.end(); ) {
if (millis() - instance->timeStamp > 32000) { //assuming a ping each 30 seconds
instance = instances.erase(instance);
// ppf("insTbl remove inactive instances %d\n", instance->ip[3]);

for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar, UINT8_MAX, f_ValueFun); //no rowNr so all rows updated

ui->callVarFun("ddpInst", UINT8_MAX, f_UIFun);
ui->callVarFun("artInst", UINT8_MAX, f_UIFun);
erased = true;
}
else
++instance;
}
if (erased) {
ppf("insTbl remove inactive instances\n");
for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar, UINT8_MAX, f_ValueFun); //no rowNr so all rows updated

ui->callVarFun("ddpInst", UINT8_MAX, f_UIFun);
ui->callVarFun("artInst", UINT8_MAX, f_UIFun);
}
}

void sendSysInfoUDP()
Expand Down Expand Up @@ -567,7 +570,7 @@ class SysModInstances:public SysModule {
web->sendUDPCounter++;
web->sendUDPBytes+=sizeof(buffer);
instanceUDP.endPacket();
ppf("sendMessageUDP ip:%d b:%s\n", ip[3], buffer);
// ppf("sendMessageUDP ip:%d b:%s\n", ip[3], buffer);
}

}
Expand Down Expand Up @@ -598,7 +601,7 @@ class SysModInstances:public SysModule {
}

instances.push_back(instance);
std::sort(instances.begin(),instances.end(), [](InstanceInfo &a, InstanceInfo &b){ return a.ip < b.ip; });//Sorting the vector strcmp(a.name,b.name);
std::sort(instances.begin(),instances.end(), [](InstanceInfo &a, InstanceInfo &b){ return strcmp(a.name,b.name)<0; });
}

//update the instance in the instances array with the message data
Expand All @@ -621,7 +624,8 @@ class SysModInstances:public SysModule {
JsonDocument newData;
DeserializationError error = deserializeJson(newData, udpStarMessage.jsonString);
if (error || !newData.is<JsonObject>()) {
ppf("updateInstance json failed ip:%d e:%s\n", instance.ip[3], error.c_str(), udpStarMessage.jsonString);
// ppf("dev updateInstance json failed ip:%d e:%s\n", instance.ip[3], error.c_str(), udpStarMessage.jsonString);
//failed because some instances not on latest firmware, so turned off temporarily (tbd/wip)
}
else {
//check if instance belongs to the same group
Expand All @@ -634,11 +638,10 @@ class SysModInstances:public SysModule {
// if (mdl->getValue(pair.key().c_str) != pair.value())
mdl->setValue(pair.key().c_str(), pair.value());
}
instance.jsonData = newData; // deepcopy: https://github.com/bblanchon/ArduinoJson/issues/1023
// ppf("updateInstance json ip:%d", instance.ip[3]);
print->printJson(" d:", instance.jsonData);
}

instance.jsonData = newData; // deepcopy: https://github.com/bblanchon/ArduinoJson/issues/1023
ppf("updateInstance json ip:%d", instance.ip[3]);
print->printJson(" d:", instance.jsonData);
}
}
}
Expand All @@ -658,7 +661,7 @@ class SysModInstances:public SysModule {

// web->sendResponseObject();

// ppf("updateInstance updRow[%d] %s\n", instance - instances.begin(), instances[instance - instances.begin()].name);
// ppf("updateInstance updRow\n");

for (JsonObject childVar: mdl->varChildren("insTbl"))
ui->callVarFun(childVar, UINT8_MAX, f_ValueFun); //rowNr instance - instances.begin()
Expand All @@ -671,7 +674,7 @@ class SysModInstances:public SysModule {
} // for instances

if (!instanceFound) {
// ppf("insTbl new instance %s\n", messageIP.toString().c_str());
ppf("insTbl new instance %s\n", messageIP.toString().c_str());

ui->callVarFun("ddpInst", UINT8_MAX, f_UIFun); //UiFun as select changes
ui->callVarFun("artInst", UINT8_MAX, f_UIFun);
Expand Down Expand Up @@ -700,7 +703,7 @@ class SysModInstances:public SysModule {
InstanceInfo instance;
instance.ip = ip;
instances.push_back(instance);
std::sort(instances.begin(),instances.end(), [](InstanceInfo &a, InstanceInfo &b){ return a.ip < b.ip; });//Sorting the vector strcmp(a.name,b.name);
std::sort(instances.begin(),instances.end(), [](InstanceInfo &a, InstanceInfo &b){ return strcmp(a.name,b.name)<0; });
}

// InstanceInfo foundInstance;
Expand Down
10 changes: 5 additions & 5 deletions src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void SysModNetwork::setup() {
// ui->setComment(var, "List of defined and available Wifi APs");
// });

ui->initText(parentVar, "ssid", "", 32, false);
ui->initText(parentVar, "ssid", "", 31, false);

ui->initPassword(parentVar, "pw", "", 32, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initPassword(parentVar, "pw", "", 63, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Password");
return true;
Expand Down Expand Up @@ -123,8 +123,8 @@ void SysModNetwork::initConnection() {

const char * ssid = mdl->getValue("ssid");
const char * password = mdl->getValue("pw");
if (ssid && strlen(ssid)>0) {
char passXXX [32] = "";
if (ssid && strlen(ssid)>0 && password) {
char passXXX [64] = "";
for (int i = 0; i < strlen(password); i++) strncat(passXXX, "*", sizeof(passXXX)-1);
ppf("Connecting to WiFi %s / %s\n", ssid, passXXX);
WiFi.begin(ssid, password);
Expand All @@ -135,7 +135,7 @@ void SysModNetwork::initConnection() {
WiFi.setHostname(mdns->cmDNS); //use the mdns name (instance name or star-mac)
}
else
ppf("No SSID");
ppf("initConnection error s:%s p:%s\n", ssid?ssid:"No SSID", password?password:"No Password");

isConfirmedConnection = false; //need to test if really connected in handleConnection
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SysModUI: public SysModule {
return initVarAndUpdate<const char *>(parent, id, "file", value, 0, max, readOnly, varFun);
}
JsonObject initPassword(JsonObject parent, const char * id, const char * value = nullptr, unsigned8 max = 32, bool readOnly = false, VarFun varFun = nullptr) {
return initVarAndUpdate<const char *>(parent, id, "password", value, 0, 0, readOnly, varFun);
return initVarAndUpdate<const char *>(parent, id, "password", value, 0, max, readOnly, varFun);
}

JsonObject initNumber(JsonObject parent, const char * id, int value = UINT16_MAX, int min = 0, int max = UINT16_MAX, bool readOnly = false, VarFun varFun = nullptr) {
Expand Down

0 comments on commit 32f292f

Please sign in to comment.