Just Call Me Koko 6 лет назад
Родитель
Сommit
9af90a2346

+ 1 - 1
esp32_marauder/Display.h

@@ -54,7 +54,7 @@ class Display
     TFT_eSPI tft = TFT_eSPI();
     TFT_eSprite img = TFT_eSprite(&tft);
     TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
-    String version_number = "v0.3.2";
+    String version_number = "v0.4.0";
 
     bool printing = false;
     bool loading = false;

+ 8 - 1
esp32_marauder/MenuFunctions.cpp

@@ -97,7 +97,13 @@ PROGMEM const unsigned char menu_icons[][66] = {
     0xEF, 0xFB, 0x3E, 0xCF, 0x7B, 0x3E, 0xAF, 0xB5, 0x3E, 0x6F, 0xEF, 0x3E, 
     0xEF, 0xDE, 0x3E, 0xAF, 0xB5, 0x3E, 0xCF, 0x7B, 0x3E, 0xDF, 0x7B, 0x3F, 
     0xBF, 0xBB, 0x3F, 0x7F, 0xDB, 0x3F, 0xFF, 0xEA, 0x3F, 0xFF, 0xF1, 0x3F, 
-    0xFF, 0xFB, 0x3F, 0xFF, 0xFF, 0x3F}};
+    0xFF, 0xFB, 0x3F, 0xFF, 0xFF, 0x3F},
+    {0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xE0, 0x3F, 0x3F, 0x80, 0x3F, // Update: 16
+    0x1F, 0x00, 0x3F, 0x0F, 0x00, 0x3E, 0x07, 0x00, 0x3C, 0x07, 0x08, 0x3C, 
+    0x03, 0x18, 0x38, 0x03, 0x38, 0x38, 0xC3, 0x7F, 0x38, 0xC3, 0x7F, 0x38, 
+    0x03, 0x38, 0x38, 0x03, 0x18, 0x38, 0x07, 0x08, 0x3C, 0x07, 0x00, 0x3C, 
+    0x0F, 0x00, 0x3E, 0x1F, 0x00, 0x3F, 0x3F, 0x80, 0x3F, 0xFF, 0xE0, 0x3F, 
+    0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F}};
 
 MenuFunctions::MenuFunctions()
 {
@@ -258,6 +264,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, "Reboot", TFT_LIGHTGREY, NULL, REBOOT, [](){ESP.restart();});
 
   // Build WiFi Menu

+ 3 - 0
esp32_marauder/MenuFunctions.h

@@ -3,9 +3,11 @@
 
 #include "WiFiScan.h"
 #include "Display.h"
+#include "Web.h"
 
 extern Display display_obj;
 extern WiFiScan wifi_scan_obj;
+extern Web web_obj;
 
 // Keypad start position, key sizes and spacing
 #define KEY_X 120 // Centre of key
@@ -38,6 +40,7 @@ extern WiFiScan wifi_scan_obj;
 #define RICK_ROLL 13
 #define REBOOT 14
 #define GENERAL_APPS 15
+#define UPDATE 16
 
 struct Menu;
 

+ 0 - 0
esp32_marauder/esp32_marauder_v0_3_0_20200128.bin → esp32_marauder/PreviousVersions/esp32_marauder_v0_3_0_20200128.bin


BIN
esp32_marauder/PreviousVersions/esp32_marauder_v0_3_2_20200130.bin


+ 92 - 0
esp32_marauder/Web.cpp

