Created
May 16, 2022 16:47
-
-
Save pgrandin/dd68d65bc164dfcc2bf2c103098ede56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiClientSecure.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266HTTPClient.h> | |
#include <TM1637Display.h> | |
#include "config.h" | |
bool debug = false; | |
const int httpsPort = 443; | |
int CLK = D3; | |
int DIO = D4; | |
TM1637Display display(CLK, DIO); | |
void setup() { | |
Serial.begin(115200); | |
uint8_t data[] = { SEG_G, SEG_G, SEG_G, SEG_G }; | |
display.setBrightness(0x07); | |
display.setSegments(data); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.println("Connecting.."); | |
} | |
} | |
void loop() { | |
if (WiFi.status() == WL_CONNECTED) { | |
WiFiClientSecure client; | |
HTTPClient http; | |
client.setInsecure(); | |
client.connect(endpoint, httpsPort); | |
http.begin(client, endpoint); | |
http.addHeader("Authorization", token); | |
int httpCode = http.GET(); | |
if (httpCode > 0) { | |
String payload = http.getString(); | |
if (debug) { | |
Serial.println("CONNECTED"); | |
Serial.println(payload); | |
} | |
// Find the hashrates array | |
int hashrates_index = payload.indexOf("hashrates"); | |
int hashrates_end = payload.indexOf("hashrates_by_coin"); | |
String hashrates_string = payload.substring(hashrates_index, hashrates_end); | |
if (debug) { | |
Serial.println(hashrates_string); | |
} | |
// Get the hashrate value | |
int hashrate_index = hashrates_string.indexOf("\"hashrate\":"); | |
int hashrate_end = hashrates_string.indexOf("}"); | |
String hashrate_string = hashrates_string.substring(hashrate_index + strlen("\"hashrate\":"), hashrate_end); | |
// Convert hashrate to float | |
float hashrate = atof(hashrate_string.c_str()) / 1000; | |
Serial.println(hashrate); | |
display.showNumberDecEx(hashrate, 0, 0, 4); | |
} | |
http.end(); | |
} | |
delay(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment