Skip to content

Commit

Permalink
re port
Browse files Browse the repository at this point in the history
  • Loading branch information
pumitahou committed Jan 23, 2025
1 parent 49200ef commit 8a8cd93
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 802 deletions.
162 changes: 123 additions & 39 deletions DuinoCoinEthernetMiner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ the proyect is arduino miner to dunicoin made with revox
thanks you Joybed to fix the hashrate problem
*/

//#define __DEBUG__ //enables or disables serial console, disabling it may result in higher hashrates, uncomment if you want serial enabled
#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. */
Expand All @@ -21,38 +22,40 @@ typedef uint32_t uintDiff;
#endif
// Arduino identifier library - https://github.com/ricaun
#include "uniqueID.h"
#include "sha1.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};
byte ip[] = {192,168,1,177};

// the pool ip final
byte pool[] = {162,55,103,174};
unsigned short port = 6000;
// http://server.duinocoin.com/getPool
byte pool[] = {0,0,0,0};
unsigned short port = 0;

//miner global variables
String Username = "Puma"; //put your username here
const char* RIG_IDENTIFIER = "AVR ethernet"; //put your rig identifier here
const char* RIG_IDENTIFIER = "None"; //put your rig identifier here
String key = "None";

String lastblockhash = "";
String newblockhash = "";

String DUCOID = "";

uintDiff difficulty = 0;
uintDiff ducos1result = 0;
const uint16_t job_maxsize = 104;

const uint16_t job_maxsize = 104;
uint8_t job[job_maxsize];
Sha1Wrapper Sha1_base;

//client variables SETTINGS
const char * miner_version = "PumaFron miner 3.0";
String VER = "3.0";
unsigned short SOC_TIMEOUT = 15;
unsigned short REPORT_TIME = 120;
unsigned short AVR_TIMEPUT = 7;
String start_diff = "AVR";

String SEPARATOR = ",";
String BLOCK = "";

Expand All @@ -62,20 +65,24 @@ String client_buffer = "";
char END_TOKEN = '\n';
char SEP_TOKEN = ',';

EthernetClient client;
EthernetClient client;

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
DUCOID = get_DUCOID();
//set connection
Ethernet.begin(mac,ip);
Ethernet.begin(mac);

#ifdef __DEBUG__
Serial.begin(9600);
Serial.println("starting miner...");
Serial.print(DUCOID);
#endif
resolvePool();

waitForClientData();
String server_version = getValue(client_buffer, SEP_TOKEN, 1);

