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

Add password to configuration ap #484

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions pio/lib/Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct iData
#if API_MQTT_HASSIO
bool my_hassio = false;
#endif
char my_ap_pw[TKIDSIZE];
};

extern iData myData;
Expand Down
12 changes: 10 additions & 2 deletions pio/src/iSpindel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravit
bool shouldSaveConfig = false;

iData myData;

#if API_MQTT_HASSIO
//myData.my_hassio = false;
bool my_hassio_changed = false;
Expand Down Expand Up @@ -163,6 +162,8 @@ bool readConfig()
}
else
{
if (doc.containsKey("apPW"))
strcpy(myData.my_ap_pw, doc["apPW"]);
if (doc.containsKey("Name"))
strcpy(myData.my_name, doc["Name"]);
if (doc.containsKey("Token"))
Expand Down Expand Up @@ -335,6 +336,7 @@ bool startConfiguration()
WiFiManagerParameter api_list(HTTP_API_LIST);
WiFiManagerParameter custom_api("selAPI", "selAPI", String(myData.my_api).c_str(), 20, TYPE_HIDDEN, WFM_NO_LABEL);

WiFiManagerParameter custom_ap_pw("apPW", "AP Mode PW", htmlencode(myData.my_ap_pw).c_str(), TKIDSIZE, "type=\"password\"");
WiFiManagerParameter custom_name("name", "iSpindel Name", htmlencode(myData.my_name).c_str(), TKIDSIZE);
WiFiManagerParameter custom_sleep("sleep", "Update Interval (s)", String(myData.my_sleeptime).c_str(), 6, TYPE_NUMBER);
WiFiManagerParameter custom_token("token", "Token/ API key", htmlencode(myData.my_token).c_str(), TKIDSIZE * 2);
Expand All @@ -361,6 +363,7 @@ bool startConfiguration()
"Thingname</LI><LI>Server must be Endpoint</LI><LI>Port must be 8883</LI><LI>Path/URI is Publish Topic</LI></UL>",
"<<<<< >>>>>", TKIDSIZE);

wifiManager.addParameter(&custom_ap_pw);
wifiManager.addParameter(&custom_name);
wifiManager.addParameter(&custom_sleep);
wifiManager.addParameter(&custom_vfact);
Expand Down Expand Up @@ -405,10 +408,14 @@ bool startConfiguration()
else
snprintf(ssid, sizeof ssid, "iSpindel_%s", myData.my_name);

wifiManager.startConfigPortal(ssid);
if (strlen(myData.my_ap_pw) == 0)
wifiManager.startConfigPortal(ssid);
else
wifiManager.startConfigPortal(ssid, myData.my_ap_pw);

strcpy(myData.my_polynominal, custom_polynom.getValue());

validateInput(custom_ap_pw.getValue(), myData.my_ap_pw);
validateInput(custom_name.getValue(), myData.my_name);
validateInput(custom_token.getValue(), myData.my_token);
validateInput(custom_server.getValue(), myData.my_server);
Expand Down Expand Up @@ -489,6 +496,7 @@ bool saveConfig()

DynamicJsonDocument doc(2048);

doc["apPW"] = myData.my_ap_pw;
doc["Name"] = myData.my_name;
doc["Token"] = myData.my_token;
doc["Sleep"] = myData.my_sleeptime;
Expand Down