commit 06fa513380762ed154ac1e6188e87302dd3ef254 Author: Sam Rolfe Date: Fri Sep 25 20:39:37 2026 +1000 Initial commit (secrets isolated) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7f308a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +secrets.h +.pio/ +build/ +.vscode/ +.idea/ +*.bin +*.elf +*.hex diff --git a/LoraMqtt_transmitter.ino b/LoraMqtt_transmitter.ino new file mode 100755 index 0000000..d8aa629 --- /dev/null +++ b/LoraMqtt_transmitter.ino @@ -0,0 +1,60 @@ +#include + +#define LORA_UART Serial2 +#define LORA_TX_PIN 17 // GPIO17 for TX +#define LORA_RX_PIN 16 // GPIO16 for RX + +#define RELAY_PIN 13 // GPIO pin to control the relay + +void setup() { + Serial.begin(115200); // Main serial for debugging + LORA_UART.begin(9600, SERIAL_8N1, LORA_RX_PIN, LORA_TX_PIN); // Initialize UART for LoRa + + pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as output + digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off at startup + + if (LORA_UART) { + Serial.println("LoRa Receiver Initialized"); + } else { + Serial.println("LoRa Receiver Initialization Failed"); + } +} + +void loop() { + // Check for incoming LoRa messages via UART + if (LORA_UART.available()) { + String incoming = ""; + while (LORA_UART.available()) { + char receivedChar = (char)LORA_UART.read(); + Serial.print(receivedChar); // Print each received character + incoming += receivedChar; + } + Serial.println("\nReceived via LoRa: " + incoming); + + // Handle relay commands + if (incoming == "turn_on_front_sprinkler") { + digitalWrite(RELAY_PIN, HIGH); // Turn on the relay + Serial.println("Relay turned on"); + } else if (incoming == "turn_off_front_sprinkler") { + digitalWrite(RELAY_PIN, LOW); // Turn off the relay + Serial.println("Relay turned off"); + } + } + + // Check for Serial Monitor command + if (Serial.available()) { + String command = Serial.readStringUntil('\n'); + command.trim(); // Remove any extra whitespace + + if (command == "restart") { + Serial.println("Restarting Receiver..."); + delay(1000); // Give time for message to print + ESP.restart(); + } else if (command == "test") { + LORA_UART.print("Test message from Receiver"); + Serial.println("Sent test message via LoRa"); + } + } + + delay(1000); // Add a delay to avoid watchdog timer reset +} diff --git a/secrets.h.example b/secrets.h.example new file mode 100644 index 0000000..5ff32d1 --- /dev/null +++ b/secrets.h.example @@ -0,0 +1,9 @@ +#ifndef SECRETS_H +#define SECRETS_H + +#define SECRET_WIFI_SSID "YOUR_WIFI_SSID" +#define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD" +#define SECRET_MQTT_USER "YOUR_MQTT_USERNAME" +#define SECRET_MQTT_PASS "YOUR_MQTT_PASSWORD" + +#endif