From 11396e2649772c03b66e48d271702a81b85486ff Mon Sep 17 00:00:00 2001 From: axelhamburch Date: Sun, 15 Dec 2024 00:39:46 +0100 Subject: [PATCH 1/4] force wifi scanning --- bitcoinSwitch/bitcoinSwitch.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/bitcoinSwitch/bitcoinSwitch.ino b/bitcoinSwitch/bitcoinSwitch.ino index 13875bb..231c410 100644 --- a/bitcoinSwitch/bitcoinSwitch.ino +++ b/bitcoinSwitch/bitcoinSwitch.ino @@ -58,6 +58,7 @@ struct KeyValue { }; void setup() { + WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // Force scanning for all APs, not just the first one Serial.begin(115200); Serial.println("Welcome to BitcoinSwitch, running on version: " + version); bool triggerConfig = false; From e511180e33e27edda81a9093e701290946850728 Mon Sep 17 00:00:00 2001 From: axelhamburch Date: Sun, 15 Dec 2024 01:12:47 +0100 Subject: [PATCH 2/4] Correction of the position --- bitcoinSwitch/bitcoinSwitch.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoinSwitch/bitcoinSwitch.ino b/bitcoinSwitch/bitcoinSwitch.ino index 231c410..b87dd24 100644 --- a/bitcoinSwitch/bitcoinSwitch.ino +++ b/bitcoinSwitch/bitcoinSwitch.ino @@ -58,7 +58,6 @@ struct KeyValue { }; void setup() { - WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // Force scanning for all APs, not just the first one Serial.begin(115200); Serial.println("Welcome to BitcoinSwitch, running on version: " + version); bool triggerConfig = false; @@ -85,6 +84,7 @@ void setup() { Serial.println("Launch serial config"); configOverSerialPort(); } else { + WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // Force scanning for all APs, not just the first one WiFi.begin(ssid.c_str(), wifiPassword.c_str()); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { From 25054b2c47cd0aff1502a2d404981a9a47e144c1 Mon Sep 17 00:00:00 2001 From: axelhamburch Date: Mon, 20 Jan 2025 14:34:56 +0100 Subject: [PATCH 3/4] Activate threshold --- bitcoinSwitch/bitcoinSwitch.ino | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/bitcoinSwitch/bitcoinSwitch.ino b/bitcoinSwitch/bitcoinSwitch.ino index b87dd24..55829e4 100644 --- a/bitcoinSwitch/bitcoinSwitch.ino +++ b/bitcoinSwitch/bitcoinSwitch.ino @@ -244,6 +244,64 @@ void readFiles() { Serial.println("LNbits server: " + lnbitsServer); Serial.println("LNbits API url: " + apiUrl); Serial.println("Switch device ID: " + deviceId); + + // For threshold options + if (thresholdInkey == "") + { // check thresholdInkey is not set above + thresholdInkey = getJsonValue(doc, "thresholdInkey"); + Serial.println(""); + Serial.println("Threshold invoice key used from memory"); + Serial.println("Threshold invoice key: " + thresholdInkey); + } + else + { + Serial.println(""); + Serial.println("Threshold invoice key hardcoded"); + Serial.println("Threshold invoice key: " + thresholdInkey); + } + if (thresholdAmount == 0) + { // check thresholdAmount is not set above + String thresholdAmountString = getJsonValue(doc, "thresholdAmount"); + thresholdAmount = thresholdAmountString.toInt(); + Serial.println(""); + Serial.println("Threshold amount used from memory"); + Serial.println("Threshold amount: " + String(thresholdAmount)); + } + else + { + Serial.println(""); + Serial.println("Threshold amount hardcoded"); + Serial.println("Threshold amount: " + String(thresholdAmount)); + } + if (thresholdPin == 0) + { // check thresholdPin is not set above + String thresholdPinString = getJsonValue(doc, "thresholdPin"); + thresholdPin = thresholdPinString.toInt(); + Serial.println(""); + Serial.println("Threshold pin to trigger used from memory"); + Serial.println("Threshold pin to trigger: " + String(thresholdPin)); + } + else + { + Serial.println(""); + Serial.println("Threshold pin to trigger hardcoded"); + Serial.println("Threshold pin to trigger: " + String(thresholdPin)); + } + if (thresholdTime == 0) + { // check thresholdPin is not set above + String thresholdTimeString = getJsonValue(doc, "thresholdTime"); + thresholdTime = thresholdTimeString.toInt(); + Serial.println(""); + Serial.println("Threshold time used from memory"); + Serial.println("Threshold time: " + String(thresholdTime)); + } + else + { + Serial.println(""); + Serial.println("Threshold time hardcoded"); + Serial.println("Threshold time: " + String(thresholdTime)); + } + Serial.println(""); } paramFile.close(); } From 9715626c38de1ba6ea7a8b047df9bb4a7f0e1d1d Mon Sep 17 00:00:00 2001 From: axelhamburch Date: Mon, 20 Jan 2025 15:06:28 +0100 Subject: [PATCH 4/4] User feedback improved --- bitcoinSwitch/bitcoinSwitch.ino | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bitcoinSwitch/bitcoinSwitch.ino b/bitcoinSwitch/bitcoinSwitch.ino index 55829e4..5163dcc 100644 --- a/bitcoinSwitch/bitcoinSwitch.ino +++ b/bitcoinSwitch/bitcoinSwitch.ino @@ -81,7 +81,10 @@ void setup() { readFiles(); // get the saved details and store in global variables if (triggerConfig == true || ssid == "" || ssid == "null") { - Serial.println("Launch serial config"); + Serial.println(">>>>>>>>>>>>>><<<<<<<<<<<<<<"); + Serial.println(">>> Launch serial config <<<"); + Serial.println(">>> Waiting for upload <<<"); + Serial.println(">>>>>>>>>>>>>><<<<<<<<<<<<<<"); configOverSerialPort(); } else { WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // Force scanning for all APs, not just the first one @@ -134,10 +137,10 @@ void loop() { JsonObject payment = doc["payment"]; payment_amount = payment["amount"]; thresholdSum = thresholdSum + payment_amount; - Serial.println("thresholdSum: " + String(thresholdSum)); - Serial.println("thresholdAmount: " + String((thresholdAmount * 1000))); - Serial.println("thresholdPin: " + String(thresholdPin)); + Serial.println("thresholdSum: " + String(thresholdSum) + " mSats"); + Serial.println("thresholdAmount: " + String((thresholdAmount * 1000)) + " mSats"); if (thresholdSum >= (thresholdAmount * 1000)) { + Serial.println("Threshold value reached, switch pin " + String(thresholdPin) + " for " + String(thresholdTime) + " ms."); pinMode(thresholdPin, OUTPUT); digitalWrite(thresholdPin, HIGH); delay(thresholdTime);