@@ -0,0 +1,92 @@
+#include "Web.h"
+
+WebServer server(80);
+
+Web::Web()
+{
+  
+}
+
+void Web::main()
+{
+  //Serial.println("Running the shits");
+  // Notify if client has connected to the update server
+  int current_sta = WiFi.softAPgetStationNum();
+  
+  if (current_sta < this->num_sta)
+  {
+    this->num_sta = current_sta;
+    Serial.print("Update server: Client disconnected -> ");
+    Serial.println(this->num_sta);
+  }
+  else if (current_sta > this->num_sta)
+  {
+    this->num_sta = current_sta;
+    Serial.print("Update server: Client connected -> ");
+    Serial.println(this->num_sta);
+  }
+  
+  server.handleClient();
+  delay(1);
+}
+
+void Web::setupOTAupdate()
+{
+  Serial.println("Configuring update server...");
+  
+  // Start WiFi AP
+  WiFi.softAP(ssid, password);
+  Serial.println("");
+  
+  Serial.print("IP address: ");
+  Serial.println(WiFi.softAPIP());
+
+  /*use mdns for host name resolution*/
+  /*
+  if (!MDNS.begin(host)) { //http://esp32.local
+    Serial.println("Error setting up MDNS responder!");
+    while (1) {
+      delay(1000);
+    }
+  }
+  Serial.println("mDNS responder started");
+  */
+  
+  /*return index page which is stored in serverIndex */
+  server.on("/", HTTP_GET, [this]() {
+    server.sendHeader("Connection", "close");
+    server.send(200, "text/html", loginIndex);
+  });
+  server.on("/serverIndex", HTTP_GET, [this]() {
+    server.sendHeader("Connection", "close");
+    server.send(200, "text/html", serverIndex);
+  });
+  /*handling uploading firmware file */
+  server.on("/update", HTTP_POST, [this]() {
+    server.sendHeader("Connection", "close");
+    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
+    ESP.restart();
+  }, [this]() {
+    HTTPUpload& upload = server.upload();
+    if (upload.status == UPLOAD_FILE_START) {
+      Serial.printf("Update: %s\n", upload.filename.c_str());
+      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
+        Update.printError(Serial);
+      }
+    } else if (upload.status == UPLOAD_FILE_WRITE) {
+      /* flashing firmware to ESP*/
+      if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
+        Update.printError(Serial);
+      }
+    } else if (upload.status == UPLOAD_FILE_END) {
+      if (Update.end(true)) { //true to set the size to the current progress
+        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
+      } else {
+        Update.printError(Serial);
+      }
+    }
+  });
+  server.begin();
+
+  Serial.println("Completed update server setup");
+}

+ 115 - 0
esp32_marauder/Web.h

@@ -0,0 +1,115 @@
+#ifndef Web_h
+#define Web_h
+
+/*
+Code taken from espressif ESP32 OTA Update example
+*/
+
+#include <WiFi.h>
+#include <WiFiClient.h>
+#include <WebServer.h>
+#include <ESPmDNS.h>
+#include <Update.h>
+
+class Web
+{
+  private:
+    
+    const char* host = "esp32marauder";
+    const char* ssid = "MarauderOTA";
+    const char* password = "justcallmekoko";
+
+    bool serving = false;
+    int num_sta = 0;
+
+    const char* loginIndex = 
+     "<form name='loginForm'>"
+        "<table width='20%' bgcolor='A09F9F' align='center'>"
+            "<tr>"
+                "<td colspan=2>"
+                    "<center><font size=4><b>ESP32 Login Page</b></font></center>"
+                    "<br>"
+                "</td>"
+                "<br>"
+                "<br>"
+            "</tr>"
+            "<td>Username:</td>"
+            "<td><input type='text' size=25 name='userid'><br></td>"
+            "</tr>"
+            "<br>"
+            "<br>"
+            "<tr>"
+                "<td>Password:</td>"
+                "<td><input type='Password' size=25 name='pwd'><br></td>"
+                "<br>"
+                "<br>"
+            "</tr>"
+            "<tr>"
+                "<td><input type='submit' onclick='check(this.form)' value='Login'></td>"
+            "</tr>"
+        "</table>"
+    "</form>"
+    "<script>"
+        "function check(form)"
+        "{"
+        "if(form.userid.value=='admin' && form.pwd.value=='admin')"
+        "{"
+        "window.open('/serverIndex')"
+        "}"
+        "else"
+        "{"
+        " alert('Error Password or Username')/*displays error message*/"
+        "}"
+        "}"
+    "</script>";
+     
+    /*
+     * Server Index Page
+     */
+     
+    const char* serverIndex = 
+    "<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
+    "<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
+       "<input type='file' name='update'>"
+            "<input type='submit' value='Update'>"
+        "</form>"
+     "<div id='prg'>progress: 0%</div>"
+     "<script>"
+      "$('form').submit(function(e){"
+      "e.preventDefault();"
+      "var form = $('#upload_form')[0];"
+      "var data = new FormData(form);"
+      " $.ajax({"
+      "url: '/update',"
+      "type: 'POST',"
+      "data: data,"
+      "contentType: false,"
+      "processData:false,"
+      "xhr: function() {"
+      "var xhr = new window.XMLHttpRequest();"
+      "xhr.upload.addEventListener('progress', function(evt) {"
+      "if (evt.lengthComputable) {"
+      "var per = evt.loaded / evt.total;"
+      "$('#prg').html('progress: ' + Math.round(per*100) + '%');"
+      "}"
+      "}, false);"
+      "return xhr;"
+      "},"
+      "success:function(d, s) {"
+      "console.log('success!')" 
+     "},"
+     "error: function (a, b, c) {"
+     "}"
+     "});"
+     "});"
+     "</script>";
+
+  public:
+  
+    Web();
+
+    void main();
+    void setupOTAupdate();
+};
+
+#endif

+ 1 - 0
esp32_marauder/WiFiScan.h

@@ -14,6 +14,7 @@
 
 #define bad_list_length 3
 
+#define OTA_UPDATE 100
 #define WIFI_SCAN_OFF 0
 #define WIFI_SCAN_PROBE 1
 #define WIFI_SCAN_AP 2

+ 17 - 4
esp32_marauder/esp32_marauder.ino

@@ -18,11 +18,13 @@ https://www.online-utility.org/image/convert/to/XBM
 #include "Display.h"
 #include "WiFiScan.h"
 #include "MenuFunctions.h"
+#include "Web.h"
 //#include "icons.h"
 
 Display display_obj;
 WiFiScan wifi_scan_obj;
 MenuFunctions menu_function_obj;
+Web web_obj;
 
 uint32_t currentTime  = 0;
 
@@ -34,8 +36,10 @@ void setup()
   digitalWrite(TFT_BL, LOW);
   
   Serial.begin(115200);
-  Serial.println("\n\n--------------------------------");
-  Serial.println("         ESP32 Marauder      ");
+  Serial.println("\n\n--------------------------------\n");
+  Serial.println("         ESP32 Marauder      \n");
+  Serial.println("            " + display_obj.version_number + "\n");
+  Serial.println("       By: justcallmekoko\n");
   Serial.println("--------------------------------\n\n");
 
   // Run display setup
@@ -48,12 +52,14 @@ void setup()
 
 void loop()
 {
+  
   // get the current time
   //if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM))
   currentTime = millis();
 
   // Update all of our objects
-  if (!display_obj.draw_tft)
+  if ((!display_obj.draw_tft) &&
+      (wifi_scan_obj.currentScanMode != OTA_UPDATE))
   {
     display_obj.main(); 
     wifi_scan_obj.main(currentTime);
@@ -62,10 +68,17 @@ void loop()
       menu_function_obj.main();
     delay(1);
   }
-  else
+  else if ((display_obj.draw_tft) &&
+           (wifi_scan_obj.currentScanMode != OTA_UPDATE))
   {
     display_obj.drawStylus();
   }
+  else
+  {
+    web_obj.main();
+  }
+
+  //Serial.println(wifi_scan_obj.currentScanMode);
 
   //Serial.print("Run Time: ");
   //Serial.print(millis() - currentTime);

BIN
esp32_marauder/esp32_marauder_v0_4_0_20200130.bin


BIN
pictures/icons/update_22.bmp


+ 9 - 0
pictures/xbm/update_22.XBM

@@ -0,0 +1,9 @@
+#define 1580428515860_width 22
+#define 1580428515860_height 22
+static char 1580428515860_bits[] = {
+  0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xE0, 0x3F, 0x3F, 0x80, 0x3F, 
+  0x1F, 0x00, 0x3F, 0x0F, 0x00, 0x3E, 0x07, 0x00, 0x3C, 0x07, 0x08, 0x3C, 
+  0x03, 0x18, 0x38, 0x03, 0x38, 0x38, 0xC3, 0x7F, 0x38, 0xC3, 0x7F, 0x38, 
+  0x03, 0x38, 0x38, 0x03, 0x18, 0x38, 0x07, 0x08, 0x3C, 0x07, 0x00, 0x3C, 
+  0x0F, 0x00, 0x3E, 0x1F, 0x00, 0x3F, 0x3F, 0x80, 0x3F, 0xFF, 0xE0, 0x3F, 
+  0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, };