save/load ip addresses as array

This commit is contained in:
Marcus 2024-10-19 04:25:22 +02:00
parent 52cd7d469f
commit d4e1108759
3 changed files with 31 additions and 13 deletions

View file

@ -41,15 +41,16 @@
#define CANGROW_BUILD "0000" #define CANGROW_BUILD "0000"
#endif #endif
#define CANGROW_SSID "CanGrow-unconfigured"
struct Config_WiFi { struct Config_WiFi {
char ssid[32]; char ssid[32];
char password[64]; char password[64];
char ip[16]; byte ip[4] = {192,168,4,20};
char netmask[16]; byte netmask[4] = {255,255,255,0};
char gateway[16]; byte gateway[4] = {192,168,4,254};
char dns[16]; byte dns[4] = {0,0,0,0};
bool dhcp; bool dhcp = true;
}; };
Config_WiFi configWifi; Config_WiFi configWifi;

View file

@ -45,3 +45,11 @@ void Panic() {
} }
void WifiConnect() {
}
void WifiAp() {
Serial.printf(":: [WiFi] create access point: %s\n", CANGROW_SSID);
WiFi.softAPConfig(configWifi.ip, configWifi.gateway, configWifi.netmask);
}

View file

@ -183,10 +183,15 @@ bool loadConfig() {
JsonObject objWifi = doc["wifi"][0]; JsonObject objWifi = doc["wifi"][0];
strlcpy(configWifi.ssid, objWifi["ssid"], sizeof(configWifi.ssid)); strlcpy(configWifi.ssid, objWifi["ssid"], sizeof(configWifi.ssid));
strlcpy(configWifi.password, objWifi["password"], sizeof(configWifi.password)); strlcpy(configWifi.password, objWifi["password"], sizeof(configWifi.password));
strlcpy(configWifi.ip, objWifi["ip"], sizeof(configWifi.ip));
strlcpy(configWifi.netmask, objWifi["netmask"], sizeof(configWifi.netmask)); // load the ip addresses as array
strlcpy(configWifi.gateway, objWifi["gateway"], sizeof(configWifi.gateway)); int i;
strlcpy(configWifi.dns, objWifi["dns"], sizeof(configWifi.dns)); for(i=0; i <4 ; i++) {
configWifi.ip[i] = objWifi["ip"][i];
configWifi.netmask[i] = objWifi["netmask"][i];
configWifi.gateway[i] = objWifi["gateway"][i];
configWifi.dns[i] = objWifi["dns"][i];
}
// Copy bool / int directly into struct // Copy bool / int directly into struct
configWifi.dhcp = objWifi["dhcp"]; configWifi.dhcp = objWifi["dhcp"];
@ -246,10 +251,14 @@ void saveConfig() {
JsonObject objWifi = doc["wifi"].add<JsonObject>(); JsonObject objWifi = doc["wifi"].add<JsonObject>();
objWifi["ssid"] = configWifi.ssid; objWifi["ssid"] = configWifi.ssid;
objWifi["password"] = configWifi.password; objWifi["password"] = configWifi.password;
objWifi["ip"] = configWifi.ip; // save the ip addressess as array
objWifi["netmask"] = configWifi.netmask; int i;
objWifi["gateway"] = configWifi.gateway; for(i=0; i <4 ; i++) {
objWifi["dns"] = configWifi.dns; objWifi["ip"][i] = configWifi.ip[i];
objWifi["netmask"][i] = configWifi.netmask[i];
objWifi["gateway"][i] = configWifi.gateway[i];
objWifi["dns"][i] = configWifi.dns[i];
}
objWifi["dhcp"] = configWifi.dhcp; objWifi["dhcp"] = configWifi.dhcp;
// * System * // * System *