2023-03-20 01:10:44 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <WebServer.h>
|
2023-04-17 02:07:18 +02:00
|
|
|
#include <esp_task_wdt.h>
|
2023-03-20 01:10:44 +01:00
|
|
|
#include <TFT_eSPI.h> // Graphics and font library
|
2023-04-17 02:07:18 +02:00
|
|
|
|
|
|
|
#include "mbedtls/md.h"
|
2023-04-07 00:43:20 +02:00
|
|
|
#include "media/images.h"
|
|
|
|
#include "media/myFonts.h"
|
2023-03-20 01:10:44 +01:00
|
|
|
#include "OpenFontRender.h"
|
|
|
|
#include "wManager.h"
|
|
|
|
#include "mining.h"
|
2023-04-17 02:07:18 +02:00
|
|
|
|
|
|
|
//3 seconds WDT
|
|
|
|
#define WDT_TIMEOUT 3
|
2023-03-20 01:10:44 +01:00
|
|
|
|
|
|
|
OpenFontRender render;
|
|
|
|
|
|
|
|
/**********************⚡ GLOBAL Vars *******************************/
|
|
|
|
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
|
|
|
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
|
|
|
|
|
|
|
|
static long templates = 0;
|
|
|
|
static long hashes = 0;
|
|
|
|
static int halfshares = 0; // increase if blockhash has 16 bits of zeroes
|
|
|
|
static int shares = 0; // increase if blockhash has 32 bits of zeroes
|
2023-04-17 02:07:18 +02:00
|
|
|
static int valids = 0; // increased if blockhash <= target
|
|
|
|
|
|
|
|
int oldStatus = 0;
|
|
|
|
unsigned long start = millis();
|
2023-03-20 01:10:44 +01:00
|
|
|
|
|
|
|
//void runMonitor(void *name);
|
|
|
|
|
|
|
|
/********* INIT *****/
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2023-04-17 02:07:18 +02:00
|
|
|
Serial.setTimeout(0);
|
2023-03-20 01:10:44 +01:00
|
|
|
delay(100);
|
|
|
|
|
|
|
|
// Idle task that would reset WDT never runs, because core 0 gets fully utilized
|
|
|
|
disableCore0WDT();
|
|
|
|
|
|
|
|
/******** INIT NERDMINER ************/
|
2023-04-17 02:07:18 +02:00
|
|
|
Serial.println("NerdMiner v2 starting......");
|
|
|
|
|
|
|
|
// Setup the button
|
|
|
|
pinMode(PIN_BUTTON_1, INPUT);
|
|
|
|
attachInterrupt(PIN_BUTTON_1, checkResetConfigButton, FALLING);
|
2023-03-20 01:10:44 +01:00
|
|
|
|
|
|
|
/******** INIT DISPLAY ************/
|
|
|
|
tft.init();
|
|
|
|
tft.setRotation(1);
|
|
|
|
tft.setSwapBytes(true);// Swap the colour byte order when rendering
|
|
|
|
background.createSprite(initWidth,initHeight); //Background Sprite
|
|
|
|
background.setSwapBytes(true);
|
|
|
|
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
|
|
|
|
render.setLineSpaceRatio(0.9); //Espaciado entre texto
|
|
|
|
|
|
|
|
// Load the font and check it can be read OK
|
|
|
|
//if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) {
|
|
|
|
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers))){
|
|
|
|
Serial.println("Initialise error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******** PRINT INIT SCREEN *****/
|
|
|
|
tft.fillScreen(TFT_BLACK);
|
|
|
|
tft.pushImage(0, 0, initWidth, initHeight, initScreen);
|
|
|
|
|
|
|
|
delay(2000);
|
|
|
|
|
|
|
|
/******** INIT WIFI ************/
|
|
|
|
init_WifiManager();
|
|
|
|
|
|
|
|
/******** CREATE TASK TO PRINT SCREEN *****/
|
|
|
|
//tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
|
|
|
// Higher prio monitor task
|
2023-04-17 02:07:18 +02:00
|
|
|
Serial.println("");
|
|
|
|
Serial.println("Initiating tasks...");
|
2023-03-20 01:10:44 +01:00
|
|
|
xTaskCreate(runMonitor, "Monitor", 5000, NULL, 4, NULL);
|
|
|
|
|
2023-04-18 14:08:58 +02:00
|
|
|
/******** CREATE MINER TASKS *****/
|
2023-04-17 02:07:18 +02:00
|
|
|
for (size_t i = 0; i < THREADS; i++) {
|
|
|
|
char *name = (char*) malloc(32);
|
|
|
|
sprintf(name, "(%d)", i);
|
2023-03-20 01:10:44 +01:00
|
|
|
|
|
|
|
// Start mining tasks
|
2023-04-17 02:07:18 +02:00
|
|
|
BaseType_t res = xTaskCreate(runWorker, name, 30000, (void*)name, 1, NULL);
|
|
|
|
Serial.printf("Starting %s %s!\n", name, res == pdPASS? "successful":"failed");
|
2023-03-20 01:10:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
void app_error_fault_handler(void *arg) {
|
|
|
|
// Get stack errors
|
|
|
|
char *stack = (char *)arg;
|
2023-03-20 01:10:44 +01:00
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
// Print the stack errors in the console
|
|
|
|
esp_log_write(ESP_LOG_ERROR, "APP_ERROR", "Pila de errores:\n%s", stack);
|
2023-03-20 01:10:44 +01:00
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
// restart ESP32
|
|
|
|
esp_restart();
|
2023-03-20 01:10:44 +01:00
|
|
|
}
|
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
void loop() {
|
2023-03-20 01:10:44 +01:00
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
|
|
|
|
|
|
|
int newStatus = WiFi.status();
|
|
|
|
if (newStatus != oldStatus) {
|
|
|
|
if (newStatus == WL_CONNECTED) {
|
|
|
|
Serial.println("CONNECTED - Current ip: " + WiFi.localIP().toString());
|
|
|
|
} else {
|
|
|
|
Serial.print("[Error] - current status: ");
|
|
|
|
Serial.println(newStatus);
|
|
|
|
}
|
|
|
|
oldStatus = newStatus;
|
|
|
|
}
|
2023-03-20 01:10:44 +01:00
|
|
|
|
2023-04-17 02:07:18 +02:00
|
|
|
checkRemoveConfiguration();
|
2023-03-20 01:10:44 +01:00
|
|
|
|
2023-04-18 14:08:58 +02:00
|
|
|
}
|