Skip to content

Instantly share code, notes, and snippets.

@yakutozcan
Last active December 28, 2017 08:48
Show Gist options
  • Save yakutozcan/10620dd19ab8e618b254fcbf29fc5046 to your computer and use it in GitHub Desktop.
Save yakutozcan/10620dd19ab8e618b254fcbf29fc5046 to your computer and use it in GitHub Desktop.
bitcoin,esp8266,nodemcu,arduino,oled display,SSD1306
//yakutozcan.blogspot.com
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
#include <Wire.h>
#include "SSD1306.h"
//D1 ile D2 pinine bağlı ekran
SSD1306 display(0x3c, D1, D2);
#include <ArduinoJson.h>
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
display.init();
display.flipScreenVertically();
display.setContrast(255);
display.clear();
display.setFont(ArialMT_Plain_24);
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
for (uint8_t t = 0; t <= 4; t++) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
display.clear();
display.drawProgressBar(0, 32, 120, 10, t * 25);
display.drawString(64, 15, String(t * 25) + "%");
display.display();
delay(1000);
}
//Wifi ayarları
WiFiMulti.addAP("yakutozcan", "wifisifre");
}
void loop() {
if ((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
//Coin durumunu aldığımız borsa
http.begin("https://api.coinbase.com/v2/prices/spot?currency=USD", "B3 9C 3E 29 EF 32 9B 20 80 6E AC 2C F0 7C D9 D4 24 1A 2D C6"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
int httpCode = http.GET();
if (httpCode > 0) {
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
DynamicJsonBuffer jsonBuffer(capacity);
//JSON objesini parçaladığımız kısım
JsonObject& root = jsonBuffer.parseObject(payload);
JsonObject& data = root["data"];
const char* data_amount = data["amount"];
USE_SERIAL.println(data_amount);
display.clear();
display.drawString(64, 22, "1 BTC>USD");
display.drawString(64, 42, data_amount);
display.display();
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
//10sn bekleme
delay(10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment