Skip to content

Commit

Permalink
Feature/v0.0.10 (#19)
Browse files Browse the repository at this point in the history
* minor changes

* bump version

* fix readme

---------

Co-authored-by: Matteo Crippa <[email protected]>
  • Loading branch information
matteocrippa and Matteo Crippa authored Mar 11, 2024
1 parent 665601c commit 934299e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# v0.0.9
# v0.0.10

- Improved network handling

- Fix build script for binaries
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ _Legend_

- Download the binary file for your board

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

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

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.9"
#define _VERSION "0.0.10"
#define DIFFICULTY 1e-4

// Mining
Expand Down
72 changes: 58 additions & 14 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
#include "current.h"
#include "model/configuration.h"

#define NETWORK_BUFFER_SIZE 2048
#define NETWORK_TIMEOUT 1000 * 60
#define NETWORK_DELAY 1222
#define NETWORK_WIFI_ATTEMPTS 2
#define NETWORK_STRATUM_ATTEMPTS 2
#define MAX_PAYLOAD_SIZE 256
#define MAX_PAYLOADS 10

WiFiClient client = WiFiClient();
char TAG_NETWORK[8] = "Network";
uint64_t id = 0;
Expand All @@ -21,12 +29,8 @@ uint32_t authorizeId = 0;
uint8_t isAuthorized = 0;
uint8_t isListening = 0;
extern Configuration configuration;

#define NETWORK_BUFFER_SIZE 2048
#define NETWORK_TIMEOUT 1000 * 60
#define NETWORK_DELAY 1222
#define NETWORK_WIFI_ATTEMPTS 2
#define NETWORK_STRATUM_ATTEMPTS 2
char payloads[MAX_PAYLOADS][MAX_PAYLOAD_SIZE]; // Array of payloads
size_t payloads_count = 0;

/**
* @brief Generates the next ID for the network.
Expand Down Expand Up @@ -367,25 +371,38 @@ short network_getJob()
return 1;
}

void enqueue(const char *payload) {
if (payloads_count < MAX_PAYLOADS) {
strncpy(payloads[payloads_count], payload, MAX_PAYLOAD_SIZE - 1);
payloads_count++;
l_debug(TAG_NETWORK, "Payload queued: %s", payload);
} else {
l_error(TAG_NETWORK, "Payload queue is full");
}
}

void network_send(const std::string &job_id, const std::string &extranonce2, const std::string &ntime, const uint32_t &nonce)
{
char payload[256];
char payload[MAX_PAYLOAD_SIZE];
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();
request(payload);
#else
enqueue(payload);
#endif
}

void network_listen()
{
#if defined(ESP8266)
#if defined(ESP8266)
if (isListening == 1)
{
return;
}
isListening = 1;
#endif
#endif

int len = 0;
isConnected();
do
Expand All @@ -398,18 +415,45 @@ void network_listen()
response(data);
}
} while (len > 0);
#if defined(ESP8266)

#if defined(ESP8266)
isListening = 0;
#endif
#endif
}

void network_submit(const char *payload) {
if (isConnected() == -1) {
return; // Handle connection failure
}

request(payload);

// Remove the submitted payload from the array
for (size_t i = 0; i < payloads_count; ++i) {
if (strcmp(payloads[i], payload) == 0) {
// Shift remaining payloads
for (size_t j = i; j < payloads_count - 1; ++j) {
strcpy(payloads[j], payloads[j+1]);
}
payloads_count--;
break;
}
}
}

void network_submit_all() {
for (size_t i = 0; i < payloads_count; ++i) {
network_submit(payloads[i]);
}
}

#if defined(ESP32)
#define NETWORK_TASK_TIMEOUT 600
#define NETWORK_TASK_TIMEOUT 100
void networkTaskFunction(void *pvParameters)
{
while (1)
{
network_listen();
network_submit_all();
network_listen();
vTaskDelay(NETWORK_TASK_TIMEOUT / portTICK_PERIOD_MS);
}
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.9",
"current": "0.0.10",
"link": "https://github.com/matteocrippa/leafminer/releases/download/v{{version}}/firmware_{{device}}.bin",
"devices": [
"esp8266",
Expand Down

0 comments on commit 934299e

Please sign in to comment.