From d22d93ff08b9ff01a14377cd216fe628f4e6b9a2 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Fri, 19 Apr 2024 23:09:15 +0200 Subject: [PATCH] V/0.0.14 (#34) * bump build * introduce reset connection handler * skipe enqueue for 1 core devices * add auto update flag * updated security * show ip, mac * add configuration debug print * add chip info * new release script * updated readme * updated script * updates --------- Co-authored-by: Matteo Crippa --- .github/workflows/release.yml | 19 ++++++++++++++++--- CHANGELOG.md | 6 +++++- README.md | 18 ++++++++++-------- SECURITY.md | 2 +- src/current.cpp | 12 ++++++++++++ src/current.h | 1 + src/html/setup.html | 22 ++++++++++++++++++++-- src/leafminer.h | 2 +- src/main.cpp | 19 ++++++++++++++++++- src/model/configuration.h | 17 +++++++++++++++++ src/network/accesspoint.cpp | 4 ++++ src/network/network.cpp | 12 +++++++++++- src/storage/storage.cpp | 2 ++ version.json | 2 +- 14 files changed, 119 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8d2ef68..6cd54d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,9 +46,22 @@ jobs: - name: Archive Artifacts run: | mkdir -p artifacts - find .pio/build -name "firmware.bin" -exec sh -c 'cp "{}" "artifacts/firmware_$(basename $(dirname {})).bin"' \; - find .pio/build -name "bootloader.bin" -exec sh -c 'cp "{}" "artifacts/bootloader_$(basename $(dirname {})).bin"' \; - find .pio/build -name "partitions.bin" -exec sh -c 'cp "{}" "artifacts/partitions_$(basename $(dirname {})).bin"' \; + # Define the mapping of board names to file prefixes + declare -A board_map=( + ["esp8266"]="0x0000_firmware" + ["geekmagic-smalltv"]="0x0000_firmware" + ["esp32"]="0x10000_firmware 0x1000_bootloader 0x8000_partitions" + ["esp32-s2"]="0x10000_firmware 0x1000_bootloader 0x8000_partitions" + ["esp32-s3"]="0x10000_firmware 0x1000_bootloader 0x8000_partitions" + ["lilygo-t-display-s3"]="0x10000_firmware 0x1000_bootloader 0x8000_partitions" + ) + + # Iterate through each board and copy corresponding files + for board in "${!board_map[@]}"; do + for file_type in ${board_map[$board]}; do + find .pio/build -name "${file_type}.bin" -exec sh -c 'cp "{}" "artifacts/'"${board_map[$board]}"'_$(basename $(dirname {})).bin"' \; + done + done working-directory: ${{ github.workspace }} - name: Upload Artifacts diff --git a/CHANGELOG.md b/CHANGELOG.md index 03ffbab..e10ae45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ -# v0.0.13 +# v0.0.14 - Investigated issue with reboot on ESP8266 +- Add support for disable auto update to WebUI +- Fix WebUI bug for blinking +- Add new build script with address to write the binaries +- Updated readme diff --git a/README.md b/README.md index 77ee3d3..a64a13c 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,16 @@ _Legend_ | Board | Link | | :------------------------------------------------------- | :----------------------------------------------------------- | -| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | -| [GeekMagic SmartTV]() | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | -| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | -| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | -| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | -| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.13](https://github.com/matteocrippa/leafminer/releases) | - -- Browse to [ESPWebtool](https://esp.huhn.me/) using a Chrome based browser and follow the instructions. +| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | +| [GeekMagic SmartTV]() | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | +| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | +| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | +| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | +| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.14](https://github.com/matteocrippa/leafminer/releases) | + +- Browse to [ESPWebtool](https://esp.huhn.me/) using a Chrome based browser and upload the file according to the address in the file name. + +For example this is how ESP32-S3 will look like: LeafMiner Web flash diff --git a/SECURITY.md b/SECURITY.md index 4d35b16..9ac2f69 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,7 +4,7 @@ The following versions of LeafMiner are currently supported with security updates: -- 0.0.8 +- 0.0.14 ## Reporting a Vulnerability diff --git a/src/current.cpp b/src/current.cpp index c2999d9..423b5d2 100644 --- a/src/current.cpp +++ b/src/current.cpp @@ -78,12 +78,16 @@ void current_setJob(const Notification ¬ification) l_debug(TAG_CURRENT, "Job: %s is cleaned and replaced with %s", current_job->job_id.c_str(), notification.job_id.c_str()); } } + if (current_job_is_valid == 1) { +#if CORES > 1 current_job_next = new Job(notification, *current_subscribe, current_difficulty); l_info(TAG_CURRENT, "Job: %s queued", current_job_next->job_id.c_str()); +#endif return; } + current_job = new Job(notification, *current_subscribe, current_difficulty); current_job_is_valid = 1; l_info(TAG_CURRENT, "Job: %s ready to be mined", current_job->job_id.c_str()); @@ -127,6 +131,14 @@ const char *current_getUptime() return uptimeString; } +/** + * @brief Resets the current session by setting the current_subscribe pointer to nullptr. + */ +void current_resetSession() +{ + current_subscribe = nullptr; +} + /** * Sets the Subscribe object for the Current class. * diff --git a/src/current.h b/src/current.h index d71cbeb..55aeff1 100644 --- a/src/current.h +++ b/src/current.h @@ -17,6 +17,7 @@ const char *current_getJobId(); const char *current_getUptime(); void current_setSubscribe(Subscribe *subscribe); const char *current_getSessionId(); +void current_resetSession(); void current_setDifficulty(double difficulty); const double current_getDifficulty(); void current_increment_block_found(); diff --git a/src/html/setup.html b/src/html/setup.html index 5fa5ab8..ebc7b34 100644 --- a/src/html/setup.html +++ b/src/html/setup.html @@ -76,11 +76,29 @@

LeafMiner


+ + Off + + On + +
Off LeafMiner On > (40 - i)) & 0xff) << i; + } + l_info(TAG_MAIN, "Chip ID: %s", chipID); +#else + l_info(TAG_MAIN, "Chip ID: %s", ESP.getChipId()); +#endif #if defined(ESP8266) l_info(TAG_MAIN, "ESP8266 - Disable WDT"); @@ -46,6 +59,7 @@ void setup() force_ap = button_setup(); storage_load(&configuration); + configuration.print(); if (configuration.wifi_ssid == "" || force_ap) { @@ -70,7 +84,10 @@ void setup() screen_setup(); #endif // HAS_LCD - autoupdate(); + if (configuration.auto_update == "on") + { + autoupdate(); + } if (network_getJob() == -1) { diff --git a/src/model/configuration.h b/src/model/configuration.h index 9066bf8..5ff9004 100644 --- a/src/model/configuration.h +++ b/src/model/configuration.h @@ -3,6 +3,7 @@ #include #include +#include "utils/log.h" struct Configuration { @@ -16,6 +17,22 @@ struct Configuration int blink_brightness = 256; std::string lcd_on_start = ""; std::string miner_type = ""; + std::string auto_update = ""; + + void print() + { + l_info("wifi_ssid: %s", wifi_ssid.c_str()); + l_info("wifi_password: %s", wifi_password.c_str()); + l_info("wallet_address: %s", wallet_address.c_str()); + l_info("pool_password: %s", pool_password.c_str()); + l_info("pool_url: %s", pool_url.c_str()); + l_info("pool_port: %d", std::to_string(pool_port).c_str()); + l_info("blink_enabled: %s", blink_enabled.c_str()); + l_info("blink_brightness: %s", std::to_string(blink_brightness).c_str()); + l_info("lcd_on_start: %s", lcd_on_start.c_str()); + l_info("miner_type: %s", miner_type.c_str()); + l_info("auto_update: %s", auto_update.c_str()); + } }; #endif diff --git a/src/network/accesspoint.cpp b/src/network/accesspoint.cpp index 98a6eb1..613180f 100644 --- a/src/network/accesspoint.cpp +++ b/src/network/accesspoint.cpp @@ -51,6 +51,9 @@ std::string prepareHtmlWithValues(const Configuration &configuration) bool is_lcd_on = strcmp(configuration.lcd_on_start.c_str(), "on") == 0; replacePattern(html, "{{lcd_on_start_on}}", is_lcd_on ? "checked=\"checked\"" : ""); replacePattern(html, "{{lcd_on_start_off}}", !is_lcd_on ? "checked=\"checked\"" : ""); + bool is_autoupdate_on = strcmp(configuration.auto_update.c_str(), "on") == 0; + replacePattern(html, "{{auto_update_on}}", is_autoupdate_on ? "checked=\"checked\"" : ""); + replacePattern(html, "{{auto_update_off}}", !is_autoupdate_on ? "checked=\"checked\"" : ""); return html; } @@ -121,6 +124,7 @@ void accesspoint_webserver() conf.blink_enabled = request->arg("blink_enabled").c_str(); conf.blink_brightness = request->arg("blink_brightness").toInt(); conf.lcd_on_start = request->arg("lcd_on_start").c_str(); + conf.auto_update = request->arg("auto_update").c_str(); storage_save(conf); request->send(200, "text/html", "Data saved successfully!

