-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesp8266-bitcoin-ssid-ticker.ino
63 lines (48 loc) · 1.58 KB
/
esp8266-bitcoin-ssid-ticker.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "my ssid"; //This is where you put in your home network's SSID to connect to
const char* password = "my password"; //This is where you put in your home network's password
const String url = "http://api.coindesk.com/v1/bpi/currentprice.json";
HTTPClient http;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.print("Connecting to '");
Serial.print(ssid);
Serial.print("' ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print(" connected!");
Serial.print("My IP is: ");
Serial.println(WiFi.localIP());
}
void loop() {
//Some boards have issues using wifi while softAP is up, so we shut it down to fetch a fresh price
WiFi.softAPdisconnect(false);
WiFi.enableAP(false);
http.begin(url);
int code = http.GET();
if (code == 200) {
String payload = http.getString();
DynamicJsonDocument jsonBuffer(1100);
deserializeJson(jsonBuffer, payload);
JsonObject bpi = jsonBuffer["bpi"];
JsonObject bpi_EUR = bpi["EUR"];
int last = bpi_EUR["rate_float"];
String sSSID = "📈 1 bitcoin = € ";
sSSID += last;
sSSID += ",-";
WiFi.softAP(sSSID.c_str());
} else {
Serial.print("Failed to request coindesk API - is the internet connection active? Return code: ");
Serial.println(code);
WiFi.softAP("😥 Help me I'm broken!");
}
http.end();
delay(60000); //Coindesk's API updates once a minute
}