ESP12e Crypto Ticker, Almost complete.

Hello everyone.

I have been trying to get a crypto "ticker" working for a little while now. I am almost there with it, but could use some help with the final part (if anybody would be interested in helping).

I am using an esp12e board along with esp8266. I have managed to get the board to connect to my home WiFi, and can even connect to the server I need and get data from it. The problem I am now having is getting that data to display correctly on the display. At the moment I can display the RAW data, but that is not what I need. Below is the code that I have found, and adapted to make work so far:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <Wire.h>
#include "SSD1306.h"

#define SDA D2
#define SCL D1
#define I2C 0x3C

SSD1306 display(I2C, SDA, SCL);



void setup() {
  Serial.begin(115200);

  // Initialize display
  display.init();
  display.flipScreenVertically();
  display.clear();
  display.drawString(35, 1, "Value Test");
  display.display();
  
  Serial.println(F("\n\r* * * ESP BOOT * * *"));
  Serial.println(F("WiFi begin!"));
  WiFi.mode(WIFI_STA);
  WiFi.begin("XXX SSID XXX", "XXX PASSWORD XXX");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println(F("\n\rWiFi connected!"));
}

void getpr24h() {
  std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
  client->setInsecure();
  HTTPClient https;

  if (https.begin(*client, "https://api.coingecko.com/api/v3/simple/price?ids=geodb%2Cxyo-network%2Cethereum&vs_currencies=usd")) {  // HTTPS
    Serial.println("[HTTPS] GET...");
    int httpCode = https.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
      // file found at server?
      if (httpCode == HTTP_CODE_OK) {
        String payload = https.getString();
        Serial.println(String("[HTTPS] Received payload: ") + payload);
        Serial.println(String("1GEO = ") + payload + "USD");
        display.drawString(1, 15, payload);
        display.display();
      }
    } else {
      Serial.printf("[HTTPS] GET... failed, error: %s\n\r", https.errorToString(httpCode).c_str());
    }

    https.end();
  } else {
    Serial.printf("[HTTPS] Unable to connect\n\r");
  }
}

void loop() {
  getpr24h();
  Serial.println("Wait 20s before next round to not get banned on API server...");
  delay(20000);
}

Here is a link to the server. If you visit it, you will see the data required. If you click on "RAW" in the top tab, this is exactly what is displayed on my screen (which is obviously no good):

{"ethereum":{"usd":2144.22},"xyo-network":{"usd":0.00630442},"geodb":{"usd":1.43}}

Looking through other examples online, it would seem that I need to use json to filter through the returned payload, and take out everything that doesn't need to be displayed. I have absolutely no idea how to do this. I have looked through other example sketches and cant seemt o work out how to transfer over the parts needed.

Could anybody help?

Thank you for reading through this, sorry to have rambled on a bit.

Tim

How to parse JSON Data with Arduino (ArduinoJson Tutorial)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.