I tried making some minor changes and updating my cryptoticker and it failed with, “error loading data.”

After some searches I found this open ticket on github, https://github.com/witnessmenow/arduino-coinmarketcap-api/issues/4

Although it was working before hand, it should still have worked and I was stumped as to why it was failing. Some comments mentioned the API had changed, another comment mentioned it was still working for them. I decided to rewrite the code using a different, free API, as suggested per this comment: https://github.com/witnessmenow/arduino-coinmarketcap-api/issues/4#issuecomment-444731941

Here is what I came up with:

Download - View Code

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h> //need to use version < 6, I'm using version 5.12.0
#include "SH1106.h"

#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager


// Pins based on your wiring
#define SCL_PIN D5
#define SDA_PIN D3


SH1106 display(0x3c, SDA_PIN, SCL_PIN);


float ripple_usd;
float ripple_usd_24h_change;


void setup() {
  Serial.begin(115200);
    //WiFiManager
    WiFiManager wifiManager;
    wifiManager.autoConnect("CryptoTicker"); //if no known WiFi connections available, creates CryptoTicker WiFi which can be used to set the cryptoticker to connect to another WiFi from your phone, for me it set to 192.168.4.1


 
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi Connected.");
    delay(1000);
  }


  //boot title
  display.init();
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_16);
  display.drawString(64, 20, F("CryptoTicker"));
  display.display();
  delay(2000);

  
}


void loop() {
  // Check WiFi Status
    if (WiFi.status() == WL_CONNECTED) {
    Serial.println("Connected!");
    
    HTTPClient http;  //Object of class HTTPClient

    //using the coingecko api, see their documentation, to add coins seperate with commas



    //using https://www.coingecko.com/api/documentations/v3 -- they have a URL generator, but basically just seperate your currencies with commas, example: ripple,bitcoin,litecoin in the URL
    //I found the URL has to end in a trailing slash or it won't work and will return a -1 error code for the http response so I added &/ on the end of the URL
    String api="https://api.coingecko.com/api/v3/simple/price?ids=ripple&vs_currencies=usd&include_24hr_change=true&/";

    //used https://www.grc.com/fingerprints.htm to get fingerprint for the JSON URL
    String thumbprint="BB:53:CF:D0:70:1C:34:D3:51:0B:76:65:1E:4F:52:63:38:A3:FE:BE"; 

    
   
    http.begin(api, thumbprint);
    //http.addHeader("Content-Type", "application/json"); 
    int httpCode = http.GET();
    Serial.println(httpCode);
    //Check the returning code                                                                  
    if (httpCode == HTTP_CODE_OK) {
      // Parsing
      // generated with https://arduinojson.org/v5/assistant/
      // regenerate with new api URL if adding coins
    
      //from here -------------------------
      
      const size_t capacity = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + 60;
      DynamicJsonBuffer jsonBuffer(capacity);

      String payload = http.getString();
      
       
      JsonObject& root = jsonBuffer.parseObject(payload);
      
      ripple_usd = root["ripple"]["usd"]; 
      ripple_usd_24h_change = root["ripple"]["usd_24h_change"]; 
      
      //to here -------------------------
          
      
    }
    http.end();   //Close connection

    }
    
  displayValue();  
  displayHolding();
  

}

//display value of XRP and 24 hour change
//copa pasta code with new variables if adding coins
void displayValue(){ 

  display.clear();

  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_16);
  display.drawString(64, 0, F("XRP"));
  
  display.setFont(ArialMT_Plain_24);
  display.drawString(64, 20, "$" + String(ripple_usd));
  
  display.setFont(ArialMT_Plain_16);
  display.drawString(64, 48, "24h: " + String(ripple_usd_24h_change) + "%");
  
  display.display();
  delay(15000); //display current price for 15 seconds

}

//display my holdings
void displayHolding(){
  display.clear();

  int holdings = 0; //set this to the amount of coins you have

  int value = ripple_usd*holdings;
  
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  
  display.setFont(ArialMT_Plain_16);
  display.drawString(64, 0, F("XRP"));

  display.setFont(ArialMT_Plain_24);
  display.drawString(64, 20, "$" + String(value));
  display.display();
  delay(3000); // display holdings for 3 seconds

  
}