diff --git a/bgeigiezen_firmware/controller.cpp b/bgeigiezen_firmware/controller.cpp index 26f5a89f..7b09a9a1 100644 --- a/bgeigiezen_firmware/controller.cpp +++ b/bgeigiezen_firmware/controller.cpp @@ -90,18 +90,14 @@ bool Controller::write_sd_config() { return SDInterface::i().write_safezen_file_from_settings(_settings); } -bool Controller::gps_cold_start() { - _gnss.coldStart(); - return true; // how to check? no idea +TeenyUbloxConnect& Controller::get_gnss() { + return _gnss; } void Controller::reset_settings() { _settings.reset_defaults(); } -void Controller::set_fixed_testing(bool enable) { - -} const LocalStorage& Controller::get_settings() const { return _settings; } diff --git a/bgeigiezen_firmware/controller.h b/bgeigiezen_firmware/controller.h index e3b2369e..a3f19911 100644 --- a/bgeigiezen_firmware/controller.h +++ b/bgeigiezen_firmware/controller.h @@ -57,14 +57,9 @@ class Controller : public Aggregator, public Worker { bool write_sd_config(); /** - * Writes device settings onto SD - */ - bool gps_cold_start(); - - /** - * Set fixed mode testing + * get GNSS instance */ - void set_fixed_testing(bool enable); + TeenyUbloxConnect& get_gnss(); /** * Reset memory settings and restart system diff --git a/bgeigiezen_firmware/screens/config_mode.cpp b/bgeigiezen_firmware/screens/config_mode.cpp index c197ed41..870d62ce 100644 --- a/bgeigiezen_firmware/screens/config_mode.cpp +++ b/bgeigiezen_firmware/screens/config_mode.cpp @@ -107,7 +107,7 @@ void ConfigModeScreen::render_page_main(const worker_map_t& workers, const handl // Temp print out device settings on screen const auto& config = *workers.worker(k_worker_local_storage); - M5.Lcd.setCursor(0, 30, &fonts::Font2); + M5.Lcd.setCursor(0, 40, &fonts::Font2); if (_main_page_info_section == e_config_section_device) { M5.Lcd.printf("Device settings\n\n"); @@ -142,13 +142,13 @@ void ConfigModeScreen::render_page_ap(const worker_map_t& workers, const handler const auto settings = workers.worker(k_worker_local_storage); - M5.Lcd.setCursor(0, 78, &fonts::Font0); + M5.Lcd.setCursor(0, 70, &fonts::Font2); M5.Lcd.setTextColor(LCD_COLOR_DEFAULT, LCD_COLOR_BACKGROUND); M5.Lcd.printf("Config through Access Point, connect to\n"); - M5.Lcd.printf("SSID: %s\n", WiFiWrapper_i.get_hostname()); - M5.Lcd.printf("Password: %s\n", settings->get_ap_password()); + M5.Lcd.printf("SSID: %s\n", WiFiWrapper_i.get_hostname()); + M5.Lcd.printf("Password: %s\n", settings->get_ap_password()); - M5.Lcd.printf("IP: %s \n", WiFi.softAPIP().toString().c_str()); + M5.Lcd.printf("IP: %s \n", WiFi.softAPIP().toString().c_str()); } void ConfigModeScreen::render_page_wifi(const worker_map_t& workers, const handler_map_t& handlers) { @@ -157,13 +157,13 @@ void ConfigModeScreen::render_page_wifi(const worker_map_t& workers, const handl const auto settings = workers.worker(k_worker_local_storage); - M5.Lcd.setCursor(0, 78, &fonts::Font0); + M5.Lcd.setCursor(0, 70, &fonts::Font2); M5.Lcd.setTextColor(LCD_COLOR_DEFAULT, LCD_COLOR_BACKGROUND); M5.Lcd.printf("Config through local network, connect to\n"); - M5.Lcd.printf("Network: %s\n", settings->get_wifi_ssid()); - M5.Lcd.printf("Connected: %s\n", WiFiWrapper_i.wifi_connected() ? "Yes " : "Not yet..."); + M5.Lcd.printf("Network: %s\n", settings->get_wifi_ssid()); + M5.Lcd.printf("Connected: %s\n", WiFiWrapper_i.wifi_connected() ? "Yes " : "Not yet..."); - M5.Lcd.printf("IP: %s \n", WiFiWrapper_i.wifi_connected() ? WiFi.localIP().toString().c_str() : "Waiting for connection... "); + M5.Lcd.printf("IP: %s \n", WiFiWrapper_i.wifi_connected() ? WiFi.localIP().toString().c_str() : "Waiting for connection... "); } void ConfigModeScreen::render_reset_device(const worker_map_t& workers, const handler_map_t& handlers) { @@ -171,7 +171,7 @@ void ConfigModeScreen::render_reset_device(const worker_map_t& workers, const ha drawButton2("RESET"); drawButton3("Menu"); - M5.Lcd.setCursor(0, 78, &fonts::Font0); + M5.Lcd.setCursor(0, 70, &fonts::Font2); M5.Lcd.setTextColor(LCD_COLOR_DEFAULT, LCD_COLOR_BACKGROUND); M5.Lcd.printf("Press RESET to confirm clearing all local storage\n"); } diff --git a/bgeigiezen_firmware/screens/satellite_view.cpp b/bgeigiezen_firmware/screens/satellite_view.cpp index 55749d90..0b8660c8 100644 --- a/bgeigiezen_firmware/screens/satellite_view.cpp +++ b/bgeigiezen_firmware/screens/satellite_view.cpp @@ -132,7 +132,7 @@ void SatelliteViewScreen::render(const worker_map_t& workers, const handler_map_ case 4: label = 'S'; break; case 6: label = 'W'; break; } - M5.Lcd.drawChar(xCoord + mapCenterX - 5, yCoord + mapCenterY - 7, label, LCD_COLOR_DEFAULT, LCD_COLOR_BACKGROUND, 2); + M5.Lcd.drawChar(xCoord + mapCenterX - 5, yCoord + mapCenterY - 7, label, LCD_COLOR_BACKGROUND, LCD_COLOR_DEFAULT, 2); } if (navsat->get_data().available) { @@ -141,10 +141,10 @@ void SatelliteViewScreen::render(const worker_map_t& workers, const handler_map_ const auto& navsat_info = navsat->get_data().navsat_info; // draw the positions of the sats - for(int16_t i = navsat_info.numSvsEphValid -1; i >= 0; i--) { + for(int16_t i = navsat_info.numSvsEphValid -1; i >= 0; --i) { // Sat position - numSats ++; + ++numSats; satAzimuth = navsat_info.svSortList[i].azim; satElevation = navsat_info.svSortList[i].elev; if(satElevation < 0) satElevation = 0; @@ -211,7 +211,7 @@ void SatelliteViewScreen::enter_screen(Controller& controller) { // controller.set_worker_active(k_worker_navsat_collector, true); switch (_current_page) { case e_satellite_page_cold_start: - controller.gps_cold_start(); + controller.get_gnss().coldStart(); set_status_message(F(" GPS cold start, this can take a while...")); _current_page = e_satellite_page_main; // Back on main page open_menu(false); // Re-enter menu diff --git a/bgeigiezen_firmware/utils/http_pages.cpp b/bgeigiezen_firmware/utils/http_pages.cpp index d825bbf9..63d6e5e5 100644 --- a/bgeigiezen_firmware/utils/http_pages.cpp +++ b/bgeigiezen_firmware/utils/http_pages.cpp @@ -52,7 +52,6 @@ const char* base_page_format_begin = "
  • Device
  • " "
  • Connection
  • " "
  • Location
  • " - "
  • Update firmware
  • " "
  • Github
  • " "" "" @@ -79,10 +78,9 @@ const char* HttpPages::get_home_page(const LocalStorage& settings) { "

    bGeigieZen version %s

    " "

    " "

    " "More information about configurations in the User manual. " "Or view your device on Grafana." diff --git a/bgeigiezen_firmware/workers/battery_indicator.cpp b/bgeigiezen_firmware/workers/battery_indicator.cpp index 03007a3d..273481ae 100644 --- a/bgeigiezen_firmware/workers/battery_indicator.cpp +++ b/bgeigiezen_firmware/workers/battery_indicator.cpp @@ -1,7 +1,5 @@ #include "battery_indicator.h" -#include - BatteryIndicator::BatteryIndicator() : Worker(1000) { } diff --git a/bgeigiezen_firmware/workers/battery_indicator.h b/bgeigiezen_firmware/workers/battery_indicator.h index 9fc23b1e..46d8b4f0 100644 --- a/bgeigiezen_firmware/workers/battery_indicator.h +++ b/bgeigiezen_firmware/workers/battery_indicator.h @@ -1,15 +1,15 @@ #ifndef BGEIGIEZEN_BATTERYINDICATOR_H_ #define BGEIGIEZEN_BATTERYINDICATOR_H_ +#include #include -#include /** * Relevant battery status */ struct BatteryStatus { - uint8_t percentage; - bool isCharging; + int32_t percentage; + m5::Power_Class::is_charging_t isCharging; }; /** diff --git a/bgeigiezen_firmware/workers/configuration_server.cpp b/bgeigiezen_firmware/workers/configuration_server.cpp index dd44a980..60854931 100644 --- a/bgeigiezen_firmware/workers/configuration_server.cpp +++ b/bgeigiezen_firmware/workers/configuration_server.cpp @@ -13,7 +13,8 @@ T clamp(T2 val, T min, T max) { ConfigWebServer::ConfigWebServer(LocalStorage& config) : Worker(k_server_status_offline, 0), _server(SERVER_WIFI_PORT), - _config(config) { + _config(config), + _handled_client(false) { add_urls(); } @@ -27,20 +28,21 @@ bool ConfigWebServer::activate(bool) { // Start config server _server.begin(SERVER_WIFI_PORT); HttpPages::internet_access = WiFiWrapper_i.wifi_connected(); + data = HttpPages::internet_access ? k_server_status_running_wifi : k_server_status_running_access_point; return true; } return false; } void ConfigWebServer::deactivate() { + data = k_server_status_offline; _server.close(); - _server.stop(); } int8_t ConfigWebServer::produce_data() { _server.handleClient(); - if(data == k_server_status_offline) { - data = HttpPages::internet_access ? k_server_status_running_wifi : k_server_status_running_access_point; + if (_handled_client) { + _handled_client = false; return Worker::e_worker_data_read; } return Worker::e_worker_idle; @@ -49,60 +51,70 @@ int8_t ConfigWebServer::produce_data() { void ConfigWebServer::add_urls() { // Home _server.on("/", HTTP_GET, [this]() { + M5_LOGD("Handle get home"); _server.sendHeader("Connection", "close"); - _server.send(200, "text/html", HttpPages::get_home_page(_config)); + _server.send_P(200, "text/html", HttpPages::get_home_page(_config)); + _handled_client = true; }); // Configure Device _server.on("/device", HTTP_GET, [this]() { + M5_LOGD("Handle get device settings"); _server.sendHeader("Connection", "close"); - _server.send(200, "text/html", HttpPages::get_config_device_page( + _server.send_P(200, "text/html", HttpPages::get_config_device_page( _server.hasArg("success"), _config )); + _handled_client = true; }); // Configure Connection _server.on("/connection", HTTP_GET, [this]() { + M5_LOGD("Handle get connection settings"); _server.sendHeader("Connection", "close"); - _server.send(200, "text/html", HttpPages::get_config_connection_page( + _server.send_P(200, "text/html", HttpPages::get_config_connection_page( _server.hasArg("success"), _config )); + _handled_client = true; }); // Configure Location _server.on("/location", HTTP_GET, [this]() { - + M5_LOGD("Handle get location settings"); _server.sendHeader("Connection", "close"); - _server.send(200, "text/html", HttpPages::get_config_location_page( + _server.send_P(200, "text/html", HttpPages::get_config_location_page( _server.hasArg("success"), _config )); - - _server.sendHeader("Connection", "close"); + _handled_client = true; }); // Save config _server.on("/save", HTTP_POST, [this]() { handle_save(); + _handled_client = true; }); _server.on("/reboot", [this]() { // Reboot - _server.send(200, "text/plain", "OK"); + M5_LOGD("Handle reboot request"); + _server.send_P(200, "text/plain", "OK"); _server.client().flush(); ESP.restart(); + _handled_client = true; }); // css get _server.on("/pure.css", HTTP_GET, [this]() { _server.sendHeader("Content-Encoding", "gzip"); _server.send_P(200, "text/css", reinterpret_cast(HttpPages::pure_css), PURE_CSS_SIZE); + _handled_client = true; }); // css get _server.on("/favicon.ico", HTTP_GET, [this]() { _server.send_P(200, "image/x-icon", reinterpret_cast(HttpPages::favicon), FAVICON_SIZE); + _handled_client = true; }); } @@ -111,6 +123,8 @@ void ConfigWebServer::handle_save() { // _config.set...(_server.arg(...).c_str(), ...); // } + M5_LOGD("Handle post request"); + if(_server.hasArg(FORM_NAME_ALERT_THRESHOLD)) { _config.set_alert_threshold(clamp(_server.arg(FORM_NAME_ALERT_THRESHOLD).toInt(), 0, 34464), false); } diff --git a/bgeigiezen_firmware/workers/configuration_server.h b/bgeigiezen_firmware/workers/configuration_server.h index ac7d7088..7b52b125 100644 --- a/bgeigiezen_firmware/workers/configuration_server.h +++ b/bgeigiezen_firmware/workers/configuration_server.h @@ -61,6 +61,7 @@ class ConfigWebServer : public Worker { WebServer _server; LocalStorage& _config; + bool _handled_client; }; #endif //BGEIGIEZEN_SERVER_H_ diff --git a/bgeigiezen_firmware/workers/local_storage.cpp b/bgeigiezen_firmware/workers/local_storage.cpp index 1fcecc11..84ccf140 100644 --- a/bgeigiezen_firmware/workers/local_storage.cpp +++ b/bgeigiezen_firmware/workers/local_storage.cpp @@ -289,7 +289,7 @@ void LocalStorage::set_wifi_ssid(const char* wifi_ssid, bool force) { } void LocalStorage::set_wifi_password(const char* wifi_password, bool force) { - if(force || (wifi_password != nullptr && strlen(wifi_password) < CONFIG_VAL_MAX)) { + if(force || (wifi_password != nullptr && strlen(wifi_password) < CONFIG_LONG_VAL_MAX)) { if(_memory.begin(memory_name)) { strcpy(_wifi_password, wifi_password); _memory.putString(key_wifi_password, _wifi_password); diff --git a/bgeigiezen_firmware/workers/local_storage.h b/bgeigiezen_firmware/workers/local_storage.h index 9930a720..1361c7c4 100644 --- a/bgeigiezen_firmware/workers/local_storage.h +++ b/bgeigiezen_firmware/workers/local_storage.h @@ -6,6 +6,7 @@ #include #define CONFIG_VAL_MAX 32 +#define CONFIG_LONG_VAL_MAX 64 /** * Configurations for the ESP32, stored in the flash memory @@ -96,7 +97,7 @@ class LocalStorage : public ProcessWorker { // Connection settings char _wifi_ssid[CONFIG_VAL_MAX]; - char _wifi_password[CONFIG_VAL_MAX]; + char _wifi_password[CONFIG_LONG_VAL_MAX]; char _api_key[CONFIG_VAL_MAX]; // Location settings diff --git a/bgeigiezen_firmware/workers/rtc_connector.cpp b/bgeigiezen_firmware/workers/rtc_connector.cpp index f9941f3a..37ce2a84 100644 --- a/bgeigiezen_firmware/workers/rtc_connector.cpp +++ b/bgeigiezen_firmware/workers/rtc_connector.cpp @@ -10,7 +10,7 @@ #include "identifiers.h" -DateTimeProvider::DateTimeProvider() : ProcessWorker({.valid=false}, 1000), _sys_time{}, _last_sys_set(0) { +DateTimeProvider::DateTimeProvider() : ProcessWorker({.valid=false, .gps_confirmed=false}, 1000), _sys_time{}, _last_sys_set(0) { } /** @@ -67,11 +67,14 @@ void DateTimeProvider::gps_to_system(const GnssData& gps_data) { sys_time.tm_hour = gps_data.hour; sys_time.tm_min = gps_data.minute; sys_time.tm_sec = gps_data.second; - save_to_system(sys_time); + + data.gps_confirmed = true; M5_LOGD("Set system time from GPS: %04d-%02d-%02d %02d:%02d:%02d", gps_data.year, gps_data.month, gps_data.day, gps_data.hour, gps_data.minute, gps_data.second); + + save_to_system(sys_time); } } @@ -79,7 +82,12 @@ void DateTimeProvider::rtc_to_system() { if (M5.Rtc.isEnabled()) { m5::rtc_datetime_t rtc_datetime; M5.Rtc.getDateTime(&rtc_datetime); - if (rtc_datetime.date.year < 2024 || rtc_datetime.date.year > 2035) { + + M5_LOGD("Load from RTC: %04d-%02d-%02d %02d:%02d:%02d", + rtc_datetime.date.year, rtc_datetime.date.month, rtc_datetime.date.date, + rtc_datetime.time.hours, rtc_datetime.time.minutes, rtc_datetime.time.seconds); + + if (M5.Rtc.getVoltLow() || rtc_datetime.date.year < 2024) { // RTC returned invalid data M5_LOGD("RTC invalid year, reset sys time"); return invalidate_sys_time(); @@ -93,10 +101,6 @@ void DateTimeProvider::rtc_to_system() { sys_time.tm_min = static_cast(rtc_datetime.time.minutes); sys_time.tm_sec = static_cast(rtc_datetime.time.seconds); - M5_LOGD("Set system time from RTC: %04d-%02d-%02d %02d:%02d:%02d", - rtc_datetime.date.year, rtc_datetime.date.month, rtc_datetime.date.date, - rtc_datetime.time.hours, rtc_datetime.time.minutes, rtc_datetime.time.seconds); - save_to_system(sys_time); } } diff --git a/bgeigiezen_firmware/workers/rtc_connector.h b/bgeigiezen_firmware/workers/rtc_connector.h index 2f4bcef5..72e32383 100644 --- a/bgeigiezen_firmware/workers/rtc_connector.h +++ b/bgeigiezen_firmware/workers/rtc_connector.h @@ -29,6 +29,7 @@ struct RtcData { uint8_t minute; uint8_t second; bool valid; + bool gps_confirmed; }; /**