arduino/Examples/LoRaTests/Server/Server.ino

58 lines
1007 B
C++

#include <SPI.h>
#include <LoRa.h>
// The dragino shield
//#define PIN_SS 10
//#define PIN_RESET 9
//#define PIN_DIO0 2
// Custom: The smart greenhouse device
//#define PIN_SS 10
//#define PIN_RESET -1
//#define PIN_DIO0 2
// Wemos
#define PIN_SS 15
#define PIN_RESET 4
#define PIN_DIO0 5
// Channel 0
#define FREQUENCY 868100000
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
//LoRa.enableInvertIQ();
LoRa.setPins(PIN_SS, PIN_RESET, PIN_DIO0);
if (!LoRa.begin(FREQUENCY)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.onReceive(onReceive);
LoRa.receive();
Serial.println("Listening for transmissions.");
}
void loop() {
}
void onReceive(int packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}