Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TFT_eSPI.h>
- #include <WiFi.h>
- #include <HTTPClient.h>
- TFT_eSPI tft = TFT_eSPI();
- // WiFi Configuration
- const char* ssid = "Ionita";
- const char* password = "98111480";
- // API Configuration
- const String puzzle_url = "http://btcpuzzle.info/api/puzzle/68";
- // Statistics Tracking
- unsigned long startTime;
- unsigned long totalChecks = 0;
- unsigned long lastCheckTime = 0;
- void setup() {
- Serial.begin(115200);
- startTime = millis();
- // Initialize display
- tft.init();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- tft.setTextColor(TFT_YELLOW, TFT_BLACK);
- tft.setTextSize(2);
- tft.setCursor(0, 0);
- connectToWiFi();
- }
- void connectToWiFi() {
- tft.println("Connecting to WiFi...");
- WiFi.begin(ssid, password);
- unsigned long wifiStart = millis();
- while (WiFi.status() != WL_CONNECTED && millis() - wifiStart < 15000) {
- delay(250);
- tft.print(".");
- }
- if (WiFi.status() == WL_CONNECTED) {
- tft.println("\nConnected!");
- delay(1000);
- checkPuzzleStatus();
- } else {
- displayError("WiFi Failed");
- }
- }
- void checkPuzzleStatus() {
- HTTPClient http;
- http.begin(puzzle_url);
- totalChecks++;
- updateDisplayStats("Checking...", TFT_WHITE);
- int httpCode = http.GET();
- if (httpCode == HTTP_CODE_OK) {
- String payload = http.getString();
- processPayload(payload);
- } else {
- displayError("HTTP Error: " + String(httpCode));
- }
- http.end();
- lastCheckTime = millis();
- }
- void processPayload(String payload) {
- tft.fillScreen(TFT_BLACK);
- tft.setCursor(0, 0);
- if (payload.indexOf("\"solved\": true") != -1) {
- displayStatus("SOLVED!", TFT_GREEN);
- } else {
- displayStatus("UNSOLVED", TFT_RED);
- }
- updateStatistics();
- }
- void updateStatistics() {
- tft.setTextColor(TFT_CYAN);
- tft.println("\nUptime: " + formatUptime());
- tft.println("Total checks: " + String(totalChecks));
- float checksPerSecond = totalChecks / ((millis() - startTime) / 1000.0);
- tft.printf("Checks/s: %.2f", checksPerSecond);
- }
- String formatUptime() {
- unsigned long totalSeconds = (millis() - startTime) / 1000;
- unsigned int hours = totalSeconds / 3600;
- unsigned int minutes = (totalSeconds % 3600) / 60;
- unsigned int seconds = totalSeconds % 60;
- char buffer[20];
- sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
- return String(buffer);
- }
- void displayStatus(String status, uint16_t color) {
- tft.setTextColor(color);
- tft.setTextSize(3);
- tft.println("Puzzle 68");
- tft.setTextSize(4);
- tft.println(status);
- tft.setTextSize(2); // Reset text size
- }
- void displayError(String message) {
- tft.fillScreen(TFT_RED);
- tft.setTextColor(TFT_WHITE);
- tft.setCursor(0, 0);
- tft.println("ERROR:");
- tft.println(message);
- updateStatistics();
- }
- void updateDisplayStats(String message, uint16_t color) {
- tft.fillScreen(TFT_BLACK);
- tft.setCursor(0, 0);
- tft.setTextColor(color);
- tft.println(message);
- updateStatistics();
- }
- void loop() {
- // Check every 5 minutes (300000ms)
- if (millis() - lastCheckTime > 300000) {
- checkPuzzleStatus();
- }
- // Update statistics every second
- static unsigned long lastUpdate = 0;
- if (millis() - lastUpdate > 1000) {
- updateDisplayStats("Refreshing...", TFT_WHITE);
- lastUpdate = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement