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

Allow connection to wifi networks with no password #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion Software/src/morse_3_v3.0/MorsePreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Preferences pref; // use the Preferences library for storing and r
uint8_t MorsePreferences::menuPtr = 1; // current position of menu
String MorsePreferences::wlanSSID = ""; // SSID for connecting to the Internet
String MorsePreferences::wlanPassword = ""; // password for connecting to WiFi router
String MorsePreferences::wlanEmptyPassword = ""; // if set then no password required for connecting to WiFi router
String MorsePreferences::wlanTRXPeer = ""; // peer Morserino for WiFI TRX
uint32_t MorsePreferences::fileWordPointer = 0; // remember how far we have read the file in player mode / reset when loading new file
uint8_t MorsePreferences::promptPause = 2; // in echoTrainer mode, length of pause before we send next word; multiplied by interWordSpace
Expand Down Expand Up @@ -1224,6 +1225,9 @@ void MorsePreferences::readPreferences(String repository) {

MorsePreferences::wlanSSID = pref.getString("wlanSSID");
MorsePreferences::wlanPassword = pref.getString("wlanPassword");
MorsePreferences::wlanEmptyPassword = pref.getString("wlanEmptyPasswd"); // wlanEmptyPassword
//DEBUG("readPreferences - wlanEmptyPassword: \"" + String(MorsePreferences::wlanEmptyPassword) + "\"");
//DEBUG("readPreferences - pref.getString(\"wlanEmptyPassword\"): \"" + pref.getString("wlanEmptyPasswd") + "\"");
MorsePreferences::wlanTRXPeer = pref.getString("wlanTRXPeer", "");
MorsePreferences::lcwoKochSeq = pref.getBool("lcwoKochSeq");
MorsePreferences::useCustomCharSet = pref.getBool("useCustomChar");
Expand Down Expand Up @@ -1358,6 +1362,10 @@ void MorsePreferences::writePreferences(String repository) {
pref.putString("wlanSSID", MorsePreferences::wlanSSID);
if (MorsePreferences::wlanPassword != pref.getString("wlanPassword"))
pref.putString("wlanPassword", MorsePreferences::wlanPassword);
if (MorsePreferences::wlanEmptyPassword != pref.getString("wlanEmptyPasswd")){
//DEBUG("writePreferences - wlanEmptyPassword: \"" + String(MorsePreferences::wlanEmptyPassword) + "\"");
pref.putString("wlanEmptyPasswd", MorsePreferences::wlanEmptyPassword);
}
if (MorsePreferences::wlanTRXPeer != pref.getString("wlanTRXPeer"))
pref.putString("wlanTRXPeer", MorsePreferences::wlanTRXPeer);

Expand Down Expand Up @@ -1512,19 +1520,24 @@ void MorsePreferences::writeLastExecuted(uint8_t menuPtr)
pref.end(); // close namespace
}

void MorsePreferences::writeWifiInfo(String ssid, String passwd, String trxpeer)
void MorsePreferences::writeWifiInfo(String ssid, String passwd, String emptyPassword, String trxpeer)
{
if (ssid != "")
MorsePreferences::wlanSSID = ssid;
if (passwd != "")
MorsePreferences::wlanPassword = passwd;
MorsePreferences::wlanEmptyPassword = emptyPassword;
//if (trxpeer != "")
MorsePreferences::wlanTRXPeer = trxpeer;
pref.begin("morserino", false); // open the namespace as read/write
if (MorsePreferences::wlanSSID != pref.getString("wlanSSID"))
pref.putString("wlanSSID", MorsePreferences::wlanSSID);
if (MorsePreferences::wlanPassword != pref.getString("wlanPassword"))
pref.putString("wlanPassword", MorsePreferences::wlanPassword);
if (MorsePreferences::wlanEmptyPassword != pref.getString("wlanEmptyPasswd")) {
//DEBUG("writeWifiInfo - wlanEmptyPassword: \"" + String(MorsePreferences::wlanEmptyPassword) + "\"");
pref.putString("wlanEmptyPasswd", MorsePreferences::wlanEmptyPassword);
}
if (MorsePreferences::wlanTRXPeer != pref.getString("wlanTRXPeer"))
pref.putString("wlanTRXPeer", MorsePreferences::wlanTRXPeer);

Expand Down
3 changes: 2 additions & 1 deletion Software/src/morse_3_v3.0/MorsePreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace MorsePreferences
extern uint8_t menuPtr;
extern String wlanSSID;
extern String wlanPassword;
extern String wlanEmptyPassword;
extern String wlanTRXPeer;
extern uint32_t fileWordPointer;
extern uint8_t promptPause;
Expand Down Expand Up @@ -172,7 +173,7 @@ namespace MorsePreferences
void writeWordPointer();
void writeVolume();
void writeLastExecuted(uint8_t menuPtr);
void writeWifiInfo(String, String, String);
void writeWifiInfo(String, String, String, String);
void fireCharSeen(boolean wpmOnly);
void setCurrentOptions(prefPos *current, int size);
}
Expand Down
14 changes: 11 additions & 3 deletions Software/src/morse_3_v3.0/MorseWiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const char* MorseWiFi::myForm = "<html><head><meta charset='utf-8'><title>Get AP
"<input name='ssid' id='ssid' value='SSIDV'></div> <div>"
"<label for='pw'>WiFi Password?</label>"
"<input name='pw' id='pw'></div> <div>"
"<label for='nopw'>Empty Password?</label>"
"<input type='checkbox' name='nopw' id='nopw'></div> <div>"
"<label for='trxpeer'>WiFi TRX Peer IP/Host?</label>"
"<input name='trxpeer' id='trxpeer' value='PEERIPV'>"
"</div><div>(255.255.255.255 = Local Broadcast IP will be used as Peer if empty)"
Expand Down Expand Up @@ -275,7 +277,8 @@ void MorseWiFi::startAP() {
server.on("/set", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", "Wifi Info updated - now restarting Morserino-32...");
MorsePreferences::writeWifiInfo(String(server.arg("ssid")), String(server.arg("pw")), String(server.arg("trxpeer")));
//DEBUG("SSID: " + String(server.arg("ssid")) + " Password: " + String(server.arg("pw")) + " NoPW: " + String(server.arg("nopw")) + " Peer. " + String(server.arg("trxpeer")));
MorsePreferences::writeWifiInfo(String(server.arg("ssid")), String(server.arg("pw")), String(server.arg("nopw")), String(server.arg("trxpeer")));
//DEBUG("SSID: " + String(MorsePreferences::wlanSSID) + " Password: " + String(MorsePreferences::wlanPassword) + " Peer. " + String(MorsePreferences::wlanTRXPeer));
ESP.restart();
});
Expand Down Expand Up @@ -353,8 +356,13 @@ boolean MorseWiFi::wifiConnect() { // connect to local WLAN
// Connect to WiFi network
if (MorsePreferences::wlanSSID == "")
return internal::errorConnect(String("WiFi Not Conf"));

WiFi.begin(MorsePreferences::wlanSSID.c_str(), MorsePreferences::wlanPassword.c_str());

const char *wlanPasswd = MorsePreferences::wlanPassword.c_str();
if(MorsePreferences::wlanEmptyPassword == "on") {
//DEBUG("No password for WiFi");
wlanPasswd = NULL;
}
WiFi.begin(MorsePreferences::wlanSSID.c_str(), wlanPasswd);

// Wait for connection
long unsigned int wait = millis();
Expand Down