Basic functionality achived

This commit is contained in:
Tomislav Kopić 2024-11-05 12:54:36 +01:00
parent b8c903534f
commit 56ed7e4b19
No known key found for this signature in database
GPG Key ID: 77B232765688AEA7
3 changed files with 35 additions and 11 deletions

View File

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

View File

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

View File

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