|
22 | 22 | /* If during compilation the line below causes a
|
23 | 23 | "fatal error: arduinoJson.h: No such file or directory"
|
24 | 24 | message to occur; it means that you do NOT have the
|
25 |
| - ArduinoJSON library installed. To install it, |
26 |
| - go to the below link and follow the instructions: |
| 25 | + ArduinoJSON library installed. To install it, |
| 26 | + go to the below link and follow the instructions: |
27 | 27 | https://github.com/revoxhere/duino-coin/issues/832 */
|
28 | 28 | #include <ArduinoJson.h>
|
29 | 29 |
|
|
35 | 35 | follow the instructions of the readme file:
|
36 | 36 | https://github.com/esp8266/Arduino */
|
37 | 37 | #include <bearssl/bearssl.h>
|
38 |
| -#include <TypeConversion.h> |
| 38 | +//#include <TypeConversion.h> |
39 | 39 |
|
40 | 40 | #include <ESP8266WiFi.h>
|
41 | 41 | #include <ESP8266mDNS.h>
|
|
56 | 56 | // https://www.techtarget.com/iotagenda/definition/MQTT-MQ-Telemetry-Transport
|
57 | 57 |
|
58 | 58 | #ifdef USE_DHT
|
59 |
| - float temp = 0.0; |
60 |
| - float hum = 0.0; |
| 59 | +float temp = 0.0; |
| 60 | +float hum = 0.0; |
61 | 61 |
|
62 |
| - // Install "DHT sensor library" if you get an error |
63 |
| - #include <DHT.h> |
64 |
| - // Change D3 to the pin you've connected your sensor to |
65 |
| - #define DHTPIN D3 |
66 |
| - // Set DHT11 or DHT22 accordingly |
67 |
| - #define DHTTYPE DHT11 |
| 62 | +// Install "DHT sensor library" if you get an error |
| 63 | +#include <DHT.h> |
| 64 | +// Change D3 to the pin you've connected your sensor to |
| 65 | +#define DHTPIN D3 |
| 66 | +// Set DHT11 or DHT22 accordingly |
| 67 | +#define DHTTYPE DHT11 |
68 | 68 |
|
69 |
| - DHT dht(DHTPIN, DHTTYPE); |
| 69 | +DHT dht(DHTPIN, DHTTYPE); |
70 | 70 | #endif
|
71 | 71 |
|
72 | 72 | #ifdef USE_MQTT
|
73 |
| - // Install "PubSubClient" if you get an error |
74 |
| - #include <PubSubClient.h> |
| 73 | +// Install "PubSubClient" if you get an error |
| 74 | +#include <PubSubClient.h> |
75 | 75 |
|
76 |
| - long lastMsg = 0; |
| 76 | +long lastMsg = 0; |
77 | 77 |
|
78 |
| - // Change the part in brackets to your MQTT broker address |
79 |
| - #define mqtt_server "broker.hivemq.com" |
80 |
| - // broker.hivemq.com is for testing purposes, change it to your broker address |
| 78 | +// Change the part in brackets to your MQTT broker address |
| 79 | +#define mqtt_server "broker.hivemq.com" |
| 80 | +// broker.hivemq.com is for testing purposes, change it to your broker address |
81 | 81 |
|
82 |
| - // Change this to your MQTT broker port |
83 |
| - #define mqtt_port 1883 |
84 |
| - // If you want to use user and password for your MQTT broker, uncomment the line below |
85 |
| - // #define mqtt_use_credentials |
| 82 | +// Change this to your MQTT broker port |
| 83 | +#define mqtt_port 1883 |
| 84 | +// If you want to use user and password for your MQTT broker, uncomment the line below |
| 85 | +// #define mqtt_use_credentials |
86 | 86 |
|
87 |
| - // Change the part in brackets to your MQTT broker username |
88 |
| - #define mqtt_user "My cool mqtt username" |
89 |
| - // Change the part in brackets to your MQTT broker password |
90 |
| - #define mqtt_password "My secret mqtt pass" |
| 87 | +// Change the part in brackets to your MQTT broker username |
| 88 | +#define mqtt_user "My cool mqtt username" |
| 89 | +// Change the part in brackets to your MQTT broker password |
| 90 | +#define mqtt_password "My secret mqtt pass" |
91 | 91 |
|
92 |
| - // Change this if you want to send data to the topic every X milliseconds |
93 |
| - #define mqtt_update_time 5000 |
| 92 | +// Change this if you want to send data to the topic every X milliseconds |
| 93 | +#define mqtt_update_time 5000 |
94 | 94 |
|
95 |
| - // Change the part in brackets to your MQTT humidity topic |
96 |
| - #define humidity_topic "sensor/humidity" |
97 |
| - // Change the part in brackets to your MQTT temperature topic |
98 |
| - #define temperature_topic "sensor/temperature" |
| 95 | +// Change the part in brackets to your MQTT humidity topic |
| 96 | +#define humidity_topic "sensor/humidity" |
| 97 | +// Change the part in brackets to your MQTT temperature topic |
| 98 | +#define temperature_topic "sensor/temperature" |
99 | 99 |
|
100 |
| - WiFiClient espClient; |
101 |
| - PubSubClient mqttClient(espClient); |
| 100 | +WiFiClient espClient; |
| 101 | +PubSubClient mqttClient(espClient); |
102 | 102 |
|
103 |
| - void mqttReconnect() |
| 103 | +void mqttReconnect() |
| 104 | +{ |
| 105 | + // Loop until we're reconnected |
| 106 | + while (!mqttClient.connected()) |
104 | 107 | {
|
105 |
| - // Loop until we're reconnected |
106 |
| - while (!mqttClient.connected()) |
| 108 | + Serial.print("Attempting MQTT connection..."); |
| 109 | + |
| 110 | + // Create a random client ID |
| 111 | + String clientId = "ESP8266Client-"; |
| 112 | + clientId += String(random(0xffff), HEX); |
| 113 | + |
| 114 | + // Attempt to connect |
| 115 | +#ifdef mqtt_use_credentials |
| 116 | + if (mqttClient.connect("ESP8266Client", mqtt_user, mqtt_password)) |
| 117 | +#else |
| 118 | + if (mqttClient.connect(clientId.c_str())) |
| 119 | +#endif |
| 120 | + { |
| 121 | + Serial.println("connected"); |
| 122 | + } |
| 123 | + else |
107 | 124 | {
|
108 |
| - Serial.print("Attempting MQTT connection..."); |
109 |
| - |
110 |
| - // Create a random client ID |
111 |
| - String clientId = "ESP8266Client-"; |
112 |
| - clientId += String(random(0xffff), HEX); |
113 |
| - |
114 |
| - // Attempt to connect |
115 |
| - #ifdef mqtt_use_credentials |
116 |
| - if (mqttClient.connect("ESP8266Client", mqtt_user, mqtt_password)) |
117 |
| - #else |
118 |
| - if (mqttClient.connect(clientId.c_str())) |
119 |
| - #endif |
120 |
| - { |
121 |
| - Serial.println("connected"); |
122 |
| - } |
123 |
| - else |
124 |
| - { |
125 |
| - Serial.print("failed, rc="); |
126 |
| - Serial.print(mqttClient.state()); |
127 |
| - Serial.println(" try again in 5 seconds"); |
128 |
| - // Wait 5 seconds before retrying |
129 |
| - delay(5000); |
130 |
| - } |
| 125 | + Serial.print("failed, rc="); |
| 126 | + Serial.print(mqttClient.state()); |
| 127 | + Serial.println(" try again in 5 seconds"); |
| 128 | + // Wait 5 seconds before retrying |
| 129 | + delay(5000); |
131 | 130 | }
|
132 | 131 | }
|
| 132 | +} |
133 | 133 | #endif
|
134 | 134 |
|
135 | 135 | namespace
|
136 | 136 | {
|
137 |
| - // Change the part in brackets to your Duino-Coin username |
138 |
| - const char *DUCO_USER = "USERNAME"; |
139 |
| - // Change the part in brackets to your mining key (if you have enabled it in the wallet) |
140 |
| - const char *MINER_KEY = "MINING_KEY"; |
141 |
| - // Change the part in brackets to your WiFi name |
142 |
| - const char *SSID = "WIFI_NAME"; |
143 |
| - // Change the part in brackets to your WiFi password |
144 |
| - const char *PASSWORD = "WIFI_PASSWORD"; |
145 |
| - // Change the part in brackets if you want to set a custom miner name (use Auto to autogenerate, None for no name) |
146 |
| - const char *RIG_IDENTIFIER = "None"; |
147 |
| - // Set to true to use the 160 MHz overclock mode (and not get the first share rejected) |
148 |
| - const bool USE_HIGHER_DIFF = true; |
149 |
| - // Set to true if you want to host the dashboard page (available on ESPs IP address) |
150 |
| - const bool WEB_DASHBOARD = false; |
151 |
| - // Set to true if you want to update hashrate in browser without reloading the page |
152 |
| - const bool WEB_HASH_UPDATER = false; |
153 |
| - // Set to false if you want to disable the onboard led blinking when finding shares |
154 |
| - const bool LED_BLINKING = true; |
| 137 | +// Change the part in brackets to your Duino-Coin username |
| 138 | +const char *DUCO_USER = "USERNAME"; |
| 139 | +// Change the part in brackets to your mining key (if you have enabled it in the wallet) |
| 140 | +const char *MINER_KEY = "MINING_KEY"; |
| 141 | +// Change the part in brackets to your WiFi name |
| 142 | +const char *SSID = "WIFI_NAME"; |
| 143 | +// Change the part in brackets to your WiFi password |
| 144 | +const char *PASSWORD = "WIFI_PASSWORD"; |
| 145 | +// Change the part in brackets if you want to set a custom miner name (use Auto to autogenerate, None for no name) |
| 146 | +const char *RIG_IDENTIFIER = "None"; |
| 147 | +// Set to true to use the 160 MHz overclock mode (and not get the first share rejected) |
| 148 | +const bool USE_HIGHER_DIFF = true; |
| 149 | +// Set to true if you want to host the dashboard page (available on ESPs IP address) |
| 150 | +const bool WEB_DASHBOARD = false; |
| 151 | +// Set to true if you want to update hashrate in browser without reloading the page |
| 152 | +const bool WEB_HASH_UPDATER = false; |
| 153 | +// Set to false if you want to disable the onboard led blinking when finding shares |
| 154 | +const bool LED_BLINKING = true; |
155 | 155 |
|
156 | 156 | /* Do not change the lines below. These lines are static and dynamic variables
|
157 | 157 | that will be used by the program for counters and measurements. */
|
@@ -596,6 +596,20 @@ void dashboard() {
|
596 | 596 |
|
597 | 597 | } // namespace
|
598 | 598 |
|
| 599 | +// https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TypeConversion.cpp |
| 600 | +const char base36Chars[36] PROGMEM = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; |
| 601 | +const uint8_t base36CharValues[75] PROGMEM {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, // 0 to 9 |
| 602 | + 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, 0, 0, 0, 0, 0, 0, // Upper case letters |
| 603 | + 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 // Lower case letters |
| 604 | +}; |
| 605 | +uint8_t *hexStringToUint8Array(const String &hexString, uint8_t *uint8Array, const uint32_t arrayLength) { |
| 606 | + assert(hexString.length() >= arrayLength * 2); |
| 607 | + for (uint32_t i = 0; i < arrayLength; ++i) { |
| 608 | + uint8Array[i] = (pgm_read_byte(base36CharValues + hexString.charAt(i * 2) - '0') << 4) + pgm_read_byte(base36CharValues + hexString.charAt(i * 2 + 1) - '0'); |
| 609 | + } |
| 610 | + return uint8Array; |
| 611 | +} |
| 612 | + |
599 | 613 | void setup() {
|
600 | 614 | Serial.begin(500000);
|
601 | 615 | Serial.println("\nDuino-Coin " + String(MINER_VER));
|
@@ -709,9 +723,9 @@ void loop() {
|
709 | 723 | int job_len = last_block_hash.length() + expected_hash_str.length() + String(difficulty).length();
|
710 | 724 |
|
711 | 725 | Serial.println("Received job with size of " + String(job_len) + " bytes: " + last_block_hash + " " + expected_hash_str + " " + difficulty);
|
712 |
| - |
| 726 | + |
713 | 727 | uint8_t expected_hash[20];
|
714 |
| - experimental::TypeConversion::hexStringToUint8Array(expected_hash_str, expected_hash, 20); |
| 728 | + hexStringToUint8Array(expected_hash_str, expected_hash, 20); |
715 | 729 |
|
716 | 730 | br_sha1_init(&sha1_ctx_base);
|
717 | 731 | br_sha1_update(&sha1_ctx_base, last_block_hash.c_str(), last_block_hash.length());
|
|
0 commit comments