#ifdef __DEBUG__
Serial.println(server_version);
#endif
Expand All @@ -97,6 +104,7 @@ void loop() {
String expected_hash = getValue(client_buffer, SEP_TOKEN, 1);
unsigned int difficulty = getValue(client_buffer, SEP_TOKEN, 2).toInt();
#ifdef __DEBUG__

Serial.println("Job received: "
+ last_block_hash
+ " "
Expand All @@ -109,7 +117,7 @@ void loop() {
//DEBUG
Serial.println("starting hashing");
//----
ducos1result = ducos1a(last_block_hash, expected_hash, difficulty);
ducos1result = ducos1a(last_block_hash.c_str(), expected_hash.c_str(), difficulty);
last_block_hash = "";
expected_hash = "";
difficulty = 0;
Expand All @@ -120,12 +128,14 @@ void loop() {
uint32_t elapsedTime = micros() - startTime;
float elapsed_time_s = elapsedTime / 1000000.0f;
float hashrate = ducos1result / elapsed_time_s;

#ifdef __DEBUG__
Serial.print("hashrate: ");
Serial.print(hashrate);
Serial.print(" speed: ");
Serial.println(elapsed_time_s);
#endif

client.print(String(ducos1result)
+ ","
+ String(hashrate)
Expand All @@ -135,10 +145,14 @@ void loop() {
+ ","
+ String(DUCOID));



waitForClientData();

#ifdef __DEBUG__
Serial.println(client_buffer);
#endif

#if defined(ARDUINO_ARCH_AVR)
PORTB = PORTB | B00100000;
#else
Expand All @@ -149,8 +163,6 @@ void loop() {
}
}

//this function is to test pool ping command pls remove to final compilation
//the function get motd to pool
void testPing(){
if(client.connect(pool,port)){
#ifdef __DEBUG__
Expand All @@ -166,11 +178,14 @@ void testPing(){
}

void JOB_REQUEST() {
String petition = "JOB," + String(Username) + "," + String("AVR");
String petition = "JOB"
+ SEPARATOR + Username
+ SEPARATOR + "AVR"
+ SEPARATOR + key;
client.print(petition);
#ifdef __DEBUG__
Serial.println(petition);
#endif
#endif
}

String get_DUCOID() {
Expand All @@ -183,34 +198,48 @@ String get_DUCOID() {
return ID;
}

void lowercase_hex_to_bytes(char const * 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;

x = hexDigest[i + 1];
b = x >> 6;

rawDigest[j] = (r << 4) | (((x & 0xf) | (b << 3)) + b);
}
}

// DUCO-S1A hasher
uintDiff ducos1a(String lastblockhash, String newblockhash, uintDiff difficulty) {
newblockhash.toUpperCase();
const char *c = newblockhash.c_str();
uint8_t final_len = newblockhash.length() >> 1;
for (uint8_t i = 0, j = 0; j < final_len; i += 2, j++)
job[j] = ((((c[i] & 0x1F) + 9) % 25) << 4) + ((c[i + 1] & 0x1F) + 9) % 25;

// Difficulty loop
uintDiff ducos1a(char const * prevBlockHash, char const * 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
Sha1_base.init();
Sha1_base.print(lastblockhash);
for (uintDiff ducos1res = 0; ducos1res < difficulty * 100 + 1; ducos1res++) {
//Sha1.init();
//Sha1.print(lastblockhash + String(ducos1res));
Sha1 = Sha1_base;
Sha1.print(String(ducos1res));
// Get SHA1 result
uint8_t *hash_bytes = Sha1.result();
if (memcmp(hash_bytes, job, SHA1_HASH_LEN * sizeof(char)) == 0) {
// If expected hash is equal to the found hash, return the result
return ducos1res;

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(char const * 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);

uint8_t const * hash_bytes = duco_hash_try_nonce(&hash, nonceStr);
if (memcmp(hash_bytes, target, SHA1_HASH_LEN) == 0) {
return nonce;
}
}
return 0;

return 0;
}

//sorry for copy function but i need the function
Expand Down Expand Up @@ -241,3 +270,58 @@ void waitForClientData(void) {
}
}
}


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");

while (client.connected() && !client.available()) delay(1);

// Skip HTTP headers
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") break; // End of headers
}

// Read JSON body
String jsonResponse = client.readString();
client.stop();

// Manual JSON parsing
int ipStart = jsonResponse.indexOf("\"ip\":\"") + 6;
int ipEnd = jsonResponse.indexOf('"', ipStart);
String ipStr = jsonResponse.substring(ipStart, ipEnd);

int portStart = jsonResponse.indexOf("\"port\":") + 7;
int portEnd = jsonResponse.indexOf(',', portStart);
port = jsonResponse.substring(portStart, portEnd).toInt();

// Parse IP without sscanf
int dot1 = ipStr.indexOf('.');
int dot2 = ipStr.indexOf('.', dot1 + 1);
int dot3 = ipStr.indexOf('.', dot2 + 1);

pool[0] = ipStr.substring(0, dot1).toInt();
pool[1] = ipStr.substring(dot1 + 1, dot2).toInt();
pool[2] = ipStr.substring(dot2 + 1, dot3).toInt();
pool[3] = ipStr.substring(dot3 + 1).toInt();

#ifdef __DEBUG__
Serial.print("Pool: ");
Serial.print(pool[0]); Serial.print(".");
Serial.print(pool[1]); Serial.print(".");
Serial.print(pool[2]); Serial.print(".");
Serial.print(pool[3]);
Serial.print(" Port: "); Serial.println(port);
#endif
} else {
#ifdef __DEBUG__
Serial.println("Connection failed");
#endif
}
}
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ native lang: Hola este proyecto es uno de los mas complicados de arduino que e e

for mining you need put manual ip and port pool in the code

// the pool ip final
byte pool[] = {162,55,103,174};
unsigned short port = 6000;

and change name to this Variable Username to start Mining

String Username = "Puma";
Expand Down
24 changes: 0 additions & 24 deletions backend.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions config.h

This file was deleted.

Loading

0 comments on commit 8a8cd93

Please sign in to comment.