From 3cdf6c040eb773faf93a8da5d2674224f13514b8 Mon Sep 17 00:00:00 2001 From: louisa Date: Sun, 4 Jun 2023 15:28:37 +0200 Subject: [PATCH] led start --- arduino/LoRaLed/LoRaLed.ino | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 arduino/LoRaLed/LoRaLed.ino diff --git a/arduino/LoRaLed/LoRaLed.ino b/arduino/LoRaLed/LoRaLed.ino new file mode 100644 index 0000000..f09aa74 --- /dev/null +++ b/arduino/LoRaLed/LoRaLed.ino @@ -0,0 +1,55 @@ +#include +#include + +#define LORA_SS_PIN 10 +#define LORA_RST_PIN 9 +#define LORA_DI0_PIN 2 + +void setup() { + Serial.begin(9600); + while (!Serial); + + pinMode(LED_BUILTIN, OUTPUT); + + // Initialize LoRa module + LoRa.setPins(LORA_SS_PIN, LORA_RST_PIN, LORA_DI0_PIN); + if (!LoRa.begin(433E6)) { + Serial.println("LoRa initialization failed. Check your wiring!"); + while (true); + } + + // Connect to WiFi or Ethernet here + + // Connect to Socket.IO server + // Replace with the actual server address + // e.g., http://localhost:3000 + // Replace with an authentication token if required + // e.g., "?token=abcd1234" + //socketIO.connect(""); +} + +void loop() { + // Handle Socket.IO events or other tasks here + + // Check for incoming LoRa messages + int packetSize = LoRa.parsePacket(); + if (packetSize) { + while (LoRa.available()) { + String message = LoRa.readString(); + Serial.println("Received message: " + message); + + // Process the received message and control the LED + if (message == "led_on") { + digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED + LoRa.beginPacket(); + LoRa.print("ack"); + LoRa.endPacket(); + } else if (message == "led_off") { + digitalWrite(LED_BUILTIN, LOW); // Turn off the LED + LoRa.beginPacket(); + LoRa.print("ack"); + LoRa.endPacket(); + } + } + } +}