From 5cdffe9269be531b371f8a85581c235c8672374e Mon Sep 17 00:00:00 2001 From: Robert Piotrowski <50244265+revoxhere@users.noreply.github.com> Date: Sun, 28 Mar 2021 14:21:17 +0200 Subject: [PATCH] Update ESP32_Code.ino --- ESP32_Code/ESP32_Code.ino | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/ESP32_Code/ESP32_Code.ino b/ESP32_Code/ESP32_Code.ino index 06f25706..aba9b4ff 100644 --- a/ESP32_Code/ESP32_Code.ino +++ b/ESP32_Code/ESP32_Code.ino @@ -5,7 +5,7 @@ // | | | | | | | | '_ \ / _ \______| | / _ \| | '_ \ // | |__| | |_| | | | | | (_) | | |___| (_) | | | | | // |_____/ \__,_|_|_| |_|\___/ \_____\___/|_|_| |_| -// Code for ESP32 boards v2.4 +// Code for ESP32 boards v2.3 // © Duino-Coin Community 2019-2021 // Distributed under MIT License ////////////////////////////////////////////////////////// @@ -36,10 +36,10 @@ const char * host = "51.15.127.80"; // Static server IP const int port = 2811; // Task1code -void Task1code( void * pvParameters ){ +void Task1code( void * pvParameters ) { unsigned int Shares1 = 0; // Share variable - Serial.println("\nCORE1 Connecting to Duino-Coin server..."); + Serial.println("\nCORE1 Connecting to Duino-Coin server..."); // Use WiFiClient class to create TCP connection WiFiClient client1; client1.setTimeout(2); @@ -68,8 +68,8 @@ void Task1code( void * pvParameters ){ size_t final_len = len / 2; unsigned char* job11 = (unsigned char*)malloc((final_len + 1) * sizeof(unsigned char)); for (size_t i = 0, j = 0; j < final_len; i += 2, j++) - job11[j] = (c[i] % 32 + 9) % 25 * 16 + (c[i + 1] % 32 + 9) % 25; - + job11[j] = (c[i] % 32 + 9) % 25 * 16 + (c[i + 1] % 32 + 9) % 25; + byte shaResult1[20]; Serial.println("CORE1 Job received: " + String(hash1) + " " + String(job1) + " " + String(diff1)); @@ -82,35 +82,35 @@ void Task1code( void * pvParameters ){ unsigned int payloadLenght1 = hash11.length(); esp_sha(SHA1, payload1, payloadLenght1, shaResult1); - + if (memcmp(shaResult1, job11, sizeof(shaResult1)) == 0) { // If result is found unsigned long EndTime1 = micros(); // End time measurement unsigned long ElapsedTime1 = EndTime1 - StartTime1; // Calculate elapsed time float ElapsedTimeMiliSeconds1 = ElapsedTime1 / 1000; // Convert to miliseconds float ElapsedTimeSeconds1 = ElapsedTimeMiliSeconds1 / 1000; // Convert to seconds float HashRate1 = iJob1 / ElapsedTimeSeconds1; // Calculate hashrate - client1.print(String(iJob1) + "," + String(HashRate1) + ",ESP32 CORE1 Miner v2.4," + String(rigname)); // Send result to server + client1.print(String(iJob1) + "," + String(HashRate1) + ",ESP32 CORE1 Miner v2.3," + String(rigname)); // Send result to server String feedback1 = client1.readStringUntil('\n'); // Receive feedback Shares1++; Serial.println("CORE1 " + String(feedback1) + " share #" + String(Shares1) + " (" + String(iJob1) + ")" + " Hashrate: " + String(HashRate1)); if (HashRate1 < 4000) { Serial.println("CORE1 Low hashrate. Restarting core 1"); client1.stop(); - xTaskCreatePinnedToCore(Task1code,"Task1",10000,NULL,1,&Task1,0); + xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, &Task1, 0); vTaskDelete( NULL ); } break; // Stop and ask for more work } - } + } } Serial.println("CORE1 Not connected. Restarting core 1"); client1.stop(); - xTaskCreatePinnedToCore(Task1code,"Task1",10000,NULL,1,&Task1,0); + xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, &Task1, 0); vTaskDelete( NULL ); } //Task2code -void Task2code( void * pvParameters ){ +void Task2code( void * pvParameters ) { unsigned int Shares = 0; // Share variable Serial.println("\nCORE2 Connecting to Duino-Coin server..."); @@ -127,7 +127,7 @@ void Task2code( void * pvParameters ){ digitalWrite(LED_BUILTIN, HIGH); // Turn off built-in led delay(50); digitalWrite(LED_BUILTIN, LOW); // Turn on built-in led - + while (client.connected()) { Serial.println("CORE2 Asking for a new job for user: " + String(ducouser)); client.print("JOB," + String(ducouser) + ",ESP32"); // Ask for new job @@ -142,10 +142,10 @@ void Task2code( void * pvParameters ){ size_t final_len = len / 2; unsigned char* job1 = (unsigned char*)malloc((final_len + 1) * sizeof(unsigned char)); for (size_t i = 0, j = 0; j < final_len; i += 2, j++) - job1[j] = (c[i] % 32 + 9) % 25 * 16 + (c[i + 1] % 32 + 9) % 25; - + job1[j] = (c[i] % 32 + 9) % 25 * 16 + (c[i + 1] % 32 + 9) % 25; + byte shaResult[20]; - + Serial.println("CORE2 Job received: " + String(hash) + " " + String(job) + " " + String(diff)); unsigned long StartTime = micros(); // Start time measurement @@ -163,30 +163,30 @@ void Task2code( void * pvParameters ){ mbedtls_md_update(&ctx, (const unsigned char *) payload, payloadLength); mbedtls_md_finish(&ctx, shaResult); mbedtls_md_free(&ctx); - + if (memcmp(shaResult, job1, sizeof(shaResult)) == 0) { // If result is found unsigned long EndTime = micros(); // End time measurement unsigned long ElapsedTime = EndTime - StartTime; // Calculate elapsed time float ElapsedTimeMiliSeconds = ElapsedTime / 1000; // Convert to miliseconds float ElapsedTimeSeconds = ElapsedTimeMiliSeconds / 1000; // Convert to seconds float HashRate = iJob / ElapsedTimeSeconds; // Calculate hashrate - client.print(String(iJob) + "," + String(HashRate) + ",ESP32 CORE2 Miner v2.4," + String(rigname)); // Send result to server + client.print(String(iJob) + "," + String(HashRate) + ",ESP32 CORE2 Miner v2.3," + String(rigname)); // Send result to server String feedback = client.readStringUntil('\n'); // Receive feedback Shares++; Serial.println("CORE2 " + String(feedback) + " share #" + String(Shares) + " (" + String(iJob) + ")" + " Hashrate: " + String(HashRate)); if (HashRate < 4000) { Serial.println("CORE2 Low hashrate. Restarting core 2"); client.stop(); - xTaskCreatePinnedToCore(Task2code,"Task2",10000,NULL,2,&Task2,1); + xTaskCreatePinnedToCore(Task2code, "Task2", 10000, NULL, 2, &Task2, 1); vTaskDelete( NULL ); } break; // Stop and ask for more work } - } + } } Serial.println("CORE2 Not connected. Restarting core 2"); client.stop(); - xTaskCreatePinnedToCore(Task2code,"Task2",10000,NULL,2,&Task2,1); + xTaskCreatePinnedToCore(Task2code, "Task2", 10000, NULL, 2, &Task2, 1); vTaskDelete( NULL ); } @@ -194,7 +194,7 @@ void setup() { disableCore0WDT(); disableCore1WDT(); Serial.begin(115200); // Start serial connection - Serial.println("\n\nDuino-Coin ESP32 Miner v2.4"); + Serial.println("\n\nDuino-Coin ESP32 Miner v2.3"); Serial.println("Connecting to: " + String(ssid)); WiFi.mode(WIFI_STA); // Setup ESP in client mode WiFi.begin(ssid, password); // Connect to wifi @@ -205,9 +205,9 @@ void setup() { } Serial.println("\nConnected to WiFi!"); Serial.println("Local IP address: " + WiFi.localIP().toString()); - xTaskCreatePinnedToCore(Task1code,"Task1",10000,NULL,1,&Task1,0); //create a task with priority 1 and executed on core 0 - delay(250); - xTaskCreatePinnedToCore(Task2code,"Task2",10000,NULL,2,&Task2,1); //create a task with priority 2 and executed on core 1 + xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, &Task1, 0); //create a task with priority 1 and executed on core 0 + delay(250); + xTaskCreatePinnedToCore(Task2code, "Task2", 10000, NULL, 2, &Task2, 1); //create a task with priority 2 and executed on core 1 delay(250); }