Initial commit (secrets isolated)
This commit is contained in:
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
secrets.h
|
||||||
|
.pio/
|
||||||
|
build/
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.bin
|
||||||
|
*.elf
|
||||||
|
*.hex
|
||||||
60
LoraMqtt_transmitter.ino
Executable file
60
LoraMqtt_transmitter.ino
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
|
#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
|
||||||
|
}
|
||||||
9
secrets.h.example
Normal file
9
secrets.h.example
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user