Skip to content

Instantly share code, notes, and snippets.

@lxe
Created February 20, 2021 08:44
Show Gist options
  • Save lxe/772094e3fdbbcae6ffc6ab321d578e04 to your computer and use it in GitHub Desktop.
Save lxe/772094e3fdbbcae6ffc6ab321d578e04 to your computer and use it in GitHub Desktop.
// Be in Arduino
// Go to file -> preferences -> settings tab -> additional board manager URL
// Paste this: https://dl.espressif.com/dl/package_esp32_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json
// Go to tools -> board -> board manager
// Find "esp32" and install it
// Copy https://github.com/Bodmer/TFT_eSPI into C:\Users\you\Documents\Arduino\libraries
#include <TFT_eSPI.h>
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char *SSID = "YOUR WIFI SSID";
const char *WiFiPassword = "YOUR WIFI PASSWORD";
TFT_eSPI tft = TFT_eSPI();
uint32_t targetTime = 0;
String price;
void doTheThing () {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String serverPath = "https://api.cryptonator.com/api/ticker/doge-usd";
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
price = payload.substring(49, 56);
Serial.println(price);
tft.setTextColor(0x39C4, TFT_BLACK);
tft.drawString("888888", 0, 30, 7);
tft.setTextColor(0xFBE0, TFT_BLACK);
tft.drawString("DOGE", 0, 7, 4);
tft.drawString(price, 0, 30, 7);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
}
void ConnectToWiFi()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, WiFiPassword);
Serial.print("Connecting to ");
Serial.println(SSID);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(500);
if ((++i % 16) == 0)
{
Serial.println(F(" still trying to connect"));
}
}
Serial.print(F("Connected. My IP address is: "));
Serial.println(WiFi.localIP());
}
void setup(void) {
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
targetTime = millis() + 1000;
ConnectToWiFi();
doTheThing();
}
unsigned long lastTime = 0;
unsigned long timerDelay = 600000; // 10m
void loop() {
if ((millis() - lastTime) > timerDelay) {
doTheThing();
lastTime = millis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment