Skip to content

Commit

Permalink
Feature/v0.0.8 (#16)
Browse files Browse the repository at this point in the history
* new base server

* new logic

* improved timeout

* bump to 0.0.8

* fix comments for check stale

* tweak logic for network back

---------

Co-authored-by: Matteo Crippa <[email protected]>
  • Loading branch information
matteocrippa and Matteo Crippa authored Mar 9, 2024
1 parent 888f701 commit d850612
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 41 deletions.
13 changes: 2 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# v0.0.7
# v0.0.8

- Nonce increment
- Linted code
- Updated ESP32 dependecy
- Rework task handling
- Aligned logging system level to ESP ones
- Easy mass deployment via USB
- Improve hashrate visualization
- Add version check
- Auto reboot on stuck AP after 5 minutes
- Fix Log system
- Enforce reconnection logic
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ _Legend_

| Board | Link |
| :------------------------------------------------------- | :---------------------------------------------------------- |
| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [GeekMagic SmartTV]() | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.6](https://github.com/matteocrippa/leafminer/releases) |
| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |
| [GeekMagic SmartTV]() | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |
| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |
| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.8](https://github.com/matteocrippa/leafminer/releases) |

- Browse to [ESPWebtool](https://esp.huhn.me/) using a Chrome based browser and follow the instructions.

Expand All @@ -88,7 +88,7 @@ Follow these steps to set up your ESP32/ESP8266 with LEAFMINER:
4. **Provide Information and Save:**
Fill out the form, click the save button, and then reboot your device.

We've set _public-pool.io_ as the default solo pool, but feel free to change it to your preference.
We've set _pool.vkbit.com_ as the default solo pool, but feel free to change it to your preference.

**Verification:**
If the setup is successful, you'll see your miner in the stats.
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The following versions of LeafMiner are currently supported with security updates:

- 0.0.6
- 0.0.8

## Reporting a Vulnerability

Expand Down
10 changes: 6 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ build_flags =
-DSMOOTH_FONT

[env:esp32]
platform = https://github.com/platformio/platform-espressif32.git
platform = https://github.com/platformio/platform-espressif32.git#develop
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.4
board_build.arduino.upstream_packages = yes
board = esp32dev
Expand Down Expand Up @@ -106,7 +106,8 @@ build_flags =
-fexceptions

[env:esp32-s2]
platform = https://github.com/platformio/platform-espressif32.git
platform = https://github.com/platformio/platform-espressif32.git#develop
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.4
board = lolin_s2_mini
framework = arduino
monitor_speed = 115200
Expand All @@ -126,6 +127,7 @@ build_flags =

[env:esp32-s3]
platform = https://github.com/platformio/platform-espressif32.git#develop
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.4
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
Expand Down Expand Up @@ -154,12 +156,12 @@ build_flags =
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-DNDEBUG
-fexceptions

[env:lilygo-t-display-s3]
platform = https://github.com/platformio/platform-espressif32.git
platform = https://github.com/platformio/platform-espressif32.git#develop
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.4
board = lilygo-t-display-s3
framework = arduino
monitor_speed = 115200
Expand Down
18 changes: 10 additions & 8 deletions src/current.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "current.h"
#include "utils/log.h"
#include "screen/screen.h"
#include "network/network.h"

char TAG_CURRENT[8] = "Current";

Expand Down Expand Up @@ -289,33 +290,34 @@ void current_increment_hashes()
* The current hashrate is calculated in kilohashes per second (KH/s).
*/
void current_update_hashrate()
{
if(millis() - current_hashes_time > 1000) {
{
if (millis() - current_hashes_time > 1000)
{
current_hashrate = (current_hashes / ((millis() - current_hashes_time) / 1000.0)) / 1000.0; // KH/s
l_debug(TAG_CURRENT, "Hashrate: %.2f kH/s", current_hashrate);
#if defined(HAS_LCD)
#if defined(HAS_LCD)
screen_loop();
#endif
#endif
current_hashes = 0;
current_hashes_time = millis();
}
}

/**
* Checks if the current hash has not been received in the last 5 minutes.
* Checks if the current hash has not been received in the last 3 minutes.
* If the hash is stale, it logs an error message and restarts the ESP.
*/
void current_check_stale()
{
if (millis() - current_last_hash > 60000 * 5)
if (millis() - current_last_hash > 200000)
{
l_error(TAG_CURRENT, "No hash received in the last 5 minutes. Restarting...");
l_error(TAG_CURRENT, "No hash received in the last 3 minutes. Restarting...");
ESP.restart();
}
}

#if defined(ESP32)
#define CURRENT_STALE_TIMEOUT 60000 * 2
#define CURRENT_STALE_TIMEOUT 50000
void currentTaskFunction(void *pvParameters)
{
while (1)
Expand Down
2 changes: 1 addition & 1 deletion src/leafminer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LEAFMINER_H
#define LEAFMINER_H

#define _VERSION "0.0.7"
#define _VERSION "0.0.8"
#define DIFFICULTY 1e-4

// Mining
Expand Down
7 changes: 5 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ void setup()
btStop();
xTaskCreate(currentTaskFunction, "stale", 1024, NULL, 1, NULL);
xTaskCreate(buttonTaskFunction, "button", 1024, NULL, 2, NULL);
xTaskCreate(mineTaskFunction, "miner0", 16000, (void *)0, 10, NULL);
xTaskCreate(mineTaskFunction, "miner0", 6000, (void *)0, 10, NULL);
xTaskCreate(networkTaskFunction, "network", 10000, NULL, 3, NULL);
#if CORE == 2
xTaskCreate(mineTaskFunction, "miner1", 16000, (void *)1, 11, NULL);
xTaskCreate(mineTaskFunction, "miner1", 6000, (void *)1, 11, NULL);
#endif
#endif

#if defined(ESPS8266)
network_listen();
#endif
}

void loop()
Expand Down
24 changes: 20 additions & 4 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,20 @@ void network_send(const std::string &job_id, const std::string &extranonce2, con
char payload[256];
snprintf(payload, sizeof(payload), "{\"id\":%llu,\"method\":\"mining.submit\",\"params\":[\"%s\",\"%s\",\"%s\",\"%s\",\"%08x\"]}\n", nextId(), configuration.wallet_address.c_str(), job_id.c_str(), extranonce2.c_str(), ntime.c_str(), nonce);
request(payload);
#if defined(ESP8266)
network_listen();
#endif
}

void network_listen()
{
#if defined(ESP8266)
if (isListening == 1)
{
return;
}
isListening = 1;
#endif
int len = 0;
isConnected();
do
Expand All @@ -393,9 +397,21 @@ void network_listen()
{
response(data);
}
#if defined(ESP32)
delay(89);
#endif
} while (len > 0);
#if defined(ESP8266)
isListening = 0;
}
#endif
}

#if defined(ESP32)
#define NETWORK_TASK_TIMEOUT 600
void networkTaskFunction(void *pvParameters)
{
while (1)
{
network_listen();
network_listen();
vTaskDelay(NETWORK_TASK_TIMEOUT / portTICK_PERIOD_MS);
}
}
#endif
1 change: 1 addition & 0 deletions src/network/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
short network_getJob();
void network_send(const std::string &job_id, const std::string &extranonce2, const std::string &ntime, const uint32_t &nonce);
void network_listen();
void networkTaskFunction(void *pvParameters);
#endif // NETWORK_H
4 changes: 2 additions & 2 deletions src/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void storage_load(Configuration *conf)
conf->wifi_password = preferences.getString("wifi_password", "").c_str();
conf->wallet_address = preferences.getString("wallet_address", "").c_str();
conf->pool_password = preferences.getString("pool_password", "").c_str();
conf->pool_url = preferences.getString("pool_url", "public-pool.io").c_str();
conf->pool_port = preferences.getUInt("pool_port", 21496);
conf->pool_url = preferences.getString("pool_url", "pool.vkbit.com").c_str();
conf->pool_port = preferences.getUInt("pool_port", 3333);
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();
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"current": "0.0.7",
"current": "0.0.8",
"link": "https://github.com/matteocrippa/leafminer/releases/download/v{{version}}/firmware_{{device}}.bin",
"devices": [
"esp8266",
Expand Down

0 comments on commit d850612

Please sign in to comment.