Esp32 Wroom 32D Mining Pool

gabrielresk
Posts: 1
Joined: Tue Apr 16, 2024 1:35 pm

Esp32 Wroom 32D Mining Pool

Postby gabrielresk » Tue Apr 16, 2024 1:58 pm

Hello, I have bought 10 units of the Esp32 Wroom 32D, and I have started with a small project, 0% profitable, but 100% beautiful and fun.

Problem: I have been building the script using ChatGPT, at the beginning it works perfectly, it compiles well in the Arduino 2.0 IDE, it uploads the information to the esp32, it starts the code, it connects to my Wi-Fi network, It pings Google to check if the connection is stable and if there is an internet connection, but when the time comes to connect to any pool, be it Binance, Heromiers, or Unmineable, the problem is the same.

Script:
  1. #include <WiFi.h>
  2. #include <WiFiClient.h>
  3. #include "C:\\Users\\Admin\\Documents\\Arduino\\libraries\\ESPping\\src\\ESPPing.h"
  4.  
  5. // WiFi credentials
  6. const char* WIFI_SSID = "XXX"; // I have put the Xs to hide my data.
  7. const char* WIFI_PASSWORD = "XXXXXXXXX"; // I have put the Xs to hide my data.
  8.  
  9. // Mining pool information
  10. const char* POOL_ADDRESS = "stratum+tcp://rvn.poolbinance.com";
  11. const uint16_t PORT = 9000;
  12.  
  13. // Wallet address
  14. const char* WALLET_ADDRESS = "RAcERdEbNAMZGLCegjEi1wJyqgpiEvjbs8";
  15.  
  16. WiFiClient client;
  17.  
  18. // LED pin
  19. const int LED_PIN = 2;
  20.  
  21. // Connection timeout in milliseconds
  22. const unsigned long CONNECTION_TIMEOUT = 10000;
  23.  
  24. // Task start time
  25. unsigned long taskStartTime = 0;
  26.  
  27. void setup() {
  28.   Serial.begin(115200);
  29.   pinMode(LED_PIN, OUTPUT);
  30.   Serial.println("Starting...");
  31.   connectToWiFi();
  32. }
  33.  
  34. void connectToWiFi() {
  35.   Serial.print("Connecting to WiFi: ");
  36.   WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  37.   unsigned long startTime = millis();
  38.   while (WiFi.status() != WL_CONNECTED && millis() - startTime < CONNECTION_TIMEOUT) {
  39.     Serial.print(".");
  40.     delay(1000);
  41.   }
  42.   if (WiFi.status() == WL_CONNECTED) {
  43.     Serial.println("\nWiFi connected.");
  44.     if (checkInternetConnection()) {
  45.       Serial.println("Internet connection established.");
  46.       if (checkInternetConnection()) {
  47.         Serial.println("Internet connection established after first verification.");
  48.         mineRavencoin();
  49.       } else {
  50.         Serial.println("Failed to establish internet connection after first verification.");
  51.       }
  52.     } else {
  53.       Serial.println("Failed to establish internet connection.");
  54.     }
  55.   } else {
  56.     Serial.println("Failed to connect to WiFi.");
  57.   }
  58. }
  59.  
  60. bool checkInternetConnection() {
  61.   Serial.print("Pinging google.com... ");
  62.   digitalWrite(LED_PIN, HIGH);
  63.   IPAddress googleDNS(8, 8, 8, 8);
  64.   bool success = Ping.ping(googleDNS);
  65.   digitalWrite(LED_PIN, LOW);
  66.   return success;
  67. }
  68.  
  69. void mineRavencoin() {
  70.   Serial.println("Connecting to mining pool...");
  71.   unsigned int connectionAttempts = 0;
  72.   while (connectionAttempts < 3) {
  73.     Serial.print("Connection attempt #");
  74.     Serial.println(connectionAttempts + 1);
  75.     unsigned long startTime = millis();
  76.     while (!client.connect(POOL_ADDRESS, PORT) && millis() - startTime < CONNECTION_TIMEOUT) {
  77.       Serial.println("Connecting...");
  78.       delay(1000);
  79.       blinkLED();
  80.     }
  81.     if (client.connected()) {
  82.       Serial.println("Connected to mining pool.");
  83.       client.println("mining.subscribe " + String(WALLET_ADDRESS));
  84.       break;
  85.     } else {
  86.       Serial.println("Connection failed.");
  87.       Serial.println("Server response:");
  88.       while (client.available()) {
  89.         String line = client.readStringUntil('\n');
  90.         Serial.println(line);
  91.       }
  92.       connectionAttempts++;
  93.     }
  94.   }
  95.   if (client.connected()) {
  96.     digitalWrite(LED_PIN, HIGH);
  97.     taskStartTime = millis();
  98.   } else {
  99.     Serial.println("Mining has ended.");
  100.   }
  101. }
  102.  
  103. void blinkLED() {
  104.   digitalWrite(LED_PIN, HIGH);
  105.   delay(100);
  106.   digitalWrite(LED_PIN, LOW);
  107.   delay(100);
  108. }
  109.  
  110. void loop() {
  111.   if (client.connected()) {
  112.     if (millis() - taskStartTime >= 1000) {
  113.       digitalWrite(LED_PIN, !digitalRead(LED_PIN));
  114.       taskStartTime = millis();
  115.     }
  116.     // Adjust the blink rate based on the mining speed
  117.     // Code to adjust blink rate based on mining speed
  118.   } else {
  119.     digitalWrite(LED_PIN, LOW);
  120.   }
  121.   // Add other tasks in the loop if necessary
  122. }
  123.  
Error:
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Connection failure
Server response:
Connection attempt #3
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Trying to connect...
Connection failure
Server response:
Mining has ended
I have already checked that the pool data is correct, I have checked that my WiFi is working correctly, The ESP32 firmware is updated and compatible with the version of the Arduino IDE and the libraries that I am using.

Can someone help me with this? I promise to send a photo when the MiniRig is lighting up more than a Christmas tree next to my PC xD.

Thank you and I hope for a prompt response, I have used Google Translator, my native language is Spanish.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Esp32 Wroom 32D Mining Pool

Postby lbernstone » Wed Apr 17, 2024 6:45 am

WiFiClient doesn't know anything about protocols beyond TCP. It establishes a bare connection to the server listening on a port. Cut off the stratum+tcp:// from your host and it will make the connection. It certainly is not going to (and shouldn't in this highly insecure way) be able to transact with a wallet service unless you program that protocol. You are likely going to need to use WiFiClientSecure (now known as NetworkClientSecure) to establish an encrypted TLS session.

Who is online

Users browsing this forum: Baidu [Spider] and 50 guests