Last active
September 10, 2019 11:43
-
-
Save jenschr/9f2b2996c4135bfcc8721eaf42a891f4 to your computer and use it in GitHub Desktop.
Very simple LoRa 'server' for TTGO 1.0 boards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <LoRa.h> | |
#define SCK 5 // GPIO5 -- SX1278's SCK | |
#define MISO 19 // GPIO19 -- SX1278's MISO | |
#define MOSI 27 // GPIO27 -- SX1278's MOSI | |
#define SS 18 // GPIO18 -- SX1278's CS | |
#define RST 14 // GPIO14 -- SX1278's RESET | |
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request) | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial); | |
Serial.println("LoRa Receiver"); | |
SPI.begin(SCK, MISO, MOSI, SS); | |
LoRa.setPins(SS, RST, DI0); | |
if (!LoRa.begin(866E6)) { | |
Serial.println("Starting LoRa failed!"); | |
while (1); | |
} | |
Serial.println("LoRa started!"); | |
} | |
void loop() { | |
// try to parse packet | |
int packetSize = LoRa.parsePacket(); | |
if (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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment