Arduino megacom sheld eth #1857
adrianoms2004
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm providing a code that I would like to use on the Arduino Mega with sheld eth, but it shows an error of "Server response: BAD,Incorrect result", maybe someone can help and make the correction
/*
HELLO GUYS THIS CODE is auto miner, made with pumafron afk, the code mine only using 100% arduino and ethernet shield
thanks you LDarki for help me to fix connection error
the project is arduino miner to duinocoin made with revox
thanks you Joybed to fix the hashrate problem
Updated by Deepseek-V3 to include MINER_KEY and improve stability
*/
#define DEBUG // Enables or disables serial console, disabling it may result in higher hashrates, uncomment if you want serial enabled
#pragma GCC optimize ("-Ofast")
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
/* For 8-bit microcontrollers we should use 16 bit variables since the
difficulty is low, for all the other cases should be 32 bits. */
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
typedef uint16_t uintDiff;
#else
typedef uint32_t uintDiff;
#endif
// Arduino identifier library - https://github.com/ricaun
#include "uniqueID.h"
#include "duco_hash.h"
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// The pool IP will be resolved dynamically
byte pool[] = {0, 0, 0, 0};
unsigned short port = 0;
// Miner global variables
String Username = "user name"; // Put your username here
const char* RIG_IDENTIFIER = "AVR ethernet"; // Put your rig identifier here
const char* MINER_KEY = "key"; // Add your miner key here
String lastblockhash = "";
String newblockhash = "";
String DUCOID = "";
uintDiff difficulty = 0;
uintDiff ducos1result = 0;
const uint16_t job_maxsize = 104;
uint8_t job[job_maxsize];
// Client variables SETTINGS
const char * miner_version = "PumaFron miner 3.0";
String VER = "3.0";
String start_diff = "AVR";
String SEPARATOR = ",";
String BLOCK = " ‖ ";
bool receiving_data = false;
String BUFFER_BITS = "";
String client_buffer = "";
char END_TOKEN = '\n';
char SEP_TOKEN = ',';
EthernetClient client;
// Function prototypes
uintDiff ducos1a(const char* prevBlockHash, const char* targetBlockHash, uintDiff difficulty);
String getValue(String data, char separator, int index);
void waitForClientData();
void resolvePool();
void JOB_REQUEST();
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
DUCOID = get_DUCOID();
// Set connection
Ethernet.begin(mac);
#ifdef DEBUG
Serial.begin(9600);
Serial.println("Starting miner...");
Serial.print("DUCOID: ");
Serial.println(DUCOID);
#endif
resolvePool();
waitForClientData();
String server_version = getValue(client_buffer, SEP_TOKEN, 1);
#ifdef DEBUG
Serial.print("Server version: ");
Serial.println(server_version);
#endif
}
void loop() {
if (client.connect(pool, port)) {
while (client.connected()) {
memset(job, 0, job_maxsize);
} else {
#ifdef DEBUG
Serial.println("Failed to connect to the pool.");
#endif
}
}
void JOB_REQUEST() {
String petition = "JOB"
+ SEPARATOR + Username
+ SEPARATOR + start_diff
+ SEPARATOR + MINER_KEY;
client.print(petition);
#ifdef DEBUG
Serial.println("Job request: " + petition);
#endif
}
String get_DUCOID() {
String ID = "DUCOID";
char buff[4];
for (size_t i = 0; i < 8; i++) {
sprintf(buff, "%02X", (uint8_t)UniqueID8[i]);
ID += buff;
}
return ID;
}
void waitForClientData() {
client_buffer = "";
while (client.connected()) {
if (client.available()) {
client_buffer = client.readStringUntil(END_TOKEN);
if (client_buffer.length() == 1 && client_buffer[0] == END_TOKEN)
client_buffer = "???\n"; // NOTE: Should never happen
break;
}
}
}
void resolvePool() {
const char* server = "server.duinocoin.com";
if (client.connect(server, 80)) {
client.print("GET /getPool HTTP/1.1\r\n"
"Host: server.duinocoin.com\r\n"
"Connection: close\r\n\r\n");
} else {
#ifdef DEBUG
Serial.println("Connection failed");
#endif
}
}
// Function to parse a string by a separator
String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = {0, -1};
int max_index = data.length() - 1;
for (int i = 0; i <= max_index && found <= index; i++) {
if (data.charAt(i) == separator || i == max_index) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == max_index) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
// DUCO-S1A hasher
uintDiff ducos1a(const char* prevBlockHash, const char* targetBlockHash, uintDiff difficulty) {
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// If the difficulty is too high for AVR architecture then return 0
if (difficulty > 655) return 0;
#endif
uint8_t target[SHA1_HASH_LEN];
lowercase_hex_to_bytes(targetBlockHash, target);
uintDiff const maxNonce = difficulty * 100 + 1;
return ducos1a_mine(prevBlockHash, target, maxNonce);
}
uintDiff ducos1a_mine(const char* prevBlockHash, uint8_t const* target, uintDiff maxNonce) {
static duco_hash_state_t hash;
duco_hash_init(&hash, prevBlockHash);
char nonceStr[10 + 1];
for (uintDiff nonce = 0; nonce < maxNonce; nonce++) {
ultoa(nonce, nonceStr, 10);
}
return 0;
}
void lowercase_hex_to_bytes(const char* hexDigest, uint8_t* rawDigest) {
for (uint8_t i = 0, j = 0; j < SHA1_HASH_LEN; i += 2, j += 1) {
uint8_t x = hexDigest[i];
uint8_t b = x >> 6;
uint8_t r = ((x & 0xf) | (b << 3)) + b;
}
}
Beta Was this translation helpful? Give feedback.
All reactions