Please reboot your board!"); }); diff --git a/src/network/network.cpp b/src/network/network.cpp index 1c13403..3bea3f0 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -79,6 +79,10 @@ short isConnected() return -1; } + l_info(TAG_NETWORK, "Connected to WiFi"); + l_info(TAG_NETWORK, "IP address: %s", WiFi.localIP().toString().c_str()); + l_info(TAG_NETWORK, "MAC address: %s", WiFi.macAddress().c_str()); + uint16_t wifi_stratum = 0; // and we are connected to the host @@ -358,6 +362,7 @@ short network_getJob() if (isConnected() == -1) { + current_resetSession(); return -1; } @@ -408,7 +413,11 @@ void network_listen() #endif int len = 0; - isConnected(); + if (isConnected() == -1) + { + current_resetSession(); + return; // Handle connection failure + } do { char data[NETWORK_BUFFER_SIZE]; @@ -429,6 +438,7 @@ void network_submit(const char *payload) { if (isConnected() == -1) { + current_resetSession(); return; // Handle connection failure } diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index c9dc85f..992f460 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -23,6 +23,7 @@ void storage_save(const Configuration &conf) preferences.putString("blink_enabled", conf.blink_enabled.c_str()); preferences.putUInt("blink_bright", conf.blink_brightness); preferences.putString("lcd_on_start", conf.lcd_on_start.c_str()); + preferences.putString("auto_update", conf.auto_update.c_str()); preferences.end(); } @@ -37,4 +38,5 @@ void storage_load(Configuration *conf) conf->blink_enabled = preferences.getString("blink_enabled", "on").c_str(); conf->blink_brightness = preferences.getUInt("blink_bright", 256); conf->lcd_on_start = preferences.getString("lcd_on_start", "on").c_str(); + conf->auto_update = preferences.getString("auto_update", "on").c_str(); } diff --git a/version.json b/version.json index f5328cb..2ee7f17 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "current": "0.0.13", + "current": "0.0.14", "link": "https://github.com/matteocrippa/leafminer/releases/download/v{{version}}/firmware_{{device}}.bin", "devices": [ "esp8266",