چند ماه پیش آموزشی درباره استخراج رمز ارزی به نام DUINO Coin منتشر کردیم، در آموزش قبل عملیات استخراج را به کمک برد های آردوینو انجان دادیم، در این آموزش قصد داریم همین فرآیند را به کمک برد های ESP32 انحام دهیم، همچنین به کمک یک نمایشگر OLED مقادیر موجودی والت، تعداد ماینر ها و مقادیر مختلف را همزمان با ماین کردن نمایش دهیم. در ادامه استخراج ارز دیجیتال DuinoCoin آموزش با مرجع تخصصی آردوینو به زبان فارسی، دیجی اسپارک همراه باشید.
دوینوکوین DuinoCoin ᕲ
رمز ارز DuinoCoin تنها سکه ای که می تواند با رایانه ها، Raspberry Pi ،Arduinos، برد های ESP و بسیاری میکروکنترلر های دیگر استخراج میشود. توسط تعداد زیادی سیستم عامل پشتیبانی می شود. همچنین دارای یک جامعه دوستانه و در حال رشد است و قابلیت استفاده آسان و تبادل دارد. این رمز امکان ماین شدن در سیستم های های مختلفی را دارد همچنین زبان های برنامه نویسی Python و C++ پشتیبانی میکند. دوینوکوین دارای والت و ماینر های نرمافزاری به خصوص است که توسط توسعه دهندگان آن منتشر شده، این رمز ارز از سال ۲۰۱۹ شروع به کار کرده. همچنین فرآیند انقال و دریافت در DUCO بسیار آسان است در دوینوکوین ابتدا جفت ارز رمزنگاری شده مورد نظر را انتخاب میکنیم، به عنوان مثال DUCO به BYND سپس فرم تبادل را پر میکنیم.
به زبان ساده، به معنای واقعی کلمه رمز ارز دیگری وجود ندارد که از آن پشتیبانی کند. بسیاری از مردم آردوینو دارند که فقط در حال انتظار برای روزهایی برای استفاده شدن هستند. با استفاده از این دستگاه های کوچک در دنیای رمزنگاری ایده جالبی است. که تیم DUCO میخواست چیزی جدید، ابتکاری و منحصر به فرد ایجاد کند و از نظر جامعه ای که جمع کرده، به نظر می رسد که استخراج دستگاه های فوق کم انرژی را امکان پذیر کرده است.
وسایل مورد نیاز
ثبت نام در شبکه Duino-Coin
اولین اقدامی که برای استخراج رمز ارز دوینو کوین Duino-Coin باید انجام دهید این است که حساب خود را در شبکه دوکو ثبت کنید. برای انجام این کار، می توانید برای ثبت نام در مرورگر خود از کیف پول GUI یا کیف پول CLI یا وب کیف پول استفاده کنید. همه چیز به ساده ترین شکل ممکن ساخته شده است، بنابراین در ثبت نام مشکلی نخواهید داشت. فقط کافی است هر یک از کیف پول ها را راه اندازی کنید، گزینه ثبت را انتخاب کنید و جای خالی آن را با اطلاعات معتبر پر کنید. پس از ثبت نام می توانید از کلیه نرم افزارهای مرتبط با Duino-Coin استفاده کنید. در تصاویر زیر نمونه های والت ذکر شده را مشاهده میکنید.
در آموزش “استخراج کریپتوکارنسی با آردوینو Arduino” جزئیات این بخش را مشاهده کنید.
اتصالات ماینر DuinoCoin
در پروژه استخراج ارز دیجیتال DuinoCoin از برد esp32 و نمایشگر OLED استفاده میکنیم، در ادامه به پین های مربوط به پروتکل I2C برای برقراری ارتباط بین نمایشگر OLED و برد ESP32 داریم. در برد ESP32 از پین های D21,D22 و در نمایشگر OLED از پین های SCL,SDA استفاده خواهیم کرد. همچنین به منظور تغذیه از پین های VIN یا ۵V در برد ESP32 استفاده خواهیم کرد.
کد های پروژه ماینر DuinoCoin
- در آموزش قبل که ماینینگ با استفاده از آردوینو انجام میشد، اتصال وایفای و ارتباط با سرور به کمک لپتاپ یا سیستم شما صورت میگرفت اما در این پروژه تنها با استفاده از برد ESP32 صورت میگیرد، در مرحله اول یوزرنیم و پسوورد شبکه وایفای مدنظر خود را وارد کنید سپس نوبت به یوزر اکانت دوینو کوین شما میرسد و در ادامه اگر از چندین برد به منظور استخراج استفاده میکنید به ترتیب یک شماره برای برد خود انتخاب کنید.
1 2 3 4 |
const char *wifi_ssid = "C1F3R"; const char *wifi_password = "314159265"; const char *username = "CiferTech"; const char *rig_identifier = "None"; |
- این مورد مربوط به ورژن تراشه ESP32 شما است در صورتی که پس آپلود کد دچار مشکل شدید خط اول را کامنت و خط دوم را از کامنت خارج کنید.
1 2 |
#include "hwcrypto/sha.h" //#include "sha/sha_parallel_engine.h" |
- در صورتی که نیازی به ارتباط سریال ندارید این خط را کامنت کنید، این ارتباط سریال وضعیت مربوطه را از تغییر با سریال مانیتور به شما اطلاع میدهد، معمولا غیر فعال کردن این مورد به سرعت پردازش شما کمک میکند.
1 |
#define ENABLE_SERIAL |
کد کامل پروژه استخراج ارز دیجیتال DuinoCoin با استفاده از ESP32 به همراه مانیتورینگ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
const char *wifi_ssid = "C1F3R"; const char *wifi_password = "314159265"; const char *username = "CiferTech"; const char *rig_identifier = "None"; #define LED_BUILTIN 2 #define BLINK_SHARE_FOUND 1 #define BLINK_SETUP_COMPLETE 2 #define BLINK_CLIENT_CONNECT 3 #define BLINK_RESET_DEVICE 5 #define WDT_TIMEOUT 60 #include "hwcrypto/sha.h" //#include "sha/sha_parallel_engine.h" /* If you would like to use mqtt monitoring uncomment the ENABLE_MQTT defition line(#define ENABLE_MQTT). NOTE: enabling MQTT could slightly decrease hashrate */ // #define ENABLE_MQTT // Change this to specify MQTT server (ip only no prefixes) const char *mqtt_server = ""; // Port mqtt server is listening at (default: 1883) const int mqtt_port = 1883; /* If you're using the ESP32-CAM board or other board that doesn't support OTA (Over-The-Air programming) comment the ENABLE_OTA definition line (#define ENABLE_OTA) NOTE: enabling OTA support could decrease hashrate (up to 40%) */ // #define ENABLE_OTA /* If you don't want to use the Serial interface comment the ENABLE_SERIAL definition line (#define ENABLE_SERIAL)*/ #define ENABLE_SERIAL /****************** END OF MINER CONFIGURATION SECTION ******************/ #ifndef ENABLE_SERIAL #define Serial DummySerial static class { public: void begin(...) {} void print(...) {} void println(...) {} void printf(...) {} } Serial; #endif #ifndef ENABLE_MQTT #define PubSubClient DummyPubSubClient class PubSubClient{ public: PubSubClient(Client& client) {} bool connect(...) { return false; } bool connected(...) { return true; } void loop(...) {} void publish(...) {} void subscribe(...) {} void setServer(...) {} }; #endif // Data Structures typedef struct TaskData { TaskHandle_t handler; byte taskId; float hashrate; unsigned long shares; unsigned int difficulty; } TaskData_t; // Include required libraries #define ARDUINOJSON_USE_DOUBLE 1 #include <ArduinoJson.h> #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 32 #include <ArduinoJson.h> #include <ESPmDNS.h> #include <HTTPClient.h> #include <WiFi.h> #include <WiFiUdp.h> #include <esp_task_wdt.h> //Include WDT libary #ifdef ENABLE_OTA #include <ArduinoOTA.h> #endif #ifdef ENABLE_MQTT #include <PubSubClient.h> #endif // Global Definitions #define NUMBEROFCORES 2 #define MSGDELIMITER ',' #define MSGNEWLINE '\n' #define OLED_RESET 4 #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Handles for additional threads TaskHandle_t WiFirec; TaskData_t TaskThreadData[NUMBEROFCORES]; TaskHandle_t MqttPublishHandle; SemaphoreHandle_t xMutex; // Internal Variables uint32_t lastDrawTime; uint32_t deauths = 0; int start; int wait = 0; int miners = 0; float oldb = 0.0; float userbalance; float balance; float ducomadesincesartdaily = 0.0; float daily = 0; String ducosmem; String price; String serverName = "https://server.duinocoin.com/users/"; String serverPrice = "https://server.duinocoin.com/api.json"; const char* root_ca= \ "-----BEGIN CERTIFICATE-----\n" \ "MIIFLTCCBBWgAwIBAgISBLrlR4aCBlmofGjUwxvNkJ9IMA0GCSqGSIb3DQEBCwUA\n" \ "MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD\n" \ "EwJSMzAeFw0yMTA0MjAxMjAwMThaFw0yMTA3MTkxMjAwMThaMB8xHTAbBgNVBAMT\n" \ "FHNlcnZlci5kdWlub2NvaW4uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" \ "CgKCAQEAv7SZV8V8uikoSOnw9KVa9M3HQsyB6l3QdinCuyZz7sRckOdSrUKtYFK/\n" \ "g+RmBqWVrwRLgnVmLtUlulHI7/H7Rbz0Exiv0beyjakd+p40O8V7Y1kuhE9z8WT6\n" \ "gtDd4grLNBMtUkd2Y8MmYFed2SP5OUoIdySdcUuo50NiS2KH5j3DhZB+ZmZn0lXw\n" \ "E91O2eNgEaryrnDoMftlJAUOSGh3uuCS27y1SXm8IC1Cxkv+OUyjXu9HnZoIX5v0\n" \ "59cTAFzrSo5tF/XtJlZ7fJU7VC98NaurfWKrF1XWgoKHJcjsFgep1K6PRIb7g5xq\n" \ "wlWUOFYTlDIYMAocGYJabw6jZrSphQIDAQABo4ICTjCCAkowDgYDVR0PAQH/BAQD\n" \ "AgWgM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kMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" \ "Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n" \ "AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n" \ "rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n" \ "OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n" \ "xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n" \ "7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n" \ "aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" \ "HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n" \ "SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n" \ "ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n" \ "AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" \ "R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" \ "JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" \ "Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" \ "-----END CERTIFICATE-----\n"; const char *get_pool_api[] = {"https://server.duinocoin.com/getPool"}; const char *miner_version = "Official ESP32 Miner 2.76"; String pool_name = ""; String host = ""; int port = 0; int walletid = 0; volatile int wifi_state = 0; volatile int wifi_prev_state = WL_CONNECTED; volatile bool ota_state = false; volatile char chip_id[23]; // DUCO MCU ID char rigname_auto[23]; // SPACE TO STORE RIG NAME int mqttUpdateTrigger = 0; String mqttRigTopic = ""; // Wifi and Mqtt Clients WiFiClient wifiMqttClient; PubSubClient mqttClient(wifiMqttClient); // Util Functions void blink(uint8_t count, uint8_t pin = LED_BUILTIN) { uint8_t state = LOW; for (int x = 0; x < (count << 1); ++x) { digitalWrite(pin, state ^= HIGH); delay(75); } } // Communication Functions void UpdatePool() { String input = ""; int waitTime = 1; int poolIndex = 0; int poolSize = sizeof(get_pool_api) / sizeof(char*); while (input == "") { Serial.println("Fetching pool (" + String(get_pool_api[poolIndex]) + ")... "); input = httpGetString(get_pool_api[poolIndex]); poolIndex += 1; // Check if pool index needs to roll over if( poolIndex >= poolSize ){ Serial.println("Retrying pool list in: " + String(waitTime) + "s"); poolIndex %= poolSize; delay(waitTime * 1000); // Increase wait time till a maximum of 16 seconds (addresses: Limit connection requests on failure in ESP boards #1041) waitTime *= 2; if( waitTime > 16 ) waitTime = 16; } } // Setup pool with new input UpdateHostPort(input); } void UpdateHostPort(String input) { // Thanks @ricaun for the code StaticJsonDocument<256> doc; DeserializationError error = deserializeJson(doc, input); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.f_str()); return; } const char *name = doc["name"]; const char *h = doc["ip"]; int p = doc["port"]; host = h; port = p; // Send to MQTT mqttClient.publish((mqttRigTopic + "pool_name").c_str(), name); mqttClient.publish((mqttRigTopic + "pool_ip").c_str(), h); mqttClient.publish((mqttRigTopic + "pool_port").c_str(), String(p).c_str()); // Send to Serial Serial.println("Fetched pool: " + String(name) + " - " + String(host) + ":" + String(port)); } String httpGetString(String URL) { String payload = ""; WiFiClientSecure client; client.setInsecure(); HTTPClient http; if (http.begin(client, URL)) { int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { payload = http.getString(); } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } return payload; } void HandleMqttConnection() { // Check Connection if (!mqttClient.connected()) { // Setup MQTT Client Serial.println("Connecting to mqtt server: " + String(mqtt_server) + " on port: " + String(mqtt_port)); mqttClient.setServer(mqtt_server, mqtt_port); // Setup Rig Topic mqttRigTopic = "duinocoin/" + String(rig_identifier) + "/"; // Try to connect if (mqttClient.connect(rig_identifier, (mqttRigTopic + "state").c_str(), 0, true, String(0).c_str())) { // Connection Succesfull Serial.println("Succesfully connected to mqtt server"); // Output connection info mqttClient.publish((mqttRigTopic + "ip").c_str(), WiFi.localIP().toString().c_str()); mqttClient.publish((mqttRigTopic + "name").c_str(), String(rig_identifier).c_str()); } else{ // Connection Failed Serial.println("Failed to connect to mqtt server"); } } // Default MQTT Loop mqttClient.loop(); } void WiFireconnect(void *pvParameters) { int n = 0; unsigned long previousMillis = 0; const long interval = 500; esp_task_wdt_add(NULL); for (;;) { wifi_state = WiFi.status(); #ifdef ENABLE_OTA ArduinoOTA.handle(); #endif if (ota_state) // If OTA is working, reset the watchdog esp_task_wdt_reset(); // check if WiFi status has changed. if ((wifi_state == WL_CONNECTED) && (wifi_prev_state != WL_CONNECTED)) { esp_task_wdt_reset(); // Reset watchdog timer // Connect to MQTT (will do nothing if MQTT is disabled) HandleMqttConnection(); // Write Data to Serial Serial.println(F("\nConnected to WiFi!")); Serial.println(" IP address: " + WiFi.localIP().toString()); Serial.println(" Rig name: " + String(rig_identifier)); Serial.println(); // Notify Setup Complete blink(BLINK_SETUP_COMPLETE);// Sucessfull connection with wifi network // Update Pool and wait a bit UpdatePool(); yield(); delay(100); } else if ((wifi_state != WL_CONNECTED) && (wifi_prev_state == WL_CONNECTED)) { esp_task_wdt_reset(); // Reset watchdog timer Serial.println(F("\nWiFi disconnected!")); WiFi.disconnect(); Serial.println(F("Scanning for WiFi networks")); n = WiFi.scanNetworks(false, true); Serial.println(F("Scan done")); if (n == 0) { Serial.println(F("No networks found. Resetting ESP32.")); blink(BLINK_RESET_DEVICE); esp_restart(); } else { Serial.print(n); Serial.println(F(" networks found")); for (int i = 0; i < n; ++i) { // Print wifi_ssid and RSSI for each network found Serial.print(i + 1); Serial.print(F(": ")); Serial.print(WiFi.SSID(i)); Serial.print(F(" (")); Serial.print(WiFi.RSSI(i)); Serial.print(F(")")); Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); delay(10); } } esp_task_wdt_reset(); // Reset watchdog timer Serial.println(); Serial.println( F("Please, check if your WiFi network is on the list and check if " "it's strong enough (greater than -90).")); Serial.println("ESP32 will reset itself after " + String(WDT_TIMEOUT) + " seconds if can't connect to the network"); Serial.print("Connecting to: " + String(wifi_ssid)); WiFi.reconnect(); } else if ((wifi_state == WL_CONNECTED) && (wifi_prev_state == WL_CONNECTED)) { esp_task_wdt_reset(); // Reset watchdog timer delay(1000); } else { // Don't reset watchdog timer unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; Serial.print(F(".")); } } wifi_prev_state = wifi_state; } } // Miner Code void TaskMining(void *pvParameters) { // Setup Thread esp_task_wdt_add(NULL); // Disable watchdogtimer for this thread // Setup thread data String taskCoreName = "CORE" + String(xPortGetCoreID()); int taskId = xPortGetCoreID(); // Start main thread loop for ( ;; ) { // If OTA needs to be preformed reset the task watchdog if (ota_state) esp_task_wdt_reset(); // Wait for a valid network connection while (wifi_state != WL_CONNECTED){ delay(1000); esp_task_wdt_reset(); } // Wait for server to get pool information while( port == 0 ){ Serial.println(String("MinerThread on " + taskCoreName + " waiting for pool")); delay(1000); esp_task_wdt_reset(); } // Setup WiFi Client and connection details Serial.println(String("MinerThread on " + taskCoreName + " connecting to Duino-Coin server...")); WiFiClient jobClient; jobClient.setTimeout(1); jobClient.flush(); yield(); // Start connection to Duino-Coin server if (!jobClient.connect(host.c_str(), port)) { Serial.println(String("MinerThread on " + taskCoreName + " failed to connect")); delay(500); continue; } // Wait for server connection Serial.println(String("MinerThread on " + taskCoreName + " is connected")); while (!jobClient.available()) { yield(); if (!jobClient.connected()) break; delay(10); } // Server sends SERVER_VERSION after connecting String SERVER_VER = jobClient.readString(); Serial.println(String("MinerThread on " + taskCoreName + " received server version: " + SERVER_VER)); blink(BLINK_CLIENT_CONNECT); // Sucessfull connection with the server // Define job loop variables int jobClientBufferSize = 0; // Start Job loop while (jobClient.connected()) { // Reset watchdog timer before each job esp_task_wdt_reset(); // We are connected and are able to request a job Serial.println(String("MinerThread on " + taskCoreName + " asking for a new job for user: " + username)); jobClient.flush(); jobClient.print("JOB," + String(username) + ",ESP32"); while (!jobClient.available()) { if (!jobClient.connected()) break; delay(10); } yield(); // Check buffer size is larget than 10 jobClientBufferSize = jobClient.available(); if (jobClientBufferSize <= 10) { Serial.println(String("MinerThread on " + taskCoreName + " buffer size is: " + jobClientBufferSize + " (FAILED, requesting new job...)")); continue; } else{ Serial.println(String("MinerThread on " + taskCoreName + " buffer size is: " + jobClientBufferSize + " (OK)")); } // Read hash, expected hash and difficulty from job description String previousHash = jobClient.readStringUntil(MSGDELIMITER); String expectedHash = jobClient.readStringUntil(MSGDELIMITER); TaskThreadData[taskId].difficulty = jobClient.readStringUntil(MSGNEWLINE).toInt() * 100; jobClient.flush(); // Global Definitions unsigned int job_size_task_one = 100; unsigned char *expectedHashBytes = (unsigned char *)malloc(job_size_task_one * sizeof(unsigned char)); // Clear expectedHashBytes memset(expectedHashBytes, 0, job_size_task_one); size_t expectedHashLength = expectedHash.length() / 2; // Convert expected hash to byte array (for easy comparison) const char *cExpectedHash = expectedHash.c_str(); for (size_t i = 0, j = 0; j < expectedHashLength; i += 2, j++) expectedHashBytes[j] = (cExpectedHash[i] % 32 + 9) % 25 * 16 + (cExpectedHash [i + 1] % 32 + 9) % 25; // Start measurement unsigned long startTime = micros(); byte shaResult[20]; String hashUnderTest; unsigned int hashUnderTestLength; bool ignoreHashrate = false; // Try to find the nonce which creates the expected hash for (unsigned long nonceCalc = 0; nonceCalc <= TaskThreadData[taskId].difficulty; nonceCalc++) { // Define hash under Test hashUnderTest = previousHash + String(nonceCalc); hashUnderTestLength = hashUnderTest.length(); // Wait for hash module lock while( xSemaphoreTake(xMutex, portMAX_DELAY) != pdTRUE ); // We are allowed to perform our hash esp_sha(SHA1, (const unsigned char *)hashUnderTest.c_str(), hashUnderTestLength, shaResult); // Release hash module lock xSemaphoreGive(xMutex); // Check if we have found the nonce for the expected hash if( memcmp( shaResult, expectedHashBytes, sizeof(shaResult) ) == 0 ){ // Found the nonce submit it to the server Serial.println(String("MinerThread on " + taskCoreName + " found hash with nonce: " + nonceCalc )); // Calculate mining time float elapsedTime = (micros() - startTime) / 1000.0 / 1000.0; // Total elapsed time in seconds TaskThreadData[taskId].hashrate = nonceCalc / elapsedTime; // Validate connection if (!jobClient.connected()) { Serial.println(String("MinerThread on " + taskCoreName + " Lost connection. Trying to reconnect")); if (!jobClient.connect(host.c_str(), port)) { Serial.println(String("MinerThread on " + taskCoreName + " connection failed")); break; } Serial.println(String("MinerThread on " + taskCoreName + " Reconnection successful.")); } // Send result to server jobClient.flush(); jobClient.print( String(nonceCalc) + MSGDELIMITER + String(TaskThreadData[taskId].hashrate) + MSGDELIMITER + String(miner_version) + MSGDELIMITER + String(rig_identifier) + MSGDELIMITER + "DUCOID" + String((char *)chip_id) + MSGDELIMITER + String(walletid)); jobClient.flush(); // Wait for job result while (!jobClient.available()) { if (!jobClient.connected()) { Serial.println(String("MinerThread on " + taskCoreName + " Lost connection. Didn't receive feedback.")); break; } delay(10); yield(); } delay(50); yield(); // Handle feedback String feedback = jobClient.readStringUntil(MSGNEWLINE); jobClient.flush(); TaskThreadData[taskId].shares++; blink(BLINK_SHARE_FOUND); // Validate Hashrate if( TaskThreadData[taskId].hashrate < 4000 && !ignoreHashrate){ // Hashrate is low so restart esp Serial.println(String("MinerThread on " + taskCoreName + " Low hashrate (" + TaskThreadData[taskId].hashrate + "), Feedback: " + feedback + ". Restarting...")); jobClient.flush(); jobClient.stop(); blink(BLINK_RESET_DEVICE); esp_restart(); } else{ // Print statistics Serial.println(String("MinerThread on " + taskCoreName + " Job Feedback: " + feedback + ", Hashrate: " + TaskThreadData[taskId].hashrate + ", shares found: #" + TaskThreadData[taskId].shares)); } // Stop current loop and ask for a new job break; } } } Serial.println(String("MinerThread on " + taskCoreName + " Not connected. Restarting core")); jobClient.flush(); jobClient.stop(); } } void setup() { Serial.begin(500000); // Start serial connection display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); display.clearDisplay(); display.display(); Serial.println("\n\nDuino-Coin " + String(miner_version)); WiFi.mode(WIFI_STA); // Setup ESP in client mode btStop(); WiFi.begin(wifi_ssid, wifi_password); // Connect to wifi uint64_t chipid = ESP.getEfuseMac(); // Getting chip chip_id uint16_t chip = (uint16_t)(chipid >> 32); // Preparing for printing a 64 bit value (it's // actually 48 bits long) into a char array snprintf( (char *)chip_id, 23, "%04X%08X", chip, (uint32_t)chipid); // Storing the 48 bit chip chip_id into a char array. walletid = random(0, 2811); // Autogenerate ID if required if( strcmp(rig_identifier, "Auto") == 0 ){ snprintf(rigname_auto, 23, "ESP32-%04X%08X", chip, (uint32_t)chipid); rig_identifier = &rigname_auto[0]; } ota_state = false; #ifdef ENABLE_OTA ArduinoOTA .onStart([]() { String type; if (ArduinoOTA.getCommand() == U_FLASH) type = "sketch"; else // U_SPIFFS type = "filesystem"; // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS // using SPIFFS.end() Serial.println("Start updating " + type); ota_state = true; }) .onEnd([]() { Serial.println(F("\nEnd")); }) .onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); esp_task_wdt_reset(); ota_state = true; }) .onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) Serial.println(F("Auth Failed")); else if (error == OTA_BEGIN_ERROR) Serial.println(F("Begin Failed")); else if (error == OTA_CONNECT_ERROR) Serial.println(F("Connect Failed")); else if (error == OTA_RECEIVE_ERROR) Serial.println(F("Receive Failed")); else if (error == OTA_END_ERROR) Serial.println(F("End Failed")); ota_state = false; blink(BLINK_RESET_DEVICE); esp_restart(); }); ArduinoOTA.setHostname(rig_identifier); ArduinoOTA.begin(); #endif esp_task_wdt_init(WDT_TIMEOUT, true); // Init Watchdog timer pinMode(LED_BUILTIN, OUTPUT); // Determine which cores to use int wifiCore = 0; int mqttCore = 0; if( NUMBEROFCORES >= 2 ) mqttCore = 1; // Create Semaphore and main Wifi Monitoring Thread xMutex = xSemaphoreCreateMutex(); xTaskCreatePinnedToCore( WiFireconnect, "WiFirec", 10000, NULL, NUMBEROFCORES + 2, &WiFirec, mqttCore); // create a task with highest priority and executed on core 0 delay(250); // If MQTT is enabled create a sending thread #ifdef ENABLE_MQTT Serial.println("Creating mqtt thread on core: " + String(mqttCore)); xTaskCreatePinnedToCore( MqttPublishCode, "MqttPublishCode", 10000, NULL, 1, &MqttPublishHandle, mqttCore); //create a task with lowest priority and executed on core 1 delay(250); #endif // Create Mining Threads for( int i = 0; i < NUMBEROFCORES; i++ ){ Serial.println("Creating mining thread on core: " + String(i)); xTaskCreatePinnedToCore( TaskMining, String("Task" + String(i)).c_str(), 10000, NULL, 2 + i, &TaskThreadData[NUMBEROFCORES].handler, i); // create a task with priority 2 (+ core id) and executed on a specific core delay(250); } } // ************************************************************ void MqttPublishCode( void * pvParameters ) { unsigned long lastWdtReset = 0; unsigned long wdtResetDelay = 30000; for(;;) { if ((millis() - lastWdtReset) > wdtResetDelay) { // Reset timers esp_task_wdt_reset(); lastWdtReset = millis(); // Calculate combined hashrate and average difficulty float avgDiff = 0.0; float totHash = 0.0; unsigned long totShares = 0; for (int i=0; i<NUMBEROFCORES; i++) { avgDiff += TaskThreadData[i].difficulty; totHash += TaskThreadData[i].hashrate; totShares += TaskThreadData[i].shares; } avgDiff /= NUMBEROFCORES; // Update States mqttClient.publish((mqttRigTopic + "state").c_str(), String(1).c_str()); mqttClient.publish((mqttRigTopic + "hashrate").c_str(), String(totHash).c_str()); mqttClient.publish((mqttRigTopic + "avgdiff").c_str(), String(avgDiff).c_str()); mqttClient.publish((mqttRigTopic + "shares").c_str(), String(totShares).c_str()); } mqttClient.loop(); yield(); } } void loop() { if ((WiFi.status() == WL_CONNECTED)) { HTTPClient http; http.setTimeout(6000); http.begin(serverName + username, root_ca); int httpCode = http.GET(); display.clearDisplay(); while(httpCode < 0) { httpCode = http.GET(); } if (httpCode > 0) { DynamicJsonDocument doc(9216); String jsonbalance = http.getString(); deserializeJson(doc, jsonbalance); JsonObject datadoc = doc.as<JsonObject>(); String ducos = datadoc["result"]["balance"]["balance"]; ducosmem = ducos; userbalance = ducos.toFloat(); //Serial.println("Ducos: " + String(ducos)); // Miners miners = 0; for (JsonObject elem : datadoc["result"]["miners"].as<JsonArray>()) { miners++; } //Serial.println("Miners: " + String(miners)); doc.clear(); } else { ducosmem = "-"; Serial.println("Error http get: " + String(httpCode)); } http.end(); if(wait == 0){ oldb = userbalance; } if(wait == 5){ wait = 0; calcule_daily(); } else{ wait++; } display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(6,0); display.print("Ducos:"); display.println(ducosmem); display.setCursor(6,10); display.print("Miners:"); display.println(miners); display.setCursor(6,20); display.print("Daily:"); display.println(daily); display.display(); } else { display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); for (int i=0; i<3 ; i++){ for (int a=95; a<99; a++){ display.setCursor(a,16); display.print(" . "); delay(500); } } display.setCursor(29,16); display.print("CONNECTING"); display.display(); //WiFi.begin(wifi_ssid, wifi_password); while (WiFi.status() != WL_CONNECTED) { delay(500); } } delay(500); } void calcule_daily() { float ducomadein = userbalance - oldb; float dayduco = ducomadein * 960; daily = dayduco * 100 / 100; int ducomadesincestart = userbalance - balance; int secondssincestart = millis() - start; start = millis(); ducomadesincesartdaily = ((86400/secondssincestart)*ducomadesincestart)*10 / 10; } |
نتیجه نهایی
در نهایت پس از تغییر اطلاعات ذکر شده در کد، برقراری اتصالات و در نهایت آپلود کد، مقادیر موجود در والت، تعداد ماینر و میزان تخمینی ماین بر اساس تعداد ماینر و HASH RATE در نمایشگر OLED نمایش داده میشود، مقادیر پس از یک دوره کوتاه آپدیت میشوند با توجه به زمان ماین کردن برد شما و تغییر اطلاعات دریافتی.
کلام آخر با سایفر
این رمز ارز به شخصه برای من بسیار جالب و سرگرم کننده بوده، در حالی که دارای ارزش دلاری است همچنین به شما این امکان را میدهد تا تنها با استفاده از میکرو کنترلر ها اقدام به استخراج این رمز ارز بکنید، مزیت و تفاوت اصلی این رمز ارز با دیگر نمونه هایی مه اسم آن ها را زیاد در طول روز ممکن است بشنویم، دوست دار محیط زیست بودن است، همان طور که اطلاع دارید ماینر های صنعتی به شکل وحشتناکی مصرف برق و تولید حرارت را به همراه دارند اما به لطف میکروکنترلر ها این موارد دیگر اتفاق نخواهد افتاد.
چنانچه در مراحل راه اندازی و انجام این پروژه با مشکل مواجه شدید، بدون هیچ نگرانی در انتهای همین پست، به صورت ثبت نظر سوالتان را مطرح کنید. من در سریعترین زمان ممکن پاسخ رفع مشکل شما را خواهم داد. همچنین اگر ایرادی در کدها و یا مراحل اجرایی وجود دارند میتوانید از همین طریق اطلاع رسانی کنید.
در پایان نظرات و پیشنهادات خود را با ما درمیان بگذارید و با اشتراک گذاری این آموزش در شبکه های اجتماعی , از وبسایت دیجی اسپارک حمایت کنید.