Advertisement
Guest User

CYD-Code

a guest
Mar 25th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #include <TFT_eSPI.h>
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4.  
  5. TFT_eSPI tft = TFT_eSPI();
  6.  
  7. // WiFi Configuration
  8. const char* ssid = "Ionita";
  9. const char* password = "98111480";
  10.  
  11. // API Configuration
  12. const String puzzle_url = "http://btcpuzzle.info/api/puzzle/68";
  13.  
  14. // Statistics Tracking
  15. unsigned long startTime;
  16. unsigned long totalChecks = 0;
  17. unsigned long lastCheckTime = 0;
  18.  
  19. void setup() {
  20. Serial.begin(115200);
  21. startTime = millis();
  22.  
  23. // Initialize display
  24. tft.init();
  25. tft.setRotation(1);
  26. tft.fillScreen(TFT_BLACK);
  27. tft.setTextColor(TFT_YELLOW, TFT_BLACK);
  28. tft.setTextSize(2);
  29. tft.setCursor(0, 0);
  30.  
  31. connectToWiFi();
  32. }
  33.  
  34. void connectToWiFi() {
  35. tft.println("Connecting to WiFi...");
  36. WiFi.begin(ssid, password);
  37.  
  38. unsigned long wifiStart = millis();
  39. while (WiFi.status() != WL_CONNECTED && millis() - wifiStart < 15000) {
  40. delay(250);
  41. tft.print(".");
  42. }
  43.  
  44. if (WiFi.status() == WL_CONNECTED) {
  45. tft.println("\nConnected!");
  46. delay(1000);
  47. checkPuzzleStatus();
  48. } else {
  49. displayError("WiFi Failed");
  50. }
  51. }
  52.  
  53. void checkPuzzleStatus() {
  54. HTTPClient http;
  55. http.begin(puzzle_url);
  56.  
  57. totalChecks++;
  58. updateDisplayStats("Checking...", TFT_WHITE);
  59.  
  60. int httpCode = http.GET();
  61.  
  62. if (httpCode == HTTP_CODE_OK) {
  63. String payload = http.getString();
  64. processPayload(payload);
  65. } else {
  66. displayError("HTTP Error: " + String(httpCode));
  67. }
  68.  
  69. http.end();
  70. lastCheckTime = millis();
  71. }
  72.  
  73. void processPayload(String payload) {
  74. tft.fillScreen(TFT_BLACK);
  75. tft.setCursor(0, 0);
  76.  
  77. if (payload.indexOf("\"solved\": true") != -1) {
  78. displayStatus("SOLVED!", TFT_GREEN);
  79. } else {
  80. displayStatus("UNSOLVED", TFT_RED);
  81. }
  82. updateStatistics();
  83. }
  84.  
  85. void updateStatistics() {
  86. tft.setTextColor(TFT_CYAN);
  87. tft.println("\nUptime: " + formatUptime());
  88. tft.println("Total checks: " + String(totalChecks));
  89.  
  90. float checksPerSecond = totalChecks / ((millis() - startTime) / 1000.0);
  91. tft.printf("Checks/s: %.2f", checksPerSecond);
  92. }
  93.  
  94. String formatUptime() {
  95. unsigned long totalSeconds = (millis() - startTime) / 1000;
  96. unsigned int hours = totalSeconds / 3600;
  97. unsigned int minutes = (totalSeconds % 3600) / 60;
  98. unsigned int seconds = totalSeconds % 60;
  99.  
  100. char buffer[20];
  101. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  102. return String(buffer);
  103. }
  104.  
  105. void displayStatus(String status, uint16_t color) {
  106. tft.setTextColor(color);
  107. tft.setTextSize(3);
  108. tft.println("Puzzle 68");
  109. tft.setTextSize(4);
  110. tft.println(status);
  111. tft.setTextSize(2); // Reset text size
  112. }
  113.  
  114. void displayError(String message) {
  115. tft.fillScreen(TFT_RED);
  116. tft.setTextColor(TFT_WHITE);
  117. tft.setCursor(0, 0);
  118. tft.println("ERROR:");
  119. tft.println(message);
  120. updateStatistics();
  121. }
  122.  
  123. void updateDisplayStats(String message, uint16_t color) {
  124. tft.fillScreen(TFT_BLACK);
  125. tft.setCursor(0, 0);
  126. tft.setTextColor(color);
  127. tft.println(message);
  128. updateStatistics();
  129. }
  130.  
  131. void loop() {
  132. // Check every 5 minutes (300000ms)
  133. if (millis() - lastCheckTime > 300000) {
  134. checkPuzzleStatus();
  135. }
  136.  
  137. // Update statistics every second
  138. static unsigned long lastUpdate = 0;
  139. if (millis() - lastUpdate > 1000) {
  140. updateDisplayStats("Refreshing...", TFT_WHITE);
  141. lastUpdate = millis();
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement