Clean up after BLE and OTA

This commit is contained in:
Just Call Me Koko
2020-03-07 23:24:25 -05:00
parent 40a4b5f22b
commit 7a8cf2aa50
6 changed files with 62 additions and 17 deletions

View File

@@ -44,17 +44,17 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len){
// buffer is full -> drop packet
if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){
Serial.print(";");
//Serial.print(";");
return;
}
if(useA && bufSizeA + len + 16 >= BUF_SIZE && bufSizeB == 0){
useA = false;
Serial.println("\nswitched to buffer B");
//Serial.println("\nswitched to buffer B");
}
else if(!useA && bufSizeB + len + 16 >= BUF_SIZE && bufSizeA == 0){
useA = true;
Serial.println("\nswitched to buffer A");
//Serial.println("\nswitched to buffer A");
}
uint32_t microSeconds = micros(); // e.g. 45200400 => 45s 200ms 400us
@@ -116,7 +116,7 @@ void Buffer::save(fs::FS* fs){
return;
}
Serial.println("saving file");
//Serial.println("saving file");
uint32_t startTime = millis();
uint32_t finishTime;
@@ -147,7 +147,7 @@ void Buffer::save(fs::FS* fs){
finishTime = millis() - startTime;
Serial.printf("\n%u bytes written for %u ms\n", len, finishTime);
//Serial.printf("\n%u bytes written for %u ms\n", len, finishTime);
saving = false;
@@ -195,7 +195,7 @@ void Buffer::forceSave(fs::FS* fs){
file.close();
Serial.printf("saved %u bytes\n",len);
//Serial.printf("saved %u bytes\n",len);
saving = false;
writing = true;

View File

@@ -31,6 +31,7 @@ void MenuFunctions::main()
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
display_obj.displayBuffer();
//Serial.println(wifi_scan_obj.freeRAM());
// Pressed will be set true is there is a valid touch on the screen
@@ -246,7 +247,7 @@ void MenuFunctions::RunSetup()
addNodes(&deviceMenu, "Device Info", TFT_WHITE, NULL, DEVICE_INFO, [this](){wifi_scan_obj.currentScanMode = SHOW_INFO; changeMenu(&infoMenu); wifi_scan_obj.RunInfo();});
updateMenu.parentMenu = &deviceMenu;
addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu); WiFi.softAPdisconnect(true);});
addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu); WiFi.softAPdisconnect(true); web_obj.shutdownServer();});
infoMenu.parentMenu = &deviceMenu;
addNodes(&infoMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(infoMenu.parentMenu);});

View File

@@ -11,6 +11,8 @@ 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)
@@ -26,6 +28,7 @@ void Web::main()
Serial.println(this->num_sta);
}
server.handleClient();
delay(1);
}
@@ -46,15 +49,30 @@ void Web::setupOTAupdate()
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_WHITE);
Serial.println(wifi_scan_obj.freeRAM());
display_obj.tft.print("Configuring update server...\n\n");
Serial.println("Configuring update server...");
display_obj.tft.setTextColor(TFT_YELLOW);
// Start WiFi AP
Serial.println("Initializing WiFi...");
//wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init(&wifi_scan_obj.cfg);
//esp_wifi_set_storage(WIFI_STORAGE_RAM);
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK)
Serial.println("Could not set WiFi Storage!");
esp_wifi_set_mode(WIFI_MODE_NULL);
esp_wifi_start();
Serial.println(wifi_scan_obj.freeRAM());
Serial.println("Starting softAP...");
WiFi.softAP(ssid, password);
Serial.println("");
Serial.println(wifi_scan_obj.freeRAM());
Serial.println("Displaying settings to TFT...");
display_obj.tft.print("SSID: ");
display_obj.tft.println(ssid);
display_obj.tft.print("IP address: ");
@@ -75,6 +93,8 @@ void Web::setupOTAupdate()
*/
// return javascript jquery
Serial.println("Setting server behavior...");
Serial.println(wifi_scan_obj.freeRAM());
server.on("/jquery.min.js", HTTP_GET, onJavaScript);
/*return index page which is stored in serverIndex */
server.on("/", HTTP_GET, [this]() {
@@ -138,9 +158,25 @@ void Web::setupOTAupdate()
}
}
});
Serial.println("Finished setting server behavior");
Serial.println(wifi_scan_obj.freeRAM());
Serial.println("Starting server...");
server.begin();
display_obj.tft.setTextColor(TFT_GREEN);
display_obj.tft.println("\nCompleted update server setup");
Serial.println("Completed update server setup");
Serial.println(wifi_scan_obj.freeRAM());
}
void Web::shutdownServer() {
Serial.println("Closing Update Server...");
server.stop();
WiFi.mode(WIFI_OFF);
esp_wifi_set_mode(WIFI_MODE_NULL);
esp_wifi_stop();
esp_wifi_deinit();
Serial.println(wifi_scan_obj.freeRAM());
}

View File

@@ -13,8 +13,10 @@ Code taken from espressif ESP32 OTA Update example
#include "Assets.h"
#include "Display.h"
#include "WiFiScan.h"
extern Display display_obj;
extern WiFiScan wifi_scan_obj;
class Web
{
@@ -25,6 +27,7 @@ class Web
PROGMEM const char* password = "justcallmekoko";
bool serving = false;
int num_sta = 0;
PROGMEM const char* loginIndex =
@@ -121,8 +124,9 @@ class Web
Web();
void main();
static void onJavaScript();
PROGMEM static void onJavaScript();
void setupOTAupdate();
void shutdownServer();
};
#endif

View File

@@ -8,7 +8,11 @@ int num_deauth = 0;
int num_probe = 0;
class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
//advertisedDevice.getScan()->stop();
String display_string = "";
if (display_obj.display_buffer->size() >= 0)
{
@@ -241,14 +245,14 @@ String WiFiScan::freeRAM()
void WiFiScan::RunInfo()
{
String sta_mac = this->getStaMAC();
String ap_mac = this->getApMAC();
//String sta_mac = this->getStaMAC();
//String ap_mac = this->getApMAC();
String free_ram = this->freeRAM();
Serial.print("STA MAC: ");
Serial.println(sta_mac);
Serial.print("AP MAC: ");
Serial.println(ap_mac);
//Serial.print("STA MAC: ");
//Serial.println(sta_mac);
//Serial.print("AP MAC: ");
//Serial.println(ap_mac);
Serial.println(free_ram);
display_obj.tft.setTextWrap(false);
@@ -257,8 +261,8 @@ void WiFiScan::RunInfo()
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_CYAN);
display_obj.tft.println(" Station MAC: " + sta_mac);
display_obj.tft.println(" AP MAC: " + ap_mac);
//display_obj.tft.println(" Station MAC: " + sta_mac);
//display_obj.tft.println(" AP MAC: " + ap_mac);
display_obj.tft.println(" " + free_ram);
if (sd_obj.supported) {

View File

@@ -138,7 +138,7 @@ class WiFiScan
bool orient_display = false;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
String getStaMAC();
String getApMAC();