Procházet zdrojové kódy

Update display during OTA web update

Just Call Me Koko před 6 roky
rodič
revize
f3d3a099b7

+ 12 - 3
esp32_marauder/MenuFunctions.cpp

@@ -112,7 +112,8 @@ MenuFunctions::MenuFunctions()
 // Function to check menu input
 void MenuFunctions::main()
 {
-  if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) {
+  if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
+      (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
     if (wifi_scan_obj.orient_display) {
       this->orientDisplay();
       wifi_scan_obj.orient_display = false;
@@ -139,6 +140,9 @@ void MenuFunctions::main()
   // getTouch causes a 10ms delay which makes beacon spam less effective
   //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
   pressed = display_obj.tft.getTouch(&t_x, &t_y);
+
+  //if (pressed)
+  //  Serial.println("Pressed, son");
   //boolean pressed = false;
 
   //Serial.print("getTouch: ");
@@ -147,7 +151,7 @@ void MenuFunctions::main()
 
   
   // This is if there are scans/attacks going on
-  if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed))
+  if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed) && (wifi_scan_obj.currentScanMode != OTA_UPDATE))
   {  
     // Stop the current scan
     if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
@@ -238,6 +242,7 @@ void MenuFunctions::RunSetup()
   wifiMenu.list = new SimpleList<MenuNode>(); // Get list in second menu ready
   bluetoothMenu.list = new SimpleList<MenuNode>(); // Get list in third menu ready
   generalMenu.list = new SimpleList<MenuNode>();
+  updateMenu.list = new SimpleList<MenuNode>();
 
   // WiFi menu stuff
   wifiSnifferMenu.list = new SimpleList<MenuNode>();
@@ -252,6 +257,7 @@ void MenuFunctions::RunSetup()
   mainMenu.name = " ESP32 Marauder ";
   wifiMenu.name = " WiFi ";
   generalMenu.name = " General Apps ";
+  updateMenu.name = " Update Firmware ";
   bluetoothMenu.name = " Bluetooth ";
   wifiSnifferMenu.name = " WiFi Sniffers ";
   wifiScannerMenu.name = " WiFi Scanners";
@@ -264,7 +270,7 @@ void MenuFunctions::RunSetup()
   addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, WIFI, [this](){changeMenu(&wifiMenu);});
   addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, BLUETOOTH, [this](){changeMenu(&bluetoothMenu);});
   addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, GENERAL_APPS, [this](){changeMenu(&generalMenu);});
-  addNodes(&mainMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; web_obj.setupOTAupdate();});
+  addNodes(&mainMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
   addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, REBOOT, [](){ESP.restart();});
 
   // Build WiFi Menu
@@ -312,6 +318,9 @@ void MenuFunctions::RunSetup()
   addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){display_obj.draw_tft = false; changeMenu(generalMenu.parentMenu);});
   addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, DRAW, [this](){display_obj.clearScreen(); display_obj.draw_tft = true;});
 
+  updateMenu.parentMenu = &mainMenu;
+  addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu); WiFi.softAPdisconnect(true);});
+
 
   // Set the current menu to the mainMenu
   changeMenu(&mainMenu);

+ 1 - 0
esp32_marauder/MenuFunctions.h

@@ -74,6 +74,7 @@ class MenuFunctions
     Menu wifiMenu;
     Menu bluetoothMenu;
     Menu generalMenu;
+    Menu updateMenu;
 
     // WiFi menu stuff
     Menu wifiSnifferMenu;

+ 44 - 1
esp32_marauder/Web.cpp

