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
2 changes: 2 additions & 0 deletions bitcoinSwitch/100_config.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#define BOOTUP_TIMEOUT 2 // seconds
#define CONFIG_FILE "/elements.json"
#define LED_PIN 2 // On board LED pin esp32-dev

// uncomment if you dont want to use the configuration file
// #define HARDCODED
Expand All @@ -17,6 +18,7 @@

#ifdef HARDCODED
void setupConfig(){
ledPin = LED_PIN;
Serial.println("Setting hardcoded values...");
config_ssid = CONFIG_SSID;
Serial.println("SSID: " + config_ssid);
Expand Down
15 changes: 9 additions & 6 deletions bitcoinSwitch/bitcoinSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ int config_threshold_amount;
int config_threshold_pin;
int config_threshold_time;

String apiUrl = "/api/v1/ws/";
int ledPin;


WebSocketsClient webSocket;

Expand All @@ -23,8 +24,6 @@ void setup() {
setupConfig();
setupWifi();

pinMode(2, OUTPUT); // To blink on board LED

if (config_device_string == "") {
Serial.println("No device string configured!");
printTFT("No device string!", 21, 95);
Expand All @@ -45,8 +44,8 @@ void setup() {

if (config_threshold_amount != 0) { // Use in threshold mode
Serial.println("Using THRESHOLD mode");
Serial.println("Connecting to websocket: " + host + apiUrl + config_threshold_inkey);
webSocket.beginSSL(host, 443, apiUrl + config_threshold_inkey);
Serial.println("Connecting to websocket: " + host + apiPath + config_threshold_inkey);
webSocket.beginSSL(host, 443, apiPath + config_threshold_inkey);
} else { // Use in normal mode
Serial.println("Using NORMAL mode");
Serial.println("Connecting to websocket: " + host + apiPath);
Expand Down Expand Up @@ -84,7 +83,7 @@ void executePayment(uint8_t *payload) {
}
Serial.println("[WebSocket] received pin: " + String(pin) + ", duration: " + String(time));

if (config_threshold_amount != 0) {
if (config_threshold_amount > 0) {
// If in threshold mode we check the "balance" pushed by the
// websocket and use the pin/time preset
// executeThreshold();
Expand All @@ -93,9 +92,13 @@ void executePayment(uint8_t *payload) {

// the magic happens here
pinMode(pin, OUTPUT);
pinMode(ledPin, OUTPUT);

digitalWrite(pin, HIGH);
digitalWrite(ledPin, HIGH);
delay(time);
digitalWrite(pin, LOW);
digitalWrite(ledPin, LOW);

printHome(true, true, false);

Expand Down