Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EcoStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool EcoStation::initialise( void )
sensor_manager.set_solar_panel( solar_panel );
sensor_manager.set_debug_mode( debug_mode );

if ( ( esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_UNDEFINED ) && solar_panel )
if ( ( station_data.reset_reason != ESP_RST_DEEPSLEEP ) && solar_panel )
boot_timestamp = 0;

ota_setup.board = "ECO_";
Expand Down
2 changes: 1 addition & 1 deletion src/EcoStation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "common.h"
#include "EcoStation.h"

const etl::string<12> REV = "1.1.1";
const etl::string<12> REV = "1.1.2";
const unsigned long long US_HIBERNATE = 1 * 24 * 60 * 60 * 1000000ULL; // 1 day

EcoStation station;
Expand Down
66 changes: 43 additions & 23 deletions src/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ bool AWSConfig::load( etl::string<64> &firmware_sha256, bool _debug_mode )
return read_config( firmware_sha256 );
}

void AWSConfig::migrate_config_and_ui( void )
{
if ( LittleFS.exists( "/config/aws.conf" ))

return;

else {

LittleFS.rename( "/aws.conf" , "/config/aws.conf" );
LittleFS.rename( "/aws.conf.dfl" , "/config/aws.conf.dfl" );
LittleFS.rename( "/root_ca.txt" , "/config/root_ca.txt" );

LittleFS.rename( "/index.html" , "/ui/index.html" );
LittleFS.rename( "/aws.js" , "/ui/aws.js" );

}
}

char AWSConfig::nibble_to_hex_char(uint8_t nibble) const
{
return (nibble < 10) ? ('0' + nibble) : ('A' + nibble - 10);
Expand All @@ -224,11 +242,13 @@ bool AWSConfig::read_config( etl::string<64> &firmware_sha256 )
{
read_eeprom_and_nvs_config( firmware_sha256 );

migrate_config_and_ui();

read_root_ca();

if ( !read_file( "/aws.conf" ) ) {
if ( !read_file( "/config/aws.conf" ) ) {

if ( !read_file( "/aws.conf.dfl" )) {
if ( !read_file( "/config/aws.conf.dfl" )) {

Serial.printf( "\n[CONFIGMNGR] [ERROR] Could not read config file.\n" );
return false;
Expand Down Expand Up @@ -404,8 +424,8 @@ void AWSConfig::read_root_ca( void )
File file;
int s;

if ( LittleFS.exists( "/root_ca.txt" ) )
file = LittleFS.open( "/root_ca.txt", FILE_READ );
if ( LittleFS.exists( "/config/root_ca.txt" ) )
file = LittleFS.open( "/config/root_ca.txt", FILE_READ );

if ( !file ) {

Expand Down Expand Up @@ -493,8 +513,8 @@ bool AWSConfig::rollback()
return false;
}

LittleFS.remove( "/aws.conf" );
LittleFS.rename( "/aws.conf.bak", "/aws.conf" );
LittleFS.remove( "/config/aws.conf" );
LittleFS.rename( "/config/aws.conf.bak", "/config/aws.conf" );
Serial.printf( "[CONFIGMNGR] [INFO ] Rollback successful.\n" );
_can_rollback = 0;
return true;
Expand Down Expand Up @@ -532,12 +552,12 @@ bool AWSConfig::save_runtime_configuration( JsonVariant &_json_config )

update_fs_free_space();

LittleFS.remove( "/aws.conf.bak.try" );
LittleFS.rename( "/aws.conf", "/aws.conf.bak.try" );
LittleFS.remove( "/aws.conf.try" );
LittleFS.remove( "/config/aws.conf.bak.try" );
LittleFS.rename( "/config/aws.conf", "/config/aws.conf.bak.try" );
LittleFS.remove( "/config(aws.conf.try" );

// flawfinder: ignore
File file = LittleFS.open( "/aws.conf.try", FILE_WRITE );
File file = LittleFS.open( "/config/aws.conf.try", FILE_WRITE );
if ( !file ) {

Serial.printf( "[CONFIGMNGR] [ERROR] Cannot write configuration file, rolling back.\n" );
Expand All @@ -548,41 +568,41 @@ bool AWSConfig::save_runtime_configuration( JsonVariant &_json_config )
file.close();
if ( !s ) {

LittleFS.remove( "/aws.conf" );
LittleFS.remove( "/aws.conf.try" );
LittleFS.rename( "/aws.conf.bak.try", "/aws.conf" );
LittleFS.remove( "/config/aws.conf" );
LittleFS.remove( "/config/aws.conf.try" );
LittleFS.rename( "/config/aws.conf.bak.try", "/config/aws.conf" );
Serial.printf( "[CONFIGMNGR] [ERROR] Empty configuration file, rolling back.\n" );
return false;

}
if ( s > MAX_CONFIG_FILE_SIZE ) {

LittleFS.remove( "/aws.conf.try" );
LittleFS.rename( "/aws.conf.bak.try", "/aws.conf" );
LittleFS.remove( "/config/aws.conf.try" );
LittleFS.rename( "/config/aws.conf.bak.try", "/config/aws.conf" );
Serial.printf( "[CONFIGMNGR] [ERROR] Configuration file is too big [%d bytes].\n" );
station.send_alarm( "Configuration error", "Configuration file is too big. Not applying changes!" );
return false;

}

LittleFS.remove( "/aws.conf" );
LittleFS.remove( "/config/aws.conf" );

if ( debug_mode )
list_files();

LittleFS.rename( "/aws.conf.try", "/aws.conf" );
LittleFS.rename( "/aws.conf.bak.try", "/aws.conf.bak" );
LittleFS.rename( "/config/aws.conf.try", "/config/aws.conf" );
LittleFS.rename( "/config/aws.conf.bak.try", "/config/aws.conf.bak" );
Serial.printf( "[CONFIGMNGR] [INFO ] Wrote %d bytes, configuration save successful.\n", s );

LittleFS.remove( "/root_ca.txt.try" );
if ( LittleFS.exists( "/root_ca.txt" ))
LittleFS.rename( "/root_ca.txt", "/root_ca.txt.try" );
LittleFS.remove( "/config/root_ca.txt.try" );
if ( LittleFS.exists( "/config/root_ca.txt" ))
LittleFS.rename( "/config/root_ca.txt", "/config/root_ca.txt.try" );

file = LittleFS.open( "/root_ca.txt.try", FILE_WRITE );
file = LittleFS.open( "/config/root_ca.txt.try", FILE_WRITE );
s = file.print( root_ca.data() );
file.close();
Serial.printf( "[CONFIGMNGR] [INFO ] Wrote %d bytes of ROOT CA.\n", s );
LittleFS.rename( "/root_ca.txt.try", "/root_ca.txt" );
LittleFS.rename( "/config/root_ca.txt.try", "/config/root_ca.txt" );

_can_rollback = 1;
if ( debug_mode )
Expand Down
1 change: 1 addition & 0 deletions src/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class AWSConfig {
template <typename T>
T get_aag_parameter( const char * );
void list_files( void );
void migrate_config_and_ui( void );
char nibble_to_hex_char(uint8_t) const;
bool read_config( etl::string<64> & );
bool read_file( const char * );
Expand Down
4 changes: 2 additions & 2 deletions src/config_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void AWSWebServer::index( AsyncWebServerRequest *request )
return;

}
request->send( LittleFS, "/index.html" );
request->send( LittleFS, "/ui/index.html" );
}

bool AWSWebServer::initialise( bool _debug_mode )
Expand Down Expand Up @@ -268,7 +268,7 @@ void AWSWebServer::start( void )
{
server->addHandler( new AsyncCallbackJsonWebHandler( "/set_config", std::bind( &AWSWebServer::set_configuration, this, std::placeholders::_1, std::placeholders::_2 )));
server->on( "/activate_sensors", HTTP_GET, std::bind( &AWSWebServer::activate_sensors, this, std::placeholders::_1 ));
server->on( "/aws.js", HTTP_GET, std::bind( &AWSWebServer::send_file, this, std::placeholders::_1 ));
server->on( "/ui/aws.js", HTTP_GET, std::bind( &AWSWebServer::send_file, this, std::placeholders::_1 ));
server->on( "/favicon.ico", HTTP_GET, std::bind( &AWSWebServer::send_file, this, std::placeholders::_1 ));
server->on( "/unsent.txt", HTTP_GET, std::bind( &AWSWebServer::send_sdcard_file, this, std::placeholders::_1 ));
server->on( "/get_backlog", HTTP_GET, std::bind( &AWSWebServer::get_backlog, this, std::placeholders::_1 ));
Expand Down
1 change: 0 additions & 1 deletion src/data/aws.conf.dfl

This file was deleted.

Loading