Skip to content

Instantly share code, notes, and snippets.

@normandmickey
Created October 26, 2019 18:41
Show Gist options
  • Save normandmickey/51481a74b2daf23c1ffc766d24253295 to your computer and use it in GitHub Desktop.
Save normandmickey/51481a74b2daf23c1ffc766d24253295 to your computer and use it in GitHub Desktop.
M5Stack
#include <ezTime.h>
#include <M5ez.h>
#include <M5Stack.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
void setup() {
ez.begin();
}
void loop() {
ezMenu myMenu;
myMenu.addItem("Bitcoin Price", mainmenu_one);
myMenu.addItem("Lightning Invoice", mainmenu_two);
myMenu.addItem("Settings", mainmenu_three);
myMenu.run();
}
void mainmenu_one() {
HTTPClient client;
client.begin("https://api.opennode.co/v1/rates");
int httpCode = client.GET();
if (httpCode >0) {
const size_t capacity = 162*JSON_OBJECT_SIZE(1) + 8*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(169) + 2110;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, client.getString());
JsonObject data = doc["data"];
ez.msgBox("", data["BTCUSD"]["USD"]);
}
client.end();
}
void mainmenu_two() {
HTTPClient client;
client.begin("https://api.opennode.co/v1/charges");
client.addHeader("Content-Type", "application/json");
client.addHeader("Authorization", "046ef527-db76-47da-ab5b-b3ce2e64996c");
client.POST("{\"amount\":\"10\"}");
const size_t capacity = 2*JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(19) + 950;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, client.getString());
JsonObject data = doc["data"];
//ez.msgBox("", data["lightning_invoice"]["payreq"]);
const char* lnInvoice = data["lightning_invoice"]["payreq"];
ez.screen.clear();
M5.begin();
M5.Lcd.qrcode(lnInvoice);
delay(10000);
client.end();
}
void mainmenu_three() {
ez.settings.menu();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment