diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index 058806a..5442aa8 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -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; diff --git a/Arduino/CanGrow/include/CanGrow_Core.h b/Arduino/CanGrow/include/CanGrow_Core.h index 7ac9079..1af4fb1 100644 --- a/Arduino/CanGrow/include/CanGrow_Core.h +++ b/Arduino/CanGrow/include/CanGrow_Core.h @@ -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); +} diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h index 6dfeb76..3e2dbb9 100644 --- a/Arduino/CanGrow/include/CanGrow_LittleFS.h +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -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(); 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 *