//Code provided by TheResidentSkeptic, Youtube user. //Paste bin link https://pastebin.com/RKLbNCQ1 #include #include #include #include #include #include #include #include #include #define Serial Serial ESP8266WiFiMulti WiFiMulti; #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); float coin; void setup() { Serial.begin(115200); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } // Serial.setDebugOutput(true); Serial.println(); Serial.println(); Serial.println(); for (uint8_t t = 4; t > 0; t--) { // Serial.printf("[SETUP] WAIT %d...\n", t); Serial.flush(); } WiFi.mode(WIFI_STA); // provide our SSID and Password for WIFI network connection WiFiMulti.addAP("SSID", "PASSWORD"); } void loop() { // wait for WiFi connection if ((WiFiMulti.run() == WL_CONNECTED)) { HTTPClient http; http.begin("http://api.coindesk.com/v1/bpi/currentprice/CAD.json"); //HTTP URL for hosted server(local server) //192.168.43.161 - HOST PORT: 3000 and /api is the target api we need to hit to get response int httpCode = http.GET(); // Serial.println("After GET Request"); // httpCode will be negative on error if (httpCode > 0) { if (httpCode == HTTP_CODE_OK) { //HTTP_CODE_OK means code == 200 String payload = http.getString();// gives us the message received by the GET Request const size_t capacity = JSON_OBJECT_SIZE(2) + 2 * JSON_OBJECT_SIZE(3) + 2 * JSON_OBJECT_SIZE(4) + 480; DynamicJsonDocument doc(capacity); String json = payload; deserializeJson(doc, json); JsonObject time = doc["time"]; const char* time_updateduk = time["updateduk"]; // "Mar 21, 2020 at 02:43 GMT" JsonObject bpi_CAD = doc["bpi"]["CAD"]; const char* bpi_CAD_code = bpi_CAD["code"]; // "CAD" const char* bpi_CAD_rate = bpi_CAD["rate"]; // "8,991.6930" const char* bpi_CAD_description = bpi_CAD["description"]; // "Canadian Dollar" float bpi_CAD_rate_float = bpi_CAD["rate_float"]; // 8991.693 coin = bpi_CAD_rate_float; Serial.println(time_updateduk); Serial.print("Current Price: "); Serial.print("$"); Serial.print(coin); Serial.println(" CAD"); Serial.println(""); display.clearDisplay(); display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(20, 10); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font // Not all the characters will fit on the display. This is normal. // Library will draw what it can and the rest will be clipped. display.println("BITCOIN"); if ((coin <= 999.99)) { display.setCursor (27, 35); display.print("$"); display.println(coin, 2); } else if ((coin >= 1000.00) && (coin <= 9999.99)) { display.setCursor(15, 35); display.print("$"); display.println(coin, 2); } else if ((coin >= 10000.00)) { display.setCursor(5, 35); display.print("$"); display.println(coin, 2); } display.display(); display.setTextSize(1); // Normal 1:1 pixel scale display.setCursor(5 , 55); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); display.print(". "); delay(1000); display.display(); } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } }