save/load ip addresses as array
This commit is contained in:
parent
52cd7d469f
commit
d4e1108759
3 changed files with 31 additions and 13 deletions
|
@ -41,15 +41,16 @@
|
|||
#define CANGROW_BUILD "0000"
|
||||
#endif
|
||||
|
||||
#define CANGROW_SSID "CanGrow-unconfigured"
|
||||
|
||||
struct Config_WiFi {
|
||||
char ssid[32];
|
||||
char password[64];
|
||||
char ip[16];
|
||||
char netmask[16];
|
||||
char gateway[16];
|
||||
char dns[16];
|
||||
bool dhcp;
|
||||
byte ip[4] = {192,168,4,20};
|
||||
byte netmask[4] = {255,255,255,0};
|
||||
byte gateway[4] = {192,168,4,254};
|
||||
byte dns[4] = {0,0,0,0};
|
||||
bool dhcp = true;
|
||||
};
|
||||
|
||||
Config_WiFi configWifi;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -183,10 +183,15 @@ bool loadConfig() {
|
|||
JsonObject objWifi = doc["wifi"][0];
|
||||
strlcpy(configWifi.ssid, objWifi["ssid"], sizeof(configWifi.ssid));
|
||||
strlcpy(configWifi.password, objWifi["password"], sizeof(configWifi.password));
|
||||
strlcpy(configWifi.ip, objWifi["ip"], sizeof(configWifi.ip));
|
||||
strlcpy(configWifi.netmask, objWifi["netmask"], sizeof(configWifi.netmask));
|
||||
strlcpy(configWifi.gateway, objWifi["gateway"], sizeof(configWifi.gateway));
|
||||
strlcpy(configWifi.dns, objWifi["dns"], sizeof(configWifi.dns));
|
||||
|
||||
// load the ip addresses as array
|
||||
int i;
|
||||
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
|
||||
configWifi.dhcp = objWifi["dhcp"];
|
||||
|
||||
|
@ -246,10 +251,14 @@ void saveConfig() {
|
|||
JsonObject objWifi = doc["wifi"].add<JsonObject>();
|
||||
objWifi["ssid"] = configWifi.ssid;
|
||||
objWifi["password"] = configWifi.password;
|
||||
objWifi["ip"] = configWifi.ip;
|
||||
objWifi["netmask"] = configWifi.netmask;
|
||||
objWifi["gateway"] = configWifi.gateway;
|
||||
objWifi["dns"] = configWifi.dns;
|
||||
// save the ip addressess as array
|
||||
int i;
|
||||
for(i=0; i <4 ; i++) {
|
||||
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;
|
||||
|
||||
// * System *
|
||||
|
|
Loading…
Reference in a new issue