From 28a1bbf30d92a865ac8a25b9791bce8de4f87733 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Tue, 20 Aug 2024 00:02:10 +0100 Subject: [PATCH 1/2] Pulled online --- lnpos/100_config.ino | 56 ------ lnpos/lnpos.ino | 458 +------------------------------------------ 2 files changed, 3 insertions(+), 511 deletions(-) diff --git a/lnpos/100_config.ino b/lnpos/100_config.ino index 5c6cb51..ccbdabd 100644 --- a/lnpos/100_config.ino +++ b/lnpos/100_config.ino @@ -128,14 +128,10 @@ void readFiles() lnurlPoS = getJsonValue(doc, "config_lnurlpos"); lnurlATM = getJsonValue(doc, "config_lnurlatm"); masterKey = getJsonValue(doc, "config_masterkey"); - lnbitsServer = getJsonValue(doc, "config_server"); - invoice = getJsonValue(doc, "config_invoice"); lncurrency = getJsonValue(doc, "config_lncurrency"); lnurlATMMS = getJsonValue(doc, "config_lnurlatmms"); lnurlATMPin = getJsonValue(doc, "config_lnurlatmpin"); decimalplaces = getJsonValue(doc, "config_decimalplaces"); - ssid = getJsonValue(doc, "config_wifi_ssid"); - password = getJsonValue(doc, "config_wifi_password"); } ////////LNURL PoS string///////// @@ -191,34 +187,6 @@ void readFiles() Serial.println("MasterKey not set"); } - //////////Lnbits Server///////// - if (lnbitsServer != "null" || lnbitsServer != "") - { - Serial.println(""); - Serial.println("lnbitsServer used from memory"); - Serial.println("lnbitsServer: " + lnbitsServer); - } - else - { - Serial.println("lnbitsServer not set"); - } - - /////////LNbits Server/////// - if (invoice != "null" || invoice != "") - { - Serial.println(""); - Serial.println("invoice key used from memory"); - Serial.println("invoice key: " + invoice); - if (invoice != "") - { - menuItemCheck[0] = 1; - } - } - else - { - Serial.println("invoice key not set"); - } - /////////PoS Currency/////// if (lncurrency != "null" || lncurrency != "") { @@ -267,30 +235,6 @@ void readFiles() { Serial.println("no. fiat decimal places not set"); } - - /////////WiFi SSID/////// - if (ssid != "null" || ssid != "") - { - Serial.println(""); - Serial.println("WiFi SSID used from memory"); - Serial.println("WiFi SSID: " + ssid); - } - else - { - Serial.println("WiFi SSID not set"); - } - - /////////WiFi password/////// - if (decimalplaces != "null" || decimalplaces != "") - { - Serial.println(""); - Serial.println("WiFi password used from memory"); - Serial.println("WiFi password: " + password); - } - else - { - Serial.println("WiFi password not set"); - } } paramFile.close(); } diff --git a/lnpos/lnpos.ino b/lnpos/lnpos.ino index 88827ad..354262c 100644 --- a/lnpos/lnpos.ino +++ b/lnpos/lnpos.ino @@ -1,9 +1,6 @@ -#include -#include #include #include #include -using WebServerClass = WebServer; fs::SPIFFSFS &FlashFS = SPIFFS; #define FORMAT_ON_FAIL true #include @@ -14,7 +11,6 @@ fs::SPIFFSFS &FlashFS = SPIFFS; #include #include "qrcoded.h" #include "Bitcoin.h" -#include #define PARAM_FILE "/elements.json" #define KEY_FILE "/thekey.txt" @@ -35,14 +31,10 @@ bool hardcoded = false; /// Set to true to hardcode String lnurlPoS = "https://legend.lnbits.com/lnurldevice/api/v1/lnurl/WTmei,BzzoY5wbgpym3eMdb9ueXr,USD"; String lnurlATM = "https://legend.lnbits.com/lnurldevice/api/v1/lnurl/W5xu4,XGg4BJ3xCh36JdMKm2kgDw,USD"; String masterKey = "xpub6CJFgwcim8tPBJo2A6dS13kZxqbgtWKD3LKj1tyurWADbXbPyWo11exyotTSUY3cvhQy5Mfj8FSURgpXhc4L2UvQyaTMC36S49JnNJMmcWU"; -String lnbitsServer = "https://legend.lnbits.com"; -String invoice = "37d45d3e1f0d4572a905bad544588d7d"; String lncurrency = "GBP"; String lnurlATMMS = "https://mempool.space"; String lnurlATMPin = "878787"; String decimalplaces = "2"; -String ssid = "AlansBits"; -String password = "ithurtswhenip"; ////////////////////////////////////////////////// @@ -73,10 +65,10 @@ String amountToShow = "0"; String key_val; String selection; -const char menuItems[5][13] = {"LNPoS", "Offline PoS", "OnChain", "ATM", "Settings"}; +const char menuItems[5][13] = {"Offline PoS", "OnChain", "Offline ATM", "Settings"}; const char currencyItems[3][5] = {"sat", "USD", "EUR"}; char decimalplacesOutput[20]; -int menuItemCheck[5] = {0, 0, 0, 0, 1}; +int menuItemCheck[5] = {0, 0, 0, 1}; int menuItemNo = 0; int randomPin; int calNum = 1; @@ -88,7 +80,6 @@ long timeOfLastInteraction = millis(); bool isSleepEnabled = true; bool isPretendSleeping = false; bool onchainCheck = false; -bool lnCheck = false; bool lnurlCheck = false; bool unConfirmed = true; bool selected = false; @@ -97,7 +88,6 @@ bool lnurlCheckATM = false; double amountToShowNumber; enum InvoiceType { - LNPOS, LNURLPOS, ONCHAIN, LNURLATM, @@ -178,33 +168,6 @@ void setup() checkHardcoded(); readFiles(); - // connect to configured WiFi - int wifiCounter = 0; - if (menuItemCheck[0]) - { - delay(1000); - processing("Connecting to wifi"); - WiFi.mode(WIFI_STA); // Optional - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED && wifiCounter < 30) - { - Serial.print("."); - delay(100); - wifiCounter++; - } - if (WiFi.status() == WL_CONNECTED) - { - processing("Connected to wifi"); - delay(3000); - } - else - { - error("Error", "WiFi failed", ""); - delay(3000); - } - } - delay(2000); } @@ -217,16 +180,6 @@ void loop() unConfirmed = true; key_val = ""; - // check wifi status - if (menuItemCheck[0] == 1 && WiFi.status() != WL_CONNECTED) - { - menuItemCheck[0] = -1; - } - else if (menuItemCheck[0] == -1 && WiFi.status() == WL_CONNECTED) - { - menuItemCheck[0] = 1; - } - // count menu items int menuItemsAmount = 0; @@ -250,11 +203,6 @@ void loop() { menuLoop(); } - - if (selection == "LNPoS") - { - lnMain(); - } else if (selection == "OnChain") { onchainMain(); @@ -294,14 +242,10 @@ void checkHardcoded() lnurlPoS = ""; lnurlATM = ""; masterKey = ""; - lnbitsServer = ""; - invoice = ""; lncurrency = ""; lnurlATMMS = ""; lnurlATMPin = ""; decimalplaces = ""; - ssid = ""; - password = ""; } } @@ -439,128 +383,6 @@ void onchainMain() } } -void lnMain() -{ - readFiles(); - - if (!checkOnlineParams()) - { - return; - } - - if (lncurrency == "" || lncurrency == "default") - { - currencyLoop(); - } - - processing("FETCHING FIAT RATE"); - if (!getSats()) - { - error("FETCHING FIAT RATE FAILED"); - delay(3000); - return; - } - - isLNMoneyNumber(true); - - while (unConfirmed) - { - key_val = ""; - getKeypad(false, false, true, false); - - if (key_val == "*") - { - unConfirmed = false; - } - else if (key_val == "#") - { - if (noSats.toInt() == 0) - { - error("ZERO SATS"); - delay(3000); - isLNMoneyNumber(true); - continue; - } - - // request invoice - processing("FETCHING INVOICE"); - if (!getInvoice()) - { - unConfirmed = false; - error("ERROR FETCHING INVOICE"); - delay(3000); - break; - } - - // show QR - qrShowCodeln(); - - // check invoice - bool isFirstRun = true; - while (unConfirmed) - { - int timer = 0; - - if (!isFirstRun) - { - unConfirmed = checkInvoice(); - if (!unConfirmed) - { - paymentSuccess(); - timer = 5000; - - while (key_val != "*") - { - key_val = ""; - getKeypad(false, true, false, false); - - if (key_val != "*") - { - delay(100); - } - } - } - } - - // abort on * press - while (timer < (isFirstRun ? 6000 : 2000)) - { - getKeypad(false, true, false, false); - - if (key_val == "*") - { - noSats = "0"; - dataIn = "0"; - formatNumber(0, decimalplaces.toInt(), decimalplacesOutput); - amountToShow = decimalplacesOutput; - unConfirmed = false; - timer = 5000; - break; - } - else - { - delay(100); - handleBrightnessAdjust(key_val, LNPOS); - key_val = ""; - } - timer = timer + 100; - } - - isFirstRun = false; - } - - noSats = "0"; - dataIn = "0"; - formatNumber(0, decimalplaces.toInt(), decimalplacesOutput); - amountToShow = decimalplacesOutput; - } - else - { - delay(100); - } - } -} - void lnurlPoSMain() { inputs = ""; @@ -722,11 +544,6 @@ void getKeypad(bool isATMPin, bool justKey, bool isLN, bool isATMNum) { dataIn += key_val; } - - if (isLN) - { - isLNMoneyNumber(false); - } else if (isATMPin) { isATMMoneyPin(false); @@ -769,45 +586,6 @@ void configLaunch(String title) // tft.println(config.apid); } -void isLNMoneyNumber(bool cleared) -{ - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextSize(2); - tft.setCursor(0, 20); - tft.print(" - ENTER AMOUNT -"); - tft.setTextSize(3); - tft.setCursor(0, 50); - tft.println(String(lncurrency) + ": "); - tft.println("SAT: "); - tft.setCursor(0, 120); - tft.setTextSize(2); - tft.println(" *MENU #INVOICE"); - - if (!cleared) - { - amountToShowNumber = dataIn.toFloat() / pow(10, decimalplaces.toInt()); - formatNumber(amountToShowNumber, decimalplaces.toInt(), decimalplacesOutput); - amountToShow = String(decimalplacesOutput); - noSats = String(converted * amountToShowNumber); - } - else - { - noSats = "0"; - dataIn = "0"; - formatNumber(0, decimalplaces.toInt(), decimalplacesOutput); - amountToShow = decimalplacesOutput; - } - - tft.setTextSize(3); - tft.setTextColor(TFT_RED, TFT_BLACK); - tft.setCursor(75, 50); - tft.println(amountToShow); - tft.setTextColor(TFT_GREEN, TFT_BLACK); - tft.setCursor(75, 75); - tft.println(noSats.toInt()); -} - void isLNURLMoneyNumber(bool cleared) { tft.fillScreen(TFT_BLACK); @@ -922,38 +700,6 @@ void inputScreenOnChain() tft.println(" *MENU #ADDRESS"); } -void qrShowCodeln() -{ - tft.fillScreen(qrScreenBgColour); - - qrData.toUpperCase(); - const char *qrDataChar = qrData.c_str(); - QRCode qrcoded; - uint8_t qrcodeData[qrcode_getBufferSize(20)]; - - qrcode_initText(&qrcoded, qrcodeData, 11, 0, qrDataChar); - - for (uint8_t y = 0; y < qrcoded.size; y++) - { - for (uint8_t x = 0; x < qrcoded.size; x++) - { - if (qrcode_getModule(&qrcoded, x, y)) - { - tft.fillRect(65 + 2 * x, 5 + 2 * y, 2, 2, TFT_BLACK); - } - else - { - tft.fillRect(65 + 2 * x, 5 + 2 * y, 2, 2, qrScreenBgColour); - } - } - } - - tft.setCursor(0, 220); - tft.setTextSize(2); - tft.setTextColor(TFT_BLACK, TFT_WHITE); - tft.print(" *MENU"); -} - void qrShowCodeOnchain(bool anAddress, String message) { tft.fillScreen(qrScreenBgColour); @@ -1070,18 +816,6 @@ void processing(String message) tft.println(message); } -void paymentSuccess() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_GREEN, TFT_BLACK); - tft.setTextSize(3); - tft.setCursor(70, 50); - tft.println("PAID"); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextSize(2); - tft.println(" PRESS * FOR MENU"); -} - void showPin() { tft.fillScreen(TFT_BLACK); @@ -1332,42 +1066,6 @@ void menuLoop() } } -bool checkOnlineParams() -{ - if (invoice != "" && invoice.length() != 32) - { - error("WRONG INVOICE"); - delay(3000); - return false; - } - - const char *decimal = decimalplaces.c_str(); - if (!isInteger(decimal)) - { - error("WRONG DECIMAL"); - delay(3000); - return false; - } - - lnbitsServer.toLowerCase(); - - if (lnbitsServer != "") - { - const char *lnServer = lnbitsServer.c_str(); - char lastChar = lnServer[strlen(lnServer) - 1]; - - if (lastChar == '/') - { - error("WRONG LNBITS"); - delay(3000); - - return false; - } - } - - return true; -} - bool checkOfflineParams() { if (baseURLPoS != "" && baseURLPoS.substring(0, 4) != "http") @@ -1394,153 +1092,7 @@ bool checkOfflineParams() return true; } -//////////LIGHTNING////////////////////// - -bool getSats() -{ - WiFiClientSecure client; - client.setInsecure(); // Some versions of WiFiClientSecure need this - - lnbitsServer.toLowerCase(); - if (lnbitsServer.substring(0, 8) == "https://") - { - lnbitsServer = lnbitsServer.substring(8, lnbitsServer.length()); - } - const char *lnbitsServerChar = lnbitsServer.c_str(); - const char *invoiceChar = invoice.c_str(); - const char *lncurrencyChar = lncurrency.c_str(); - - Serial.println("connecting to LNbits server " + lnbitsServer); - if (!client.connect(lnbitsServerChar, 443)) - { - Serial.println("failed to connect to LNbits server " + lnbitsServer); - return false; - } - - const String toPost = "{\"amount\" : 1, \"from\" :\"" + String(lncurrencyChar) + "\"}"; - const String url = "/api/v1/conversion"; - client.print(String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + String(lnbitsServerChar) + "\r\n" + "User-Agent: ESP32\r\n" + "X-Api-Key: " + String(invoiceChar) + " \r\n" + "Content-Type: application/json\r\n" + "Connection: close\r\n" + "Content-Length: " + toPost.length() + "\r\n" + "\r\n" + toPost + "\n"); - - while (client.connected()) - { - const String line = client.readStringUntil('\n'); - if (line == "\r") - { - break; - } - } - - const String line = client.readString(); - StaticJsonDocument<150> doc; - DeserializationError error = deserializeJson(doc, line); - if (error) - { - Serial.print("deserializeJson() failed: "); - Serial.println(error.f_str()); - return false; - } - - converted = doc["sats"]; - return true; -} - -bool getInvoice() -{ - WiFiClientSecure client; - client.setInsecure(); // Some versions of WiFiClientSecure need this - - lnbitsServer.toLowerCase(); - if (lnbitsServer.substring(0, 8) == "https://") - { - lnbitsServer = lnbitsServer.substring(8, lnbitsServer.length()); - } - const char *lnbitsServerChar = lnbitsServer.c_str(); - const char *invoiceChar = invoice.c_str(); - - if (!client.connect(lnbitsServerChar, 443)) - { - Serial.println("failed"); - error("SERVER DOWN"); - delay(3000); - return false; - } - - const String toPost = "{\"out\": false,\"amount\" : " + String(noSats.toInt()) + ", \"memo\" :\"LNPoS-" + String(random(1, 1000)) + "\"}"; - const String url = "/api/v1/payments"; - client.print(String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + lnbitsServerChar + "\r\n" + "User-Agent: ESP32\r\n" + "X-Api-Key: " + invoiceChar + " \r\n" + "Content-Type: application/json\r\n" + "Connection: close\r\n" + "Content-Length: " + toPost.length() + "\r\n" + "\r\n" + toPost + "\n"); - - while (client.connected()) - { - const String line = client.readStringUntil('\n'); - - if (line == "\r") - { - break; - } - } - const String line = client.readString(); - - StaticJsonDocument<1000> doc; - DeserializationError error = deserializeJson(doc, line); - if (error) - { - Serial.print("deserializeJson() failed: "); - Serial.println(error.f_str()); - return false; - } - - const char *payment_hash = doc["checking_id"]; - const char *payment_request = doc["payment_request"]; - qrData = payment_request; - dataId = payment_hash; - - Serial.println(qrData); - return true; -} - -bool checkInvoice() -{ - WiFiClientSecure client; - client.setInsecure(); // Some versions of WiFiClientSecure need this - - const char *lnbitsServerChar = lnbitsServer.c_str(); - const char *invoiceChar = invoice.c_str(); - if (!client.connect(lnbitsServerChar, 443)) - { - error("SERVER DOWN"); - delay(3000); - return false; - } - - const String url = "/api/v1/payments/"; - client.print(String("GET ") + url + dataId + " HTTP/1.1\r\n" + "Host: " + lnbitsServerChar + "\r\n" + "User-Agent: ESP32\r\n" + "Content-Type: application/json\r\n" + "Connection: close\r\n\r\n"); - while (client.connected()) - { - const String line = client.readStringUntil('\n'); - if (line == "\r") - { - break; - } - } - - const String line = client.readString(); - Serial.println(line); - StaticJsonDocument<2000> doc; - - DeserializationError error = deserializeJson(doc, line); - if (error) - { - Serial.print("deserializeJson() failed: "); - Serial.println(error.f_str()); - return false; - } - if (doc["paid"]) - { - unConfirmed = false; - } - - return unConfirmed; -} +//////////UTILS/////////////// String getValue(String data, char separator, int index) { @@ -1561,7 +1113,6 @@ String getValue(String data, char separator, int index) return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } -//////////UTILS/////////////// void to_upper(char *arr) { for (size_t i = 0; i < strlen(arr); i++) @@ -1774,9 +1325,6 @@ void adjustQrBrightness(bool shouldMakeBrighter, InvoiceType invoiceType) switch (invoiceType) { - case LNPOS: - qrShowCodeln(); - break; case LNURLPOS: qrShowCodeLNURL(" *MENU #SHOW PIN"); break; From 620955bc1cf8b2f9d40a668d54d64a24dc9a2b63 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Tue, 20 Aug 2024 01:18:03 +0100 Subject: [PATCH 2/2] could possibly finally maybe work --- .github/workflows/arduino.yml | 2 +- build.sh | 4 ++-- lnpos/lnpos.ino | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/arduino.yml b/.github/workflows/arduino.yml index b7d498a..b46082d 100644 --- a/.github/workflows/arduino.yml +++ b/.github/workflows/arduino.yml @@ -17,7 +17,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} platforms: | - - name: esp32:esp32@2.0.17 + - name: esp32:esp32@2.0.1 source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json sketch-paths: | - lnpos/lnpos.ino diff --git a/build.sh b/build.sh index 45d4d7a..48138e9 100644 --- a/build.sh +++ b/build.sh @@ -4,11 +4,11 @@ arduino-cli config --additional-urls https://raw.githubusercontent.com/espressif arduino-cli core update-index arduino-cli upgrade # uBitcoin is broken on esp32 3.x.x -arduino-cli core install esp32:esp32@2.0.17 +arduino-cli core install esp32:esp32@2.0.1 arduino-cli lib install ArduinoJson Base64 Keypad uBitcoin arduino-cli compile \ --build-property "build.partitions=min_spiffs" \ --build-property "upload.maximum_size=1966080" \ --library ./libraries/TFT_eSPI \ --library ./libraries/QRCode \ - --build-path build --fqbn esp32:esp32:ttgo-lora32 lnpos + --build-path build --fqbn esp32:esp32:ttgo-lora32-oled-v1 lnpos diff --git a/lnpos/lnpos.ino b/lnpos/lnpos.ino index 354262c..060ec2f 100644 --- a/lnpos/lnpos.ino +++ b/lnpos/lnpos.ino @@ -21,9 +21,7 @@ fs::SPIFFSFS &FlashFS = SPIFFS; bool format = false; //////////////////////////////////////////////////////// -////////////LNPOS WILL LOOK FOR DETAILS SET///////////// -////////OVER THE WEBINSTALLER CONFIG, HOWEVER/////////// -///////////OPTIONALLY SET HARDCODED DETAILS///////////// +//////////USE THE WEBINSTALLER OR SET THESE///////////// //////////////////////////////////////////////////////// bool hardcoded = false; /// Set to true to hardcode