Merge pull request #928 from justcallmekoko/develop

Add softAP to wifi general
This commit is contained in:
Just Call Me Koko
2025-10-02 11:50:14 -04:00
committed by GitHub
4 changed files with 222 additions and 47 deletions

View File

@@ -582,14 +582,13 @@ MenuFunctions::MenuFunctions()
}
}
void MenuFunctions::joinWiFiGFX(String essid){
void MenuFunctions::joinWiFiGFX(String essid, bool start_ap){
// Create one text area
ta1 = lv_textarea_create(lv_scr_act(), NULL);
lv_textarea_set_one_line(ta1, true);
lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
lv_obj_set_pos(ta1, 5, 20);
//lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
lv_textarea_set_text(ta1, essid.c_str());
lv_obj_set_event_cb(ta1, ta_event_cb);
@@ -600,8 +599,6 @@ MenuFunctions::MenuFunctions()
// Create second text area
ta2 = lv_textarea_create(lv_scr_act(), ta1);
//lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
//lv_textarea_set_pwd_show_time(ta2, 1000);
lv_textarea_set_cursor_hidden(ta2, true);
lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
@@ -614,7 +611,11 @@ MenuFunctions::MenuFunctions()
// Create a keyboard and apply the styles
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_set_event_cb(kb, join_wifi_keyboard_event_cb);
if (!start_ap)
lv_obj_set_event_cb(kb, join_wifi_keyboard_event_cb);
else
lv_obj_set_event_cb(kb, start_ap_keyboard_event_cb);
// Focus it on one of the text areas to start
lv_keyboard_set_textarea(kb, ta1);
@@ -629,7 +630,6 @@ MenuFunctions::MenuFunctions()
lv_keyboard_def_event_cb(kb, event);
if(event == LV_EVENT_APPLY){
printf("LV_EVENT_APPLY\n");
//String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
String ta1_text = lv_textarea_get_text(ta1);
String ta2_text = lv_textarea_get_text(ta2);
Serial.println(ta1_text);
@@ -640,9 +640,31 @@ MenuFunctions::MenuFunctions()
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
}else if(event == LV_EVENT_CANCEL){
printf("LV_EVENT_CANCEL\n");
//lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
menu_function_obj.deinitLVGL();
//wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
display_obj.exit_draw = true; // set everything back to normal
if (wifi_scan_obj.connected_network != "")
wifi_scan_obj.currentScanMode = WIFI_CONNECTED;
}
}
void start_ap_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
extern Display display_obj;
extern MenuFunctions menu_function_obj;
extern WiFiScan wifi_scan_obj;
lv_keyboard_def_event_cb(kb, event);
if(event == LV_EVENT_APPLY){
printf("LV_EVENT_APPLY\n");
String ta1_text = lv_textarea_get_text(ta1);
String ta2_text = lv_textarea_get_text(ta2);
Serial.println(ta1_text);
Serial.println(ta2_text);
if (wifi_scan_obj.startWiFi(ta1_text, ta2_text))
wifi_scan_obj.currentScanMode = WIFI_CONNECTED;
else
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
}else if(event == LV_EVENT_CANCEL){
printf("LV_EVENT_CANCEL\n");
menu_function_obj.deinitLVGL();
display_obj.exit_draw = true; // set everything back to normal
if (wifi_scan_obj.connected_network != "")
wifi_scan_obj.currentScanMode = WIFI_CONNECTED;
@@ -1515,29 +1537,20 @@ void MenuFunctions::updateStatusBar()
wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
#ifdef HAS_FULL_SCREEN
//display_obj.tft.setCursor(100, 0);
//display_obj.tft.setFreeFont(2);
//display_obj.tft.print("D:" + String(getDRAMUsagePercent()) + "%");
#ifndef HAS_PSRAM
display_obj.tft.drawString("D:" + String(getDRAMUsagePercent()) + "%", 100, 0, 2);
#else
//display_obj.tft.drawString("D:" + String(getDRAMUsagePercent()) + "%" + " P:" + String(getPSRAMUsagePercent()) + "%", 100, 0, 1);
display_obj.tft.drawString("D:" + String(getDRAMUsagePercent()) + "%", 100, 0, 1);
display_obj.tft.drawString("P:" + String(getPSRAMUsagePercent()) + "%", 100, 8, 1);
#endif
//display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
#endif
#ifdef HAS_MINI_SCREEN
//display_obj.tft.setCursor(TFT_WIDTH/1.75, 0);
//display_obj.tft.setFreeFont(1);
//display_obj.tft.print("D:" + String(getDRAMUsagePercent()) + "%");
#ifndef HAS_PSRAM
display_obj.tft.drawString("D:" + String(getDRAMUsagePercent()) + "%", TFT_WIDTH/1.75, 0, 1);
#else
display_obj.tft.drawString("D:" + String(getDRAMUsagePercent()) + "%" + " P:" + String(getPSRAMUsagePercent()) + "%", TFT_WIDTH/1.75, 0, 1);
#endif
//display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
#endif
}
@@ -2551,6 +2564,8 @@ void MenuFunctions::RunSetup()
this->changeMenu(&selectProbeSSIDsMenu);
});
clearSSIDsMenu.parentMenu = &wifiGeneralMenu;
#ifdef HAS_ILI9341
this->addNodes(&wifiGeneralMenu, text_table1[1], TFTNAVY, NULL, KEYBOARD_ICO, [this](){
display_obj.clearScreen();
@@ -2576,32 +2591,6 @@ void MenuFunctions::RunSetup()
this->changeMenu(&clearAPsMenu);
wifi_scan_obj.RunClearStations();
});
/*#ifdef HAS_ILI9341
// Select APs on OG
this->addNodes(&wifiGeneralMenu, text_table1[56], TFTNAVY, NULL, KEYBOARD_ICO, [this](){
display_obj.clearScreen();
wifi_scan_obj.currentScanMode = LV_ADD_SSID;
wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
addAPGFX();
});
// Select Stations on OG
this->addNodes(&wifiGeneralMenu, text_table1[61], TFTLIGHTGREY, NULL, KEYBOARD_ICO, [this](){
display_obj.clearScreen();
wifi_scan_obj.currentScanMode = LV_ADD_SSID;
wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
addStationGFX();
});
// Select Evil Portal Files on OG
this->addNodes(&wifiGeneralMenu, "Select EP HTML File", TFTCYAN, NULL, KEYBOARD_ICO, [this](){
display_obj.clearScreen();
wifi_scan_obj.currentScanMode = LV_ADD_SSID;
wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
selectEPHTMLGFX();
});
apInfoMenu.parentMenu = &wifiGeneralMenu;
this->addNodes(&apInfoMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
this->changeMenu(apInfoMenu.parentMenu);
});*/
//#else // Mini EP HTML select
this->addNodes(&wifiGeneralMenu, "Select EP HTML File", TFTCYAN, NULL, KEYBOARD_ICO, [this](){
// Add the back button
@@ -2860,7 +2849,88 @@ void MenuFunctions::RunSetup()
}
});
wifiStationMenu.parentMenu = &wifiAPMenu;
this->addNodes(&wifiGeneralMenu, "Start AP", TFTGREEN, NULL, KEYBOARD_ICO, [this](){
ssidsMenu.parentMenu = &wifiGeneralMenu;
// Add the back button
ssidsMenu.list->clear();
this->addNodes(&ssidsMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
this->changeMenu(ssidsMenu.parentMenu);
});
// Populate the menu with buttons
for (int i = 0; i < ssids->size(); i++) {
// This is the menu node
this->addNodes(&ssidsMenu, ssids->get(i).essid, TFTCYAN, NULL, 255, [this, i](){
// Join WiFi using mini keyboard
#ifdef HAS_MINI_KB
this->changeMenu(&miniKbMenu);
String password = this->miniKeyboard(&miniKbMenu, true);
if (password != "") {
Serial.println("Using SSID: " + (String)ssids->get(i).essid + " Password: " + (String)password);
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
wifi_scan_obj.startWiFi(ssids->get(i).essid, password);
this->changeMenu(current_menu);
}
#endif
// Join WiFi using touch screen keyboard
#ifdef HAS_TOUCH
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
joinWiFiGFX(ssids->get(i).essid, true);
#endif
});
}
this->changeMenu(&ssidsMenu);
});
/*this->addNodes(&wifiGeneralMenu, "Start Saved AP", TFTWHITE, NULL, KEYBOARD_ICO, [this](){
String ssid = settings_obj.loadSetting<String>("APSSID");
String pw = settings_obj.loadSetting<String>("APPW");
if ((ssid != "") && (pw != "")) {
wifi_scan_obj.startWiFi(ssid, pw, false);
this->changeMenu(&wifiGeneralMenu);
}
else {
// Add the back button
wifiAPMenu.list->clear();
this->addNodes(&wifiAPMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
this->changeMenu(wifiAPMenu.parentMenu);
});
// Populate the menu with buttons
for (int i = 0; i < ssids->size(); i++) {
// This is the menu node
this->addNodes(&wifiAPMenu, ssids->get(i).essid, TFTCYAN, NULL, 255, [this, i](){
// Join WiFi using mini keyboard
#ifdef HAS_MINI_KB
this->changeMenu(&miniKbMenu);
String password = this->miniKeyboard(&miniKbMenu, true);
if (password != "") {
Serial.println("Using SSID: " + (String)ssids->get(i).essid + " Password: " + (String)password);
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
wifi_scan_obj.startWiFi(ssids->get(i).essid, password);
this->changeMenu(current_menu);
}
#endif
// Join WiFi using touch screen keyboard
#ifdef HAS_TOUCH
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
joinWiFiGFX(ssids->get(i).essid, true);
#endif
});
}
this->changeMenu(&wifiAPMenu);
}
});*/
wifiStationMenu.parentMenu = &ssidsMenu;
this->addNodes(&wifiStationMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
this->changeMenu(wifiStationMenu.parentMenu);
});
@@ -2957,7 +3027,7 @@ void MenuFunctions::RunSetup()
});
// Build clear ssids menu
clearSSIDsMenu.parentMenu = &wifiGeneralMenu;
this->addNodes(&clearSSIDsMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
this->changeMenu(clearSSIDsMenu.parentMenu);
});

