Add GitHub workflow and S3 mini targets
This commit is contained in:
parent
dbf7cc46d1
commit
082d61c84e
11 changed files with 262 additions and 25 deletions
|
@ -19,6 +19,24 @@ void setupTime()
|
|||
void setupPreferences()
|
||||
{
|
||||
preferences.begin("btclock", false);
|
||||
|
||||
if (!preferences.isKey(SETTING_ROW1_CONTENT))
|
||||
{
|
||||
preferences.putUInt(SETTING_ROW1_CONTENT, LINE_BLOCKHEIGHT);
|
||||
}
|
||||
if (!preferences.isKey(SETTING_ROW2_CONTENT))
|
||||
{
|
||||
preferences.putUInt(SETTING_ROW2_CONTENT, LINE_SATSPERUNIT);
|
||||
}
|
||||
if (!preferences.isKey(SETTING_ROW3_CONTENT))
|
||||
{
|
||||
preferences.putUInt(SETTING_ROW3_CONTENT, LINE_MEMPOOL_FEES);
|
||||
}
|
||||
|
||||
if (!preferences.isKey(SETTING_CURRENCY))
|
||||
{
|
||||
preferences.putString(SETTING_CURRENCY, CURRENCY_USD);
|
||||
}
|
||||
}
|
||||
|
||||
void setupWifi()
|
||||
|
|
18
src/data.cpp
18
src/data.cpp
|
@ -6,6 +6,9 @@ const String mempoolPriceApiUrl = mempoolInstance + "/api/v1/prices";
|
|||
const String mempoolBlockApiUrl = mempoolInstance + "/api/blocks/tip/height";
|
||||
const String mempoolFeeApiUrl = mempoolInstance + "/api/v1/fees/recommended";
|
||||
|
||||
uint lastPrice;
|
||||
uint lastBlock;
|
||||
|
||||
uint getPrice()
|
||||
{
|
||||
HTTPClient http;
|
||||
|
@ -22,10 +25,10 @@ uint getPrice()
|
|||
String payload = http.getString();
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, payload);
|
||||
usdPrice = doc["USD"].as<uint>();
|
||||
eurPrice = doc["EUR"].as<uint>();
|
||||
|
||||
return usdPrice;
|
||||
lastPrice = doc[preferences.getString(SETTING_CURRENCY)].as<uint>();
|
||||
|
||||
return lastPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -36,7 +39,7 @@ uint getPrice()
|
|||
return 0;
|
||||
}
|
||||
|
||||
String getBlock()
|
||||
uint getBlock()
|
||||
{
|
||||
HTTPClient http;
|
||||
|
||||
|
@ -49,9 +52,10 @@ String getBlock()
|
|||
uint usdPrice, eurPrice;
|
||||
if (httpCode == 200)
|
||||
{
|
||||
String payload = http.getString();
|
||||
uint payload = http.getString().toInt();
|
||||
|
||||
return payload;
|
||||
lastBlock = payload;
|
||||
return lastBlock;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,7 +63,7 @@ String getBlock()
|
|||
}
|
||||
http.end();
|
||||
|
||||
return "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
String getMempoolFees()
|
||||
|
|
|
@ -8,5 +8,5 @@
|
|||
#include "shared.hpp"
|
||||
|
||||
uint getPrice();
|
||||
String getBlock();
|
||||
uint getBlock();
|
||||
String getMempoolFees();
|
|
@ -89,7 +89,7 @@ void loop()
|
|||
}
|
||||
}
|
||||
|
||||
String block = getBlock();
|
||||
String block = String(getBlock());
|
||||
|
||||
uint tryCount = 0;
|
||||
while (block.equals(""))
|
||||
|
|
|
@ -56,13 +56,28 @@
|
|||
#define ICON_CHECK "Q"
|
||||
#define ICON_WARNING "R"
|
||||
|
||||
#define SETTING_ROW1_CONTENT "row1"
|
||||
#define SETTING_ROW2_CONTENT "row2"
|
||||
#define SETTING_ROW3_CONTENT "row3"
|
||||
#define SETTING_CURRENCY "currency"
|
||||
|
||||
const int LINE_BLOCKHEIGHT = 0;
|
||||
const int LINE_HALVING_COUNTDOWN = 1;
|
||||
const int LINE_SATSPERDOLLAR = 2;
|
||||
const int LINE_FIATPRICE = 3;
|
||||
const int LINE_MEMPOOL_FEES = 4;
|
||||
const int LINE_TIME = 5;
|
||||
const int LINE_DATE = 6;
|
||||
const int LINE_MEMPOOL_FEES = 1;
|
||||
const int LINE_MEMPOOL_FEES_MEDIAN = 2;
|
||||
const int LINE_HALVING_COUNTDOWN = 10;
|
||||
const int LINE_SATSPERUNIT = 20;
|
||||
const int LINE_FIATPRICE = 30;
|
||||
const int LINE_MARKETCAP = 40;
|
||||
const int LINE_TIME = 99;
|
||||
const int LINE_DATE = 100;
|
||||
|
||||
#define CURRENCY_USD "USD"
|
||||
#define CURRENCY_EUR "EUR"
|
||||
#define CURRENCY_GBP "GBP"
|
||||
#define CURRENCY_CAD "CAD"
|
||||
#define CURRENCY_CHF "CHF"
|
||||
#define CURRENCY_AUD "AUD"
|
||||
#define CURRENCY_JPY "JPY"
|
||||
|
||||
extern WiFiClientSecure client;
|
||||
extern GxEPD2_BW<EPD_CLASS, EPD_CLASS::HEIGHT> display;
|
||||
|
|
|
@ -2,12 +2,20 @@
|
|||
#include <LittleFS.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
String uintSettings[] = {SETTING_ROW1_CONTENT, SETTING_ROW2_CONTENT, SETTING_ROW3_CONTENT};
|
||||
|
||||
void setupWebserver() {
|
||||
if (!LittleFS.begin(true)) {
|
||||
void setupWebserver()
|
||||
{
|
||||
if (!LittleFS.begin(true))
|
||||
{
|
||||
Serial.println(F("An Error has occurred while mounting LittleFS"));
|
||||
}
|
||||
|
||||
server.on("/api/settings", HTTP_GET, onApiSettingsGet);
|
||||
AsyncCallbackJsonWebHandler *settingsPatchHandler =
|
||||
new AsyncCallbackJsonWebHandler("/api/json/settings", onApiSettingsPatch);
|
||||
server.addHandler(settingsPatchHandler);
|
||||
|
||||
server.serveStatic("/build", LittleFS, "/build");
|
||||
|
||||
server.on("/", HTTP_GET, onIndex);
|
||||
|
@ -20,17 +28,54 @@ void setupWebserver() {
|
|||
server.begin();
|
||||
}
|
||||
|
||||
void onIndex(AsyncWebServerRequest *request) {
|
||||
void onApiSettingsGet(AsyncWebServerRequest *request)
|
||||
{
|
||||
JsonDocument root;
|
||||
for (String setting : uintSettings)
|
||||
{
|
||||
root[setting] = preferences.getUInt(setting.c_str());
|
||||
}
|
||||
|
||||
AsyncResponseStream *response =
|
||||
request->beginResponseStream("application/json");
|
||||
serializeJson(root, *response);
|
||||
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
|
||||
{
|
||||
JsonObject settings = json.as<JsonObject>();
|
||||
|
||||
for (String setting : uintSettings)
|
||||
{
|
||||
if (settings.containsKey(setting))
|
||||
{
|
||||
preferences.putUInt(setting.c_str(), settings[setting].as<uint>());
|
||||
Serial.printf("Setting %s to %d\r\n", setting.c_str(),
|
||||
settings[setting].as<uint>());
|
||||
}
|
||||
}
|
||||
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
void onIndex(AsyncWebServerRequest *request)
|
||||
{
|
||||
request->send(LittleFS, "/index.html", String(), false);
|
||||
}
|
||||
|
||||
void onNotFound(AsyncWebServerRequest *request) {
|
||||
if (request->method() == HTTP_OPTIONS ||
|
||||
request->hasHeader("Sec-Fetch-Mode")) {
|
||||
void onNotFound(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->method() == HTTP_OPTIONS ||
|
||||
request->hasHeader("Sec-Fetch-Mode"))
|
||||
{
|
||||
// Serial.printf("NotFound, Return[%d]\n", 200);
|
||||
|
||||
request->send(200);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serial.printf("NotFound, Return[%d]\n", 404);
|
||||
request->send(404);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
// Keep order of includes because of conflicts
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "AsyncJson.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <shared.hpp>
|
||||
|
||||
void setupWebserver();
|
||||
|
||||
void onApiSettingsGet(AsyncWebServerRequest *request);
|
||||
void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json);
|
||||
|
||||
void onIndex(AsyncWebServerRequest *request);
|
||||
void onNotFound(AsyncWebServerRequest *request);
|
Loading…
Add table
Add a link
Reference in a new issue