Skip to content

Commit 934299e

Browse files
matteocrippaMatteo Crippa
andauthored
Feature/v0.0.10 (#19)
* minor changes * bump version * fix readme --------- Co-authored-by: Matteo Crippa <matteocrippa@github.users.com>
1 parent 665601c commit 934299e

File tree

5 files changed

+71
-26
lines changed

5 files changed

+71
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# v0.0.9
1+
# v0.0.10
2+
3+
- Improved network handling
24

3-
- Fix build script for binaries

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ _Legend_
5555

5656
- Download the binary file for your board
5757

58-
| Board | Link |
59-
| :------------------------------------------------------- | :---------------------------------------------------------- |
60-
| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
61-
| [GeekMagic SmartTV]() | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
62-
| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
63-
| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
64-
| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
65-
| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.9](https://github.com/matteocrippa/leafminer/releases) |
58+
| Board | Link |
59+
| :------------------------------------------------------- | :----------------------------------------------------------- |
60+
| [ESP8266](https://s.click.aliexpress.com/e/_EuwffHJ) | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
61+
| [GeekMagic SmartTV]() | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
62+
| [ESP32](https://s.click.aliexpress.com/e/_Ey6AJnT) | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
63+
| [ESP32-S2](https://s.click.aliexpress.com/e/_EGJcibR) | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
64+
| [ESP32-S3](https://s.click.aliexpress.com/e/_EJbAXyl) | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
65+
| [LILYGO-T-S3](https://s.click.aliexpress.com/e/_ExRWk6H) | [0.0.10](https://github.com/matteocrippa/leafminer/releases) |
6666

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

src/leafminer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LEAFMINER_H
22
#define LEAFMINER_H
33

4-
#define _VERSION "0.0.9"
4+
#define _VERSION "0.0.10"
55
#define DIFFICULTY 1e-4
66

77
// Mining

src/network/network.cpp

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "current.h"
1313
#include "model/configuration.h"
1414

15+
#define NETWORK_BUFFER_SIZE 2048
16+
#define NETWORK_TIMEOUT 1000 * 60
17+
#define NETWORK_DELAY 1222
18+
#define NETWORK_WIFI_ATTEMPTS 2
19+
#define NETWORK_STRATUM_ATTEMPTS 2
20+
#define MAX_PAYLOAD_SIZE 256
21+
#define MAX_PAYLOADS 10
22+
1523
WiFiClient client = WiFiClient();
1624
char TAG_NETWORK[8] = "Network";
1725
uint64_t id = 0;
@@ -21,12 +29,8 @@ uint32_t authorizeId = 0;
2129
uint8_t isAuthorized = 0;
2230
uint8_t isListening = 0;
2331
extern Configuration configuration;
24-
25-
#define NETWORK_BUFFER_SIZE 2048
26-
#define NETWORK_TIMEOUT 1000 * 60
27-
#define NETWORK_DELAY 1222
28-
#define NETWORK_WIFI_ATTEMPTS 2
29-
#define NETWORK_STRATUM_ATTEMPTS 2
32+
char payloads[MAX_PAYLOADS][MAX_PAYLOAD_SIZE]; // Array of payloads
33+
size_t payloads_count = 0;
3034

3135
/**
3236
* @brief Generates the next ID for the network.
@@ -367,25 +371,38 @@ short network_getJob()
367371
return 1;
368372
}
369373

374+
void enqueue(const char *payload) {
375+
if (payloads_count < MAX_PAYLOADS) {
376+
strncpy(payloads[payloads_count], payload, MAX_PAYLOAD_SIZE - 1);
377+
payloads_count++;
378+
l_debug(TAG_NETWORK, "Payload queued: %s", payload);
379+
} else {
380+
l_error(TAG_NETWORK, "Payload queue is full");
381+
}
382+
}
383+
370384
void network_send(const std::string &job_id, const std::string &extranonce2, const std::string &ntime, const uint32_t &nonce)
371385
{
372-
char payload[256];
386+
char payload[MAX_PAYLOAD_SIZE];
373387
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);
374-
request(payload);
375388
#if defined(ESP8266)
376389
network_listen();
390+
request(payload);
391+
#else
392+
enqueue(payload);
377393
#endif
378394
}
379395

380396
void network_listen()
381397
{
382-
#if defined(ESP8266)
398+
#if defined(ESP8266)
383399
if (isListening == 1)
384400
{
385401
return;
386402
}
387403
isListening = 1;
388-
#endif
404+
#endif
405+
389406
int len = 0;
390407
isConnected();
391408
do
@@ -398,18 +415,45 @@ void network_listen()
398415
response(data);
399416
}
400417
} while (len > 0);
401-
#if defined(ESP8266)
418+
419+
#if defined(ESP8266)
402420
isListening = 0;
403-
#endif
421+
#endif
422+
}
423+
424+
void network_submit(const char *payload) {
425+
if (isConnected() == -1) {
426+
return; // Handle connection failure
427+
}
428+
429+
request(payload);
430+
431+
// Remove the submitted payload from the array
432+
for (size_t i = 0; i < payloads_count; ++i) {
433+
if (strcmp(payloads[i], payload) == 0) {
434+
// Shift remaining payloads
435+
for (size_t j = i; j < payloads_count - 1; ++j) {
436+
strcpy(payloads[j], payloads[j+1]);
437+
}
438+
payloads_count--;
439+
break;
440+
}
441+
}
442+
}
443+
444+
void network_submit_all() {
445+
for (size_t i = 0; i < payloads_count; ++i) {
446+
network_submit(payloads[i]);
447+
}
404448
}
405449

406450
#if defined(ESP32)
407-
#define NETWORK_TASK_TIMEOUT 600
451+
#define NETWORK_TASK_TIMEOUT 100
408452
void networkTaskFunction(void *pvParameters)
409453
{
410454
while (1)
411455
{
412-
network_listen();
456+
network_submit_all();
413457
network_listen();
414458
vTaskDelay(NETWORK_TASK_TIMEOUT / portTICK_PERIOD_MS);
415459
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"current": "0.0.9",
2+
"current": "0.0.10",
33
"link": "https://github.com/matteocrippa/leafminer/releases/download/v{{version}}/firmware_{{device}}.bin",
44
"devices": [
55
"esp8266",

0 commit comments

Comments
 (0)