Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/arduino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
sketch-paths: |
- bitcoinSwitch
libraries: |
- name: Ethernet
- name: WebSockets
- name: ArduinoJson
cli-compile-flags: |
Expand Down
31 changes: 30 additions & 1 deletion bitcoinSwitch/bitcoinSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ String version = "0.1.1";
String ssid = "null"; // 'String ssid = "ssid";' / 'String ssid = "null";'
String wifiPassword = "null"; // 'String wifiPassword = "password";' / 'String wifiPassword = "null";'

// Newer Arduino Ethernet Shields include a sticker with the device's MAC address.
// For older shields, choose your own MAC address.
String ethernetMac = "null"; // 'String ethernetMac = "12:ab:34:cd:56:ef";' / 'String ethernetMac = "null";'
// use empty or null to use IP address from DHCP
String ethernetIp = "null"; // 'String ethernetIp = "10.0.0.7";' / 'String ethernetIp = "null";'

// String from the lnurlDevice plugin in LNbits lnbits.com
String switchStr = "null"; // 'String switchStr = "ws url";' / 'String switchStr = "null";'

Expand All @@ -21,6 +27,7 @@ long thresholdTime; // Time to turn pin on, 'long thresholdTime = 2000;' / 'long
// END of variables //
///////////////////////////////////////////////////////////////////////////////////

#include <Ethernet.h>
#include <WiFi.h>
#include <FS.h>
#include <SPIFFS.h>
Expand Down Expand Up @@ -80,9 +87,31 @@ void setup() {

readFiles(); // get the saved details and store in global variables

if (triggerConfig == true || ssid == "" || ssid == "null") {
if (triggerConfig == true ||
((ssid == "" || ssid == "null") &&
(ethernetMac == "" || ethernetMac == "null"))) {
Serial.println("Launch serial config");
configOverSerialPort();
} else if (ethernetMac != "" && ethernetMac != "null") {
byte mac[] = {0, 0, 0, 0, 0, 0};
sscanf(ethernetMac.c_str(), "%2x:%2x:%2x:%2x:%2x:%2x",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if (ethernetIp != "" && ethernetIp != "null") {
IPAddress ip;
ip.fromString(ethernetIp);
Ethernet.begin(mac, ip);
} else {
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to get IP address from DHCP");
Serial.println("Stopping");
for (;;) {
delay(1000);
}
}
}
Serial.println("Ethernet connected");
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
} else {
WiFi.begin(ssid.c_str(), wifiPassword.c_str());
Serial.print("Connecting to WiFi");
Expand Down
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
links2004/WebSockets@^2.3.7
bblanchon/ArduinoJson@^6.21.3
arduino-libraries/Ethernet@^2.0.0
links2004/WebSockets@^2.6.0
bblanchon/ArduinoJson@^7.1.0