Skip to content

Commit

Permalink
Merge branch 'master' into 6-dns-and-subnetmask
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedjof committed Oct 14, 2023
2 parents 554cbe2 + 2d905fd commit 4908925
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ esptool.py --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard
```
Change the `--port` parameter to match your system configuration and the path to the binary files.

#### spiffs.bin
#### littlefs.bin (ESP32 and ESP8266)
```bash
esptool.py --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x290000 spiffs.bin
esptool.py --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x290000 littlefs.bin
```
Change the `--port` parameter to match your system configuration and the path to the binary files.

Expand Down
30 changes: 7 additions & 23 deletions lib/ConfigManager/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,38 @@
ConfigManager::ConfigManager(const char* filename) {
this->filename = filename;

#ifdef ESP32DEV
// start SPIFFS
if (!SPIFFS.begin(true)) {
Serial.println("Could not initialize SPIFFS");
// start LittleFS
if (!LittleFS.begin()) {
Serial.println("Could not initialize LittleFS");
return;
}
#endif

// load config
this->load_config();
}

ConfigManager::ConfigManager() {
this->filename = DEFAULT_CONFIG_FILE;
// start SPIFFS
#ifdef ESP32DEV
if (!SPIFFS.begin(true)) {
Serial.println("Could not initialize SPIFFS");
return;
}
#else

// start LittleFS
if (!LittleFS.begin()) {
Serial.println("Could not initialize LittleFS");
return;
}
#endif

// load config
this->load_config();
}

ConfigManager::~ConfigManager() { }

// load config from SPIFFS
// load config from LittleFS
void ConfigManager::load_config() {
Serial.println("Loading config");
Serial.print("Filename: ");
Serial.println(this->filename);
// Open file for reading
#ifdef ESP32DEV
File file = SPIFFS.open(this->filename, FILE_READ);
#else
File file = LittleFS.open(this->filename, "r");
#endif

if (!file) {
Serial.println("Failed to open config file");
Expand Down Expand Up @@ -110,14 +98,10 @@ void ConfigManager::load_config() {
file.close();
}

// save config to SPIFFS
// save config to LittleFS
void ConfigManager::save_config() {
// open file for writing
#ifdef ESP32DEV
File file = SPIFFS.open(this->filename, FILE_WRITE);
#else
File file = LittleFS.open(this->filename, "w");
#endif

if (!file) {
Serial.println("Failed to create file");
Expand Down
4 changes: 0 additions & 4 deletions lib/ConfigManager/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@

#include <Arduino.h>

#ifdef ESP32DEV
#include <SPIFFS.h>
#else
#include <LittleFS.h>
#endif

#include <ArduinoJson.h>

Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ monitor_speed = 9600
monitor_port = /dev/ttyUSB0
upload_speed = 921600
build_flags = -D ESP32DEV
board_build.filesystem = littlefs
lib_deps =
Wifi
ESPmDNS
Expand Down
16 changes: 2 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <AsyncJson.h>
#include <ArduinoJson.h>
#include <LittleFS.h>

#ifdef ESP32DEV
#include <WiFi.h>
Expand All @@ -12,7 +13,6 @@
#else
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <LittleFS.h>
#endif

#include <SPI.h>
Expand Down Expand Up @@ -127,7 +127,7 @@ void loop() {
}

// auto sleep depending on AUTO_SLEEP
if (configManager.get_system_config().auto_sleep && (millis() - auto_sleep_millis > 1000 * configManager.get_system_config().auto_sleep_after)) {
if (configManager.get_system_config().auto_sleep && (millis() - auto_sleep_millis > (long unsigned int)(1000 * configManager.get_system_config().auto_sleep_after))) {
Serial.println("Going to sleep because of auto sleep");
#ifdef ESP32DEV
esp_deep_sleep_start();
Expand Down Expand Up @@ -208,27 +208,15 @@ void setup_aws() {
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
new_request();

#ifdef ESP32DEV
request->send(SPIFFS, INDEX_FILE, "text/html");
#else
request->send(LittleFS, INDEX_FILE, "text/html");
#endif
});

server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request) {
#ifdef ESP32DEV
request->send(SPIFFS, CSS_FILE, "text/css");
#else
request->send(LittleFS, CSS_FILE, "text/css");
#endif
});

server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request) {
#ifdef ESP32DEV
request->send(SPIFFS, JS_FILE, "text/javascript");
#else
request->send(LittleFS, JS_FILE, "text/javascript");
#endif
});

server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request) {
Expand Down

0 comments on commit 4908925

Please sign in to comment.