mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-12 15:50:36 -08:00
Add settings function
This commit is contained in:
@@ -51,10 +51,10 @@ void Display::RunSetup()
|
||||
|
||||
// Initialize file system
|
||||
// This should probably have its own class
|
||||
if (!SPIFFS.begin()) {
|
||||
Serial.println(F("SPIFFS initialisation failed!"));
|
||||
//if (!SPIFFS.begin()) {
|
||||
// Serial.println(F("SPIFFS initialisation failed!"));
|
||||
//while (1) yield(); // Stay here twiddling thumbs waiting
|
||||
}
|
||||
//}
|
||||
|
||||
//this->initLVGL();
|
||||
|
||||
@@ -444,7 +444,9 @@ void Display::scrollAddress(uint16_t vsp) {
|
||||
void Display::drawJpeg(const char *filename, int xpos, int ypos) {
|
||||
|
||||
// Open the named file (the Jpeg decoder library will close it after rendering image)
|
||||
fs::File jpegFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
|
||||
//fs::File jpegFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
|
||||
|
||||
//jpegFile.close();
|
||||
|
||||
//ESP32 always seems to return 1 for jpegFile so this null trap does not work
|
||||
//if ( !jpegFile ) {
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
#define LV_ADD_SSID 14
|
||||
#define WIFI_ATTACK_BEACON_LIST 15
|
||||
|
||||
#define TFT_SHIELD
|
||||
//#define TFT_DIY
|
||||
//#define TFT_SHIELD
|
||||
#define TFT_DIY
|
||||
//#define KIT
|
||||
|
||||
#define SCREEN_WIDTH 240
|
||||
|
||||
@@ -155,6 +155,49 @@ void MenuFunctions::writeBadUSB(){
|
||||
lv_keyboard_set_cursor_manage(kb, true);
|
||||
}
|
||||
|
||||
void MenuFunctions::displaySettingsGFX(){
|
||||
extern Settings settings_obj;
|
||||
|
||||
DynamicJsonDocument json(1024); // ArduinoJson v6
|
||||
|
||||
if (deserializeJson(json, settings_obj.getSettingsString())) {
|
||||
Serial.println("\nCould not parse json");
|
||||
}
|
||||
|
||||
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(list1, 160, 200);
|
||||
lv_obj_set_width(list1, LV_HOR_RES);
|
||||
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_obj_t * list_btn;
|
||||
|
||||
lv_obj_t * label;
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Exit");
|
||||
lv_obj_set_event_cb(list_btn, ap_list_cb);
|
||||
|
||||
for (int i = 0; i < json["Settings"].size(); i++) {
|
||||
char buf[json["Settings"][i]["name"].as<String>().length() + 1] = {};
|
||||
json["Settings"][i]["name"].as<String>().toCharArray(buf, json["Settings"][i]["name"].as<String>().length() + 1);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, buf);
|
||||
lv_btn_set_checkable(list_btn, true);
|
||||
lv_obj_set_event_cb(list_btn, ap_list_cb);
|
||||
|
||||
//if (access_points->get(i).selected)
|
||||
// lv_btn_toggle(list_btn);
|
||||
|
||||
//lv_obj_t * btn1 = lv_btn_create(list_btn, NULL);
|
||||
//lv_obj_set_event_cb(btn1, ap_list_cb);
|
||||
//lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
//lv_btn_set_checkable(btn1, true);
|
||||
|
||||
//label = lv_label_create(btn1, NULL);
|
||||
//lv_label_set_text(label, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// GFX Function to build a list showing all APs scanned
|
||||
void MenuFunctions::addAPGFX(){
|
||||
extern LinkedList<AccessPoint>* access_points;
|
||||
|
||||
@@ -191,6 +234,57 @@ void MenuFunctions::addAPGFX(){
|
||||
}
|
||||
}
|
||||
|
||||
void settings_list_cb(lv_obj_t * btn, lv_event_t event) {
|
||||
extern Settings settings_obj;
|
||||
extern MenuFunctions menu_function_obj;
|
||||
|
||||
String btn_text = lv_list_get_btn_text(btn);
|
||||
String display_string = "";
|
||||
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
if (btn_text != "Exit") {
|
||||
//lv_list_focus_btn(lv_obj_get_parent(lv_obj_get_parent(btn)), btn);
|
||||
}
|
||||
else {
|
||||
Serial.println("Exiting...");
|
||||
lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
|
||||
|
||||
printf("LV_EVENT_CANCEL\n");
|
||||
menu_function_obj.deinitLVGL();
|
||||
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
|
||||
display_obj.exit_draw = true; // set everything back to normal
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
||||
if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
|
||||
//Serial.print("Toggle on: ");
|
||||
//Serial.println(btn_text);
|
||||
for (int i = 0; i < access_points->size(); i++) {
|
||||
if (access_points->get(i).essid == btn_text) {
|
||||
Serial.println("Adding AP: " + (String)access_points->get(i).essid);
|
||||
AccessPoint ap = access_points->get(i);
|
||||
ap.selected = true;
|
||||
access_points->set(i, ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//Serial.print("Toggle off: ");
|
||||
//Serial.println(btn_text);
|
||||
for (int i = 0; i < access_points->size(); i++) {
|
||||
if (access_points->get(i).essid == btn_text) {
|
||||
Serial.println("Removing AP: " + (String)access_points->get(i).essid);
|
||||
AccessPoint ap = access_points->get(i);
|
||||
ap.selected = false;
|
||||
access_points->set(i, ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void ap_list_cb(lv_obj_t * btn, lv_event_t event) {
|
||||
extern LinkedList<AccessPoint>* access_points;
|
||||
extern MenuFunctions menu_function_obj;
|
||||
@@ -1387,6 +1481,12 @@ void MenuFunctions::RunSetup()
|
||||
changeMenu(&infoMenu);
|
||||
wifi_scan_obj.RunInfo();
|
||||
});
|
||||
addNodes(&deviceMenu, "Settings", TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
|
||||
display_obj.clearScreen();
|
||||
wifi_scan_obj.currentScanMode = LV_ADD_SSID;
|
||||
wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
|
||||
displaySettingsGFX();
|
||||
});
|
||||
|
||||
// Select update
|
||||
whichUpdateMenu.parentMenu = &deviceMenu;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Web.h"
|
||||
#include "esp_interface.h"
|
||||
#include "a32u4_interface.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
extern Display display_obj;
|
||||
@@ -19,6 +20,7 @@ extern SDInterface sd_obj;
|
||||
extern BatteryInterface battery_obj;
|
||||
extern EspInterface esp_obj;
|
||||
extern A32u4Interface a32u4_obj;
|
||||
extern Settings settings_obj;
|
||||
|
||||
// Keypad start position, key sizes and spacing
|
||||
#define KEY_X 120 // Centre of key
|
||||
@@ -192,6 +194,7 @@ class MenuFunctions
|
||||
void joinWiFiGFX();
|
||||
void addSSIDGFX();
|
||||
void addAPGFX();
|
||||
void displaySettingsGFX();
|
||||
void writeBadUSB();
|
||||
|
||||
void buildButtons(Menu* menu);
|
||||
|
||||
@@ -1326,16 +1326,19 @@ void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
|
||||
//Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
|
||||
|
||||
// Load json
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.parseObject(essid);
|
||||
if (!json.success()) {
|
||||
//DynamicJsonBuffer jsonBuffer; // ArduinoJson v5
|
||||
DynamicJsonDocument json(1024); // ArduinoJson v6
|
||||
//JsonObject& json = jsonBuffer.parseObject(essid); // ArduinoJson v5
|
||||
// ArduinoJson v6
|
||||
if (deserializeJson(json, essid)) {
|
||||
Serial.println("\nCould not parse Pwnagotchi json");
|
||||
display_string.concat(essid);
|
||||
}
|
||||
else {
|
||||
Serial.println("\nSuccessfully parsed json");
|
||||
String json_output;
|
||||
json.printTo(json_output);
|
||||
//json.printTo(json_output); // ArduinoJson v5
|
||||
serializeJson(json, json_output); // ArduinoJson v6
|
||||
Serial.println(json_output);
|
||||
display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ https://www.online-utility.org/image/convert/to/XBM
|
||||
#include "LedInterface.h"
|
||||
#include "esp_interface.h"
|
||||
#include "a32u4_interface.h"
|
||||
#include "settings.h"
|
||||
//#include "icons.h"
|
||||
|
||||
/*
|
||||
@@ -52,6 +53,7 @@ TemperatureInterface temp_obj;
|
||||
LedInterface led_obj;
|
||||
EspInterface esp_obj;
|
||||
A32u4Interface a32u4_obj;
|
||||
Settings settings_obj;
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
@@ -112,6 +114,8 @@ void setup()
|
||||
|
||||
//Serial.println("Internal Temp: " + (String)((temprature_sens_read() - 32) / 1.8));
|
||||
|
||||
settings_obj.begin();
|
||||
|
||||
wifi_scan_obj.RunSetup();
|
||||
|
||||
Serial.println(wifi_scan_obj.freeRAM());
|
||||
@@ -216,6 +220,7 @@ void loop()
|
||||
sd_obj.main();
|
||||
battery_obj.main(currentTime);
|
||||
temp_obj.main(currentTime);
|
||||
settings_obj.main(currentTime);
|
||||
//esp_obj.main(currentTime);
|
||||
//a32u4_obj.main(currentTime);
|
||||
//led_obj.main(currentTime);
|
||||
|
||||
108
esp32_marauder/settings.cpp
Normal file
108
esp32_marauder/settings.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "settings.h"
|
||||
|
||||
String Settings::getSettingsString() {
|
||||
return this->json_settings_string;
|
||||
}
|
||||
|
||||
bool Settings::begin() {
|
||||
if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){
|
||||
Serial.println("Settings SPIFFS Mount Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
File settingsFile;
|
||||
|
||||
//SPIFFS.remove("/settings.json"); // NEED TO REMOVE THIS LINE
|
||||
|
||||
if (SPIFFS.exists("/settings.json")) {
|
||||
settingsFile = SPIFFS.open("/settings.json", FILE_READ);
|
||||
|
||||
if (!settingsFile) {
|
||||
settingsFile.close();
|
||||
Serial.println(F("Could not find settings file"));
|
||||
if (this->createDefaultSettings(SPIFFS))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println("Settings file does not exist");
|
||||
if (this->createDefaultSettings(SPIFFS))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
String json_string;
|
||||
DynamicJsonDocument jsonBuffer(1024);
|
||||
DeserializationError error = deserializeJson(jsonBuffer, settingsFile);
|
||||
serializeJson(jsonBuffer, json_string);
|
||||
Serial.println("Settings: " + (String)json_string + "\n");
|
||||
this->printJsonSettings(json_string);
|
||||
|
||||
this->json_settings_string = json_string;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Settings::printJsonSettings(String json_string) {
|
||||
DynamicJsonDocument json(1024); // ArduinoJson v6
|
||||
|
||||
if (deserializeJson(json, json_string)) {
|
||||
Serial.println("\nCould not parse json");
|
||||
}
|
||||
|
||||
Serial.println("Settings\n----------------------------------------------");
|
||||
for (int i = 0; i < json["Settings"].size(); i++) {
|
||||
Serial.println("Name: " + json["Settings"][i]["name"].as<String>());
|
||||
Serial.println("Type: " + json["Settings"][i]["type"].as<String>());
|
||||
Serial.println("Value: " + json["Settings"][i]["value"].as<String>());
|
||||
Serial.println("----------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
bool Settings::createDefaultSettings(fs::FS &fs) {
|
||||
Serial.println(F("Creating default settings file: settings.json"));
|
||||
|
||||
File settingsFile = fs.open("/settings.json", FILE_WRITE);
|
||||
|
||||
if (!settingsFile) {
|
||||
Serial.println(F("Failed to create settings file"));
|
||||
return false;
|
||||
}
|
||||
|
||||
DynamicJsonDocument jsonBuffer(1024);
|
||||
String settings_string;
|
||||
|
||||
jsonBuffer["Settings"][0]["name"] = "channel";
|
||||
jsonBuffer["Settings"][0]["type"] = "int";
|
||||
jsonBuffer["Settings"][0]["value"] = 11;
|
||||
|
||||
jsonBuffer["Settings"][1]["name"] = "force pmkid";
|
||||
jsonBuffer["Settings"][1]["type"] = "bool";
|
||||
jsonBuffer["Settings"][1]["value"] = true;
|
||||
|
||||
jsonBuffer["Settings"][2]["name"] = "save pcap";
|
||||
jsonBuffer["Settings"][2]["type"] = "bool";
|
||||
jsonBuffer["Settings"][2]["value"] = true;
|
||||
|
||||
//jsonBuffer.printTo(settingsFile);
|
||||
if (serializeJson(jsonBuffer, settingsFile) == 0) {
|
||||
Serial.println(F("Failed to write to file"));
|
||||
}
|
||||
if (serializeJson(jsonBuffer, settings_string) == 0) {
|
||||
Serial.println(F("Failed to write to string"));
|
||||
}
|
||||
|
||||
// Close the file
|
||||
settingsFile.close();
|
||||
|
||||
this->printJsonSettings(settings_string);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Settings::main(uint32_t currentTime) {
|
||||
|
||||
}
|
||||
29
esp32_marauder/settings.h
Normal file
29
esp32_marauder/settings.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef Settings_h
|
||||
#define Settings_h
|
||||
|
||||
#include "SPIFFS.h"
|
||||
#include <FS.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#define FORMAT_SPIFFS_IF_FAILED true
|
||||
|
||||
#include "Display.h"
|
||||
|
||||
extern Display display_obj;
|
||||
|
||||
class Settings {
|
||||
|
||||
private:
|
||||
String json_settings_string;
|
||||
|
||||
void printJsonSettings(String json_string);
|
||||
bool createDefaultSettings(fs::FS &fs);
|
||||
|
||||
public:
|
||||
bool begin();
|
||||
|
||||
String getSettingsString();
|
||||
void main(uint32_t currentTime);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user