Skip to content

Commit

Permalink
Feature/v0.0.7 (#15)
Browse files Browse the repository at this point in the history
* fix changelog

* tweaks for esp8266

* fix esp8266

* adjust nonce increment

* updated docs

* linted

* updated changelog

* use master platform

* logs uses esp level logic

* drop float

* add isListening flag

* any miner can use network

* migrate to xCreateTask

* tweak

* fix blink

* add mass deploy

* minor fix

* tweaks

* minor tweaks

* migrate to inlines

* inline migration

* linted

* bump version

* linted

* fix hash

* fix release script

* fix task for screen

* fix screen

* prepare 0.0.6

* fix for screen

* add version checker

* fix auto update

* fix log levels

* attempt to fix esp32

* tweak project

* bump to 0.0.7

* tweaks

* move html to char

* add auto reset logic

* minor tweaks

* fix project

---------

Co-authored-by: Matteo Crippa <[email protected]>
  • Loading branch information
matteocrippa and Matteo Crippa authored Mar 7, 2024
1 parent 4de94ae commit 888f701
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v0.0.6
# v0.0.7

- Nonce increment
- Linted code
Expand All @@ -8,3 +8,5 @@
- Easy mass deployment via USB
- Improve hashrate visualization
- Add version check
- Auto reboot on stuck AP after 5 minutes
- Fix Log system
12 changes: 11 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ build_flags =

[env:esp32]
platform = https://github.com/platformio/platform-espressif32.git
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.4
board_build.arduino.upstream_packages = yes
board = esp32dev
board_build.f_cpu = 240000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
framework = arduino
monitor_speed = 115200
build_type = debug
Expand All @@ -94,6 +99,11 @@ build_flags =
-O3
-DESP32_WROOM=1
-DLOG_LEVEL=3
-DBOARD_HAS_PSRAM
-DCONFIG_SPIRAM_CACHE_WORKAROUND
-DCORE_DEBUG_LEVEL=0
-mfix-esp32-psram-cache-issue
-fexceptions

[env:esp32-s2]
platform = https://github.com/platformio/platform-espressif32.git
Expand All @@ -115,7 +125,7 @@ build_flags =
-DLOG_LEVEL=3

[env:esp32-s3]
platform = https://github.com/platformio/platform-espressif32.git
platform = https://github.com/platformio/platform-espressif32.git#develop
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
Expand Down
2 changes: 1 addition & 1 deletion src/html/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#include <string>

const std::string html_ota = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>LeafMiner OTA</title><style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } form { max-width: 400px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } p { width: auto; text-align: center; } label { display: block; margin-bottom: 8px; } input { width: 100%; padding: 8px; margin-bottom: 16px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; } input[type=\"radio\"] { width: auto; } input[type=\"submit\"] { background-color: #4caf50; color: #fff; cursor: pointer; } input[type=\"submit\"]:hover { background-color: #45a049; } </style></head><body><form method=\"post\" action=\"/upload\" enctype=\"multipart/form-data\"><h1>LeafMiner</h1><label>OTA bin file:</label><input type=\"file\" name=\"update\"><br /><input type=\"submit\" value=\"Upload & Install\" /></form></body></html>";
const char html_ota[] = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>LeafMiner OTA</title><style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } form { max-width: 400px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } p { width: auto; text-align: center; } label { display: block; margin-bottom: 8px; } input { width: 100%; padding: 8px; margin-bottom: 16px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; } input[type=\"radio\"] { width: auto; } input[type=\"submit\"] { background-color: #4caf50; color: #fff; cursor: pointer; } input[type=\"submit\"]:hover { background-color: #45a049; } </style></head><body><form method=\"post\" action=\"/upload\" enctype=\"multipart/form-data\"><h1>LeafMiner</h1><label>OTA bin file:</label><input type=\"file\" name=\"update\"><br /><input type=\"submit\" value=\"Upload & Install\" /></form></body></html>";

#endif // HTML_OTA_H
4 changes: 1 addition & 3 deletions src/html/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifndef HTML_SETUP_H
#define HTML_SETUP_H

#include <string>

const std::string html_setup = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>LeafMiner Setup</title><style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } form { max-width: 400px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } p { width: auto; text-align: center; } label { display: block; margin-bottom: 8px; } input { width: 100%; padding: 8px; margin-bottom: 16px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; } input[type=\"radio\"] { width: auto; } input[type=\"submit\"] { background-color: #4caf50; color: #fff; cursor: pointer; } input[type=\"submit\"]:hover { background-color: #45a049; } </style></head><body><form method=\"post\" action=\"/save\"><h1>LeafMiner</h1><label>SSID:</label><input type=\"text\" name=\"wifi_ssid\" value=\"{{wifi_ssid}}\" /><br /><label>Password:</label><input type=\"password\" name=\"wifi_password\" value=\"{{wifi_password}}\" /><br /><label>Wallet Address:</label><input type=\"text\" name=\"wallet_address\" value=\"{{wallet_address}}\" /><br /><label>Pool Password:</label><input type=\"password\" name=\"pool_password\" value=\"{{pool_password}}\" /><br /><label>Pool URL:</label><input type=\"text\" name=\"pool_url\" value=\"{{pool_url}}\" /><br /><label>Pool Port:</label><input type=\"number\" name=\"pool_port\" value=\"{{pool_port}}\" /><br /><label>Blinking Enabled:</label> Off <input type=\"radio\" id=\"lcd_on_start_off\" name=\"blink_enabled\" value=\"off\" {{blink_enabled_off}} /> On <input type=\"radio\" id=\"lcd_on_start_on\" name=\"blink_enabled\" value=\"on\" {{blink_enabled_on}} /><br /><label>Blinking Brightness:</label><input type=\"number\" name=\"blink_brightness\" value=\"{{blink_brightness}}\" /><br /><label>LCD Status on Start:</label> Off <input type=\"radio\" id=\"lcd_on_start_off\" name=\"lcd_on_start\" value=\"off\" {{lcd_on_start_off}} /> On <input type=\"radio\" id=\"lcd_on_start_on\" name=\"lcd_on_start\" value=\"on\" {{lcd_on_start_on}} /><br /><input type=\"submit\" value=\"Save\" /></form><br /><br /><p><a href=\"/ota\">Firmware Upgrade</a></p></body></html>";
const char html_setup[] = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>LeafMiner Setup</title><style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } form { max-width: 400px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } p { width: auto; text-align: center; } label { display: block; margin-bottom: 8px; } input { width: 100%; padding: 8px; margin-bottom: 16px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; } input[type=\"radio\"] { width: auto; } input[type=\"submit\"] { background-color: #4caf50; color: #fff; cursor: pointer; } input[type=\"submit\"]:hover { background-color: #45a049; } </style></head><body><form method=\"post\" action=\"/save\"><h1>LeafMiner</h1><label>SSID:</label><input type=\"text\" name=\"wifi_ssid\" value=\"{{wifi_ssid}}\" /><br /><label>Password:</label><input type=\"password\" name=\"wifi_password\" value=\"{{wifi_password}}\" /><br /><label>Wallet Address:</label><input type=\"text\" name=\"wallet_address\" value=\"{{wallet_address}}\" /><br /><label>Pool Password:</label><input type=\"password\" name=\"pool_password\" value=\"{{pool_password}}\" /><br /><label>Pool URL:</label><input type=\"text\" name=\"pool_url\" value=\"{{pool_url}}\" /><br /><label>Pool Port:</label><input type=\"number\" name=\"pool_port\" value=\"{{pool_port}}\" /><br /><label>Blinking Enabled:</label> Off <input type=\"radio\" id=\"lcd_on_start_off\" name=\"blink_enabled\" value=\"off\" {{blink_enabled_off}} /> On <input type=\"radio\" id=\"lcd_on_start_on\" name=\"blink_enabled\" value=\"on\" {{blink_enabled_on}} /><br /><label>Blinking Brightness:</label><input type=\"number\" name=\"blink_brightness\" value=\"{{blink_brightness}}\" /><br /><label>LCD Status on Start:</label> Off <input type=\"radio\" id=\"lcd_on_start_off\" name=\"lcd_on_start\" value=\"off\" {{lcd_on_start_off}} /> On <input type=\"radio\" id=\"lcd_on_start_on\" name=\"lcd_on_start\" value=\"on\" {{lcd_on_start_on}} /><br /><input type=\"submit\" value=\"Save\" /></form><br /><br /><p><a href=\"/ota\">Firmware Upgrade</a></p></body></html>";

#endif // HTML_SETUP_H
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.6"
#define _VERSION "0.0.7"
#define DIFFICULTY 1e-4

// Mining
Expand Down
4 changes: 0 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include "storage/storage.h"
#include "network/autoupdate.h"
#include "massdeploy.h"
#if defined(ESP32)
#include <WiFi.h>
#include "freertos/task.h"
#endif // ESP32
#if defined(HAS_LCD)
#include "screen/screen.h"
#endif // HAS_LCD
Expand Down
5 changes: 0 additions & 5 deletions src/miner/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ void miner(uint32_t core)
current_update_hashrate();
}

#if defined(ESP32)
l_info(TAG_MINER, "[%d] > Heap / Free heap / Min free heap: %d / %d / %d", core, ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap());
#else
#if defined(HAS_LCD)
screen_loop();
#endif // HAS_LCD
#endif

l_info(TAG_MINER, "[%d] > [%s] > 0x%.8x - diff %.12f", core, current_job->job_id.c_str(), winning_nonce, diff_hash);
network_send(current_job->job_id, current_job->extranonce2, current_job->ntime, winning_nonce);
network_listen();

current_setHighestDifficulty(diff_hash);

Expand Down
10 changes: 9 additions & 1 deletion src/network/accesspoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void accesspoint_webserver()
request->send(200, "text/html", html); });

server.on("/ota", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(200, "text/html", String(html_ota.c_str())); });
{ request->send(200, "text/html", String(html_ota)); });

server.on(
"/upload", HTTP_POST, [](AsyncWebServerRequest *request)
Expand Down Expand Up @@ -132,6 +132,8 @@ void accesspoint_webserver()
l_info(TAG_AP, "Webserver Started");
}

uint64_t accesspoint_uptime = 0;

void accesspoint_setup()
{
l_debug(TAG_AP, "Setup");
Expand All @@ -140,10 +142,16 @@ void accesspoint_setup()
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(AP_DNS_PORT, "*", WiFi.softAPIP());
accesspoint_webserver();
accesspoint_uptime = millis();
}

void accesspoint_loop()
{
dnsServer.processNextRequest();
delay(100);
if (millis() - accesspoint_uptime > 300000)
{
l_debug(TAG_AP, "Stop AP and reboot");
ESP.restart();
}
}
6 changes: 3 additions & 3 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ uint64_t nextId()
*/
short isConnected()
{

if (WiFi.status() == WL_CONNECTED && client.connected())
{
return 1;
Expand All @@ -67,7 +66,7 @@ short isConnected()
{
break;
}
delay(2000);
delay(1500);
}

if (WiFi.waitForConnectResult() != WL_CONNECTED)
Expand Down Expand Up @@ -373,6 +372,7 @@ 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);
network_listen();
}

void network_listen()
Expand All @@ -394,7 +394,7 @@ void network_listen()
response(data);
}
#if defined(ESP32)
delay(100);
delay(89);
#endif
} while (len > 0);
isListening = 0;
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.6",
"current": "0.0.7",
"link": "https://github.com/matteocrippa/leafminer/releases/download/v{{version}}/firmware_{{device}}.bin",
"devices": [
"esp8266",
Expand Down

0 comments on commit 888f701

Please sign in to comment.