@@ -32,12 +32,26 @@ void Web::main()
 
 void Web::setupOTAupdate()
 {
+  display_obj.tft.setTextWrap(false);
+  display_obj.tft.setFreeFont(NULL);
+  display_obj.tft.setCursor(0, 100);
+  display_obj.tft.setTextSize(1);
+  display_obj.tft.setTextColor(TFT_WHITE);
+
+  display_obj.tft.print("Configuring update server...\n\n");  
   Serial.println("Configuring update server...");
+
+  display_obj.tft.setTextColor(TFT_YELLOW);
   
   // Start WiFi AP
   WiFi.softAP(ssid, password);
   Serial.println("");
-  
+
+  display_obj.tft.print("SSID: ");
+  display_obj.tft.println(ssid);
+  display_obj.tft.print("IP address: ");
+  display_obj.tft.print(WiFi.softAPIP());
+  display_obj.tft.print("\n");
   Serial.print("IP address: ");
   Serial.println(WiFi.softAPIP());
 
@@ -69,6 +83,10 @@ void Web::setupOTAupdate()
   }, [this]() {
     HTTPUpload& upload = server.upload();
     if (upload.status == UPLOAD_FILE_START) {
+      display_obj.tft.setTextColor(TFT_YELLOW);
+      display_obj.tft.print("Update: ");
+      display_obj.tft.print(upload.filename.c_str());
+      display_obj.tft.print("\n");
       Serial.printf("Update: %s\n", upload.filename.c_str());
       if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
         Update.printError(Serial);
@@ -78,9 +96,32 @@ void Web::setupOTAupdate()
       if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
         Update.printError(Serial);
       }
+      //display_obj.tft.println(upload.totalSize);
+      /*
+      String display_string = "";
+      display_obj.tft.setCursor(0, 164);
+      for (int i = 0; i < 40; i++) {
+        display_string.concat(" ");
+      }
+      */
+      display_obj.tft.setTextColor(TFT_CYAN);
+      display_obj.tft.fillRect(0, 164, 240, 8, TFT_BLACK);
+      //delay(1);
+      //display_obj.tft.print(display_string);
+      display_obj.tft.setCursor(0, 164);
+      display_obj.tft.print("Bytes complete: ");
+      display_obj.tft.print(upload.totalSize);
+      display_obj.tft.print("\n");
+      
+      //Serial.println(upload.totalSize);
     } else if (upload.status == UPLOAD_FILE_END) {
       if (Update.end(true)) { //true to set the size to the current progress
+        display_obj.tft.setTextColor(TFT_GREEN);
+        display_obj.tft.print("Update Success: ");
+        display_obj.tft.print(upload.totalSize);
+        display_obj.tft.print("\nRebooting...\n");
         Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
+        delay(1000);
       } else {
         Update.printError(Serial);
       }
@@ -88,5 +129,7 @@ void Web::setupOTAupdate()
   });
   server.begin();
 
+  display_obj.tft.setTextColor(TFT_GREEN);
+  display_obj.tft.println("\nCompleted update server setup");
   Serial.println("Completed update server setup");
 }

+ 4 - 0
esp32_marauder/Web.h

@@ -11,6 +11,10 @@ Code taken from espressif ESP32 OTA Update example
 #include <ESPmDNS.h>
 #include <Update.h>
 
+#include "Display.h"
+
+extern Display display_obj;
+
 class Web
 {
   private:

+ 9 - 6
esp32_marauder/esp32_marauder.ino

@@ -58,14 +58,17 @@ void loop()
   currentTime = millis();
 
   // Update all of our objects
-  if ((!display_obj.draw_tft) &&
-      (wifi_scan_obj.currentScanMode != OTA_UPDATE))
+  //if ((!display_obj.draw_tft) &&
+  //    (wifi_scan_obj.currentScanMode != OTA_UPDATE))
+  if (!display_obj.draw_tft)
   {
     display_obj.main(); 
     wifi_scan_obj.main(currentTime);
     //if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM))
     if (wifi_scan_obj.currentScanMode != WIFI_PACKET_MONITOR)
       menu_function_obj.main();
+      if (wifi_scan_obj.currentScanMode == OTA_UPDATE)
+        web_obj.main();
     delay(1);
   }
   else if ((display_obj.draw_tft) &&
@@ -73,10 +76,10 @@ void loop()
   {
     display_obj.drawStylus();
   }
-  else
-  {
-    web_obj.main();
-  }
+  //else
+  //{
+  //  web_obj.main();
+  //}
 
   //Serial.println(wifi_scan_obj.currentScanMode);
 

binární
esp32_marauder/esp32_marauder_v0_4_0_20200130.bin