Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customize wifi ap ssid and pwd #340

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ extern String ssid;

extern String pwd;

extern String ap_ssid;

extern String ap_pwd;

extern String fileToCopy;

extern int rotation;
Expand Down
2 changes: 1 addition & 1 deletion src/core/menu_items/WifiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void WifiMenu::optionsMenu() {
if(!wifiConnected) {
options = {
{"Connect Wifi", [=]() { wifiConnectMenu(); }}, //wifi_common.h
{"WiFi AP", [=]() { wifiConnectMenu(true); displayInfo("pwd: brucenet", true); }},//wifi_common.h
{"WiFi AP", [=]() { wifiConnectMenu(true); displayInfo("pwd: " + ap_pwd, true); }},//wifi_common.h
};
} else {
options = {
Expand Down
15 changes: 14 additions & 1 deletion src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void getConfigs() {
if(file) {
// init with default settings
#if ROTATION > 1
file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":" + String(LED) + ",\"IrRx\":" + String(GROVE_SCL) + ",\"RfTx\":" + String(GROVE_SDA) + ",\"RfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfFxdFreq\":1,\"RfScanRange\":3,\"RfidModule\":" + String(RfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]");
file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":" + String(LED) + ",\"IrRx\":" + String(GROVE_SCL) + ",\"RfTx\":" + String(GROVE_SDA) + ",\"RfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfFxdFreq\":1,\"RfScanRange\":3,\"RfidModule\":" + String(RfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wifi_ap\":{\"ssid\":\"BruceNet\",\"pwd\":\"brucenet\"},\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]");
#else
file.print("[{\"rot\":1,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":" + String(LED) + ",\"IrRx\":" + String(GROVE_SCL) + ",\"RfTx\":" + String(GROVE_SDA) + ",\"RfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfFxdFreq\":1,\"RfScanRange\":3,\"RfidModule\":" + String(RfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]");
#endif
Expand Down Expand Up @@ -711,6 +711,14 @@ void getConfigs() {

if(!setting.containsKey("wifi")) { count++; log_i("Fail"); }

if(setting.containsKey("wifi_ap")) {
JsonObject wifiAp = setting["wifi_ap"].as<JsonObject>();
if (wifiAp.containsKey("ssid")) { ap_ssid = wifiAp["ssid"].as<String>(); } else { count++; log_i("Fail"); }
if (wifiAp.containsKey("pwd")) { ap_pwd = wifiAp["pwd"].as<String>(); } else { count++; log_i("Fail"); }
} else {
count++; log_i("Fail");
}

if(setting.containsKey("wigleBasicToken")) { wigleBasicToken = setting["wigleBasicToken"].as<String>(); } else { count++; log_i("Fail"); }

if(setting.containsKey("devMode")) { devMode = setting["devMode"].as<int>(); } else { count++; log_i("Fail"); }
Expand Down Expand Up @@ -770,6 +778,11 @@ void saveConfigs() {
WifiObj["pwd"] = "myNetPassword";
}
}
if(!setting.containsKey("wifi_ap")) {
JsonObject WifiAp = setting["wifi_ap"].to<JsonObject>();
WifiAp["ssid"] = ap_ssid;
WifiAp["pwd"] = ap_pwd;
}
setting["wigleBasicToken"] = wigleBasicToken;
setting["devMode"] = devMode;
setting["soundEnabled"] = soundEnabled;
Expand Down
3 changes: 2 additions & 1 deletion src/core/wifi_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ bool wifiConnect(String ssid, int encryptation, bool isAP) {
IPAddress AP_GATEWAY(172, 0, 0, 1);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0));
WiFi.softAP("BruceNet", "brucenet", 6,0,4,false); // TODO: customize options via bruce.conf
getConfigs();
WiFi.softAP(ap_ssid, ap_pwd, 6,0,4,false);
wifiIP = WiFi.softAPIP().toString(); // update global var
Serial.print("IP: "); Serial.println(wifiIP);
wifiConnected=true;
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ String wui_usr="admin";
String wui_pwd="bruce";
String ssid;
String pwd;
String ap_ssid="BruceNet";
String ap_pwd="brucenet";
std::vector<Option> options;
const int bufSize = 1024;
uint8_t buff[1024] = {0};
Expand Down
Loading