Skip to content

Commit 559eaa5

Browse files
committed
Add some coins
1 parent 95e142d commit 559eaa5

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
# arduino-crypto-tracker
3-
It works only with the price of bitcoin (coindesk API), in the future it is planned to transfer to the coinmarketcap API.
3+
Version 0.3 supports 12 coins (bitcoin, ethereum, litecoin, waves, binance coin, monero, stellar, cake, bsw, eos, dogecoin, zcash), can be increased to 100 or even more.
4+
A request to the coinmarketcap API occurs every 5 minutes. Coins change every 25 seconds (5 minutes / number of coins).
5+
6+
Now there is a separate server between the coinmarketcap and the wifi module, which simply removes unnecessary data from the coinmarketcap response. This is necessary because the wifi module can process a JSON object of no more than 4096 kilobytes.
47

58
## Components
69
* Arduino Uno

api/api.ino

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const char* password = "84570550";
88

99
const int timeout = 300000; // timeout between next API query
1010

11-
const String API_URL = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest";
12-
const String CRYPTO = "?slug=bitcoin,ethereum,litecoin";
11+
const String API_URL = "https://cmc-reducer.herokuapp.com/crypto";
12+
const String CRYPTO = "?slug=bitcoin,ethereum,litecoin,waves,binance-coin,monero,stellar,pancakeswap,biswap,eos,dogecoin,zcash";
1313
#define API_KEY "2831fae4-a23b-4b17-85ee-cce0a4520df2"
1414

1515
void setup() {
@@ -20,7 +20,7 @@ void setup() {
2020
WiFi.begin(ssid, password);
2121
while (WiFi.status() != WL_CONNECTED) {
2222
delay(500);
23-
// Serial.print(".");
23+
Serial.print(".");
2424
}
2525
Serial.print("WiFi ok.");
2626
}
@@ -48,22 +48,24 @@ void getData() {
4848
String payload = http.getString();
4949

5050
String json_str = String(payload);
51+
5152
DynamicJsonDocument doc(4096);
5253
DeserializationError error = deserializeJson(doc, payload);
53-
54-
JsonObject data = doc["data"];
54+
if (error) {
55+
Serial.print(F("json failed:,"));
56+
Serial.print(error.c_str());
57+
return;
58+
}
59+
JsonArray data = doc["data"];
60+
int arraySize = data.size();
5561

56-
for (JsonPair key : data) {
57-
JsonObject crypto = data[key.key().c_str()];
58-
String ticker = crypto["name"];
59-
60-
// get price
61-
JsonObject quote = crypto["quote"];
62-
JsonObject usd = quote["USD"];
63-
String price = usd["price"];
62+
for (int i = 0; i < arraySize; i++) {
63+
JsonObject crypto = data[i];
64+
String name = crypto["name"];
65+
String price = crypto["price"];
6466

65-
Serial.print(ticker + ",$" + price);
66-
delay(timeout / data.size());
67+
Serial.print(name + ",$" + price);
68+
delay(timeout / arraySize);
6769
}
6870
}
6971
http.end();

0 commit comments

Comments
 (0)