feature/netman #1

Merged
tomislav merged 12 commits from feature/netman into master 2024-11-05 19:43:41 +00:00
3 changed files with 35 additions and 11 deletions
Showing only changes of commit 56ed7e4b19 - Show all commits

View File

@ -3,6 +3,7 @@
"*.page-template": "vue",
"*.layout-template": "vue",
"*.vue": "vue",
"*.tcc": "cpp"
"*.tcc": "cpp",
"functional": "cpp"
}
}

View File

@ -11,7 +11,7 @@
#define FRAMERATE 8
// Buttons and buzzer
#define PIN_BTN_L 12 // D6
#define PIN_BTN_L 15 // D6
#define PIN_BTN_M 13 // D7
#define PIN_BTN_R 15 // D8
#define PIN_BTN_R 12 // D8
#define PIN_BUZZER 0 // D3

View File

@ -46,18 +46,24 @@ private:
void netman::init(String ssid, String pass, bool hidden) {
// Ensure password meets minimum length
if (pass != "" && pass.length() < 8) {
display.println("Password too short. Using default: '8characters'");
pass = "8characters";
display.clearDisplay();
display.setCursor(0, 0);
display.println("Password too short");
display.display();
pass = "8characters";
}
// Set default SSID if none provided
_ssid = ssid.isEmpty() ? "ESP" + String(ESP.getChipId()) : ssid;
_ssid = ssid.isEmpty() ? "SmartCube_" + String(ESP.getChipId()) : ssid;
_pass = pass;
_hidden = hidden;
// Initialize LittleFS with error handling
if (!LittleFS.begin()) {
display.println("Failed to initialize filesystem.");
display.clearDisplay();
display.setCursor(0, 0);
display.println("FS init failed");
display.display();
}
}
@ -73,7 +79,11 @@ netman::netman(String ssid, String pass, bool hidden, Adafruit_SSD1306& display)
// Attempt to start and connect or create AP
bool netman::start() {
if (_pass == "8characters") {
display.println("Using default password due to length requirement.");
display.clearDisplay();
display.setCursor(0, 0);
display.println("Using default pass:");
display.println("8characters");
display.display();
}
return tryConnect() || (createAP(), false);
}
@ -81,6 +91,10 @@ bool netman::start() {
// Attempt connection to each saved SSID in order
bool netman::tryConnect() {
readConfig();
display.clearDisplay();
display.setCursor(0, 0);
display.println("Connecting to wifi");
display.display();
for (auto const& item : _ssids) {
if (tryConnectToSsid(item.first.c_str(), item.second.c_str())) {
return true;
@ -113,7 +127,14 @@ void netman::createAP() {
WiFi.mode(WIFI_AP);
WiFi.softAP(_ssid.c_str(), _pass.c_str(), 1, _hidden);
display.println("AP created with IP: " + WiFi.softAPIP().toString());
display.clearDisplay();
display.setCursor(0, 0);
display.println("AccessPoint created");
display.println("SSID:");
display.println(_ssid.c_str());
display.println("IP:");
display.println(WiFi.softAPIP().toString());
display.display();
server.reset(new ESP8266WebServer(80));
DNSServer dnsServer;
@ -124,7 +145,6 @@ void netman::createAP() {
server->on("/remove", std::bind(&netman::handleRemove, this));
server->begin();
display.println("HTTP server started");
while (true) {
dnsServer.processNextRequest();
@ -163,7 +183,10 @@ void netman::readConfig() {
_ssids.clear();
File file = LittleFS.open(configFile, "r");
if (!file) {
display.println("No config file found.");
display.clearDisplay();
display.setCursor(0, 0);
display.println("Config not found");
display.display();
return;
}