Hi all,
I'm working on 2 LoRa32u4 devices.
One is sending a signal if a strap is loose or tight. The other should change the attached LEDs Red or Green if it is Loose or Tight respectively.
The sender LoRa unit is sending "Tight" or "Loose"
The below is my receiver code:
#include <LoRa.h>
/*********
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module
#define ss 8
#define rst 4
#define dio0 7
#define LED_Green 13
#define LED_Red 12
void setup() {
pinMode(LED_Red, OUTPUT);
pinMode(LED_Green, OUTPUT);
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(433E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
//Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
String LoRaData = LoRa.readString();
Serial.print(LoRaData);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
String LoRaLabel = LoRa.readString();
LoRa.read();
if (LoRaLabel.endsWith("Tight")) {
digitalWrite(LED_Green, HIGH);
}
}