View File

@@ -102,6 +102,7 @@ PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
PROGMEM static void join_wifi_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void start_ap_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void html_list_cb(lv_obj_t * btn, lv_event_t event);
PROGMEM static void ap_list_cb(lv_obj_t * btn, lv_event_t event);
@@ -284,7 +285,7 @@ class MenuFunctions
String loaded_file = "";
void joinWiFiGFX(String essid);
void joinWiFiGFX(String essid, bool start_ap = false);
void setGraphScale(float scale);
void initLVGL();
void deinitLVGL();

View File

@@ -854,6 +854,108 @@ bool WiFiScan::joinWiFi(String ssid, String password, bool gui)
return true;
}
bool WiFiScan::startWiFi(String ssid, String password, bool gui)
{
static const char * btns[] ={text16, ""};
int count = 0;
if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
#ifdef HAS_TOUCH
if (gui) {
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, text_table4[2]);
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); //Align to the corner
}
#endif
this->wifi_initialized = true;
this->currentScanMode = WIFI_CONNECTED;
return true;
}
else if (WiFi.status() == WL_CONNECTED) {
Serial.println("Already connected. Disconnecting...");
WiFi.disconnect();
}
WiFi.disconnect(true);
delay(100);
WiFi.mode(WIFI_MODE_AP);
//esp_wifi_set_mode(WIFI_IF_STA);
this->setMac();
if (password != "")
WiFi.softAP(ssid.c_str(), password.c_str());
else
WiFi.softAP(ssid.c_str());
#ifdef HAS_SCREEN
#ifdef HAS_MINI_KB
if (gui) {
display_obj.clearScreen();
display_obj.tft.setCursor(0, TFT_HEIGHT / 2);
display_obj.tft.setTextSize(1);
display_obj.tft.print("Starting");
display_obj.tft.setTextWrap(true, false);
}
#endif
#endif
Serial.print("Started WiFi");
#ifdef HAS_TOUCH
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, text_table4[4]);
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); //Align to the corner
#endif
this->connected_network = ssid;
this->ip_addr = WiFi.softAPIP();
this->gateway = WiFi.gatewayIP();
this->subnet = WiFi.subnetMask();
Serial.println("\nStarted AP");
Serial.print("IP address: ");
Serial.println(this->ip_addr);
Serial.print("Gateway: ");
Serial.println(this->gateway);
Serial.print("Netmask: ");
Serial.println(this->subnet);
Serial.print("MAC: ");
Serial.println(WiFi.macAddress());
#ifdef HAS_SCREEN
#ifdef HAS_MINI_KB
display_obj.tft.println("\nStarted AP");
display_obj.tft.print("IP address: ");
display_obj.tft.println(this->ip_addr);
display_obj.tft.print("Gateway: ");
display_obj.tft.println(this->gateway);
display_obj.tft.print("Netmask: ");
display_obj.tft.println(this->subnet);
display_obj.tft.print("MAC: ");
display_obj.tft.println(WiFi.macAddress());
display_obj.tft.println("Returning...");
delay(2000);
#endif
#endif
this->wifi_initialized = true;
#ifndef HAS_TOUCH
this->currentScanMode = WIFI_CONNECTED;
#ifdef HAS_SCREEN
display_obj.tft.setTextWrap(false, false);
#endif
#endif
//settings_obj.saveSetting<bool>("APSSID", ssid);
//settings_obj.saveSetting<bool>("APPW", password);
return true;
}
// Apply WiFi settings
void WiFiScan::initWiFi(uint8_t scan_mode) {
// Set the channel
@@ -8851,7 +8953,7 @@ void WiFiScan::main(uint32_t currentTime)
gps_obj.disable_queue();
#endif
if (WiFi.status() == WL_CONNECTED) {
if ((WiFi.status() == WL_CONNECTED) || (WiFi.softAPIP() != IPAddress(0,0,0,0))) {
this->wifi_connected = true;
this->wifi_initialized = true;
}

View File

@@ -135,6 +135,7 @@
#define WIFI_SCAN_HTTPS 66
#define WIFI_SCAN_SMTP 67
#define WIFI_SCAN_RDP 68
#define WIFI_HOSTSPOT 69 // Nice
#define WIFI_ATTACK_FUNNY_BEACON 99
@@ -721,6 +722,7 @@ class WiFiScan
bool shutdownBLE();
bool scanning();
bool joinWiFi(String ssid, String password, bool gui = true);
bool startWiFi(String ssid, String password, bool gui = true);
String getStaMAC();
String getApMAC();
String freeRAM();