You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB
Arduino

7 months ago
#include <LoRa.h>
#include "boards.h"
void setup()
{
initBoard();
// When the power is turned on, a delay is required.
delay(1500);
Serial.println("LoRa Receiver");
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DI0_PIN);
if (!LoRa.begin(LoRa_frequency)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
// Serial.print("Received packet '");
String recv = "";
// read packet
while (LoRa.available()) {
recv += (char)LoRa.read();
}
Serial.println(recv);
// // print RSSI of packet
// Serial.print("' with RSSI ");
// Serial.println(LoRa.packetRssi());
////
#ifdef HAS_DISPLAY
if (u8g2) {
u8g2->clearBuffer();
char buf[256];
u8g2->drawStr(0, 12, "Received OK!");
u8g2->drawStr(0, 26, recv.c_str());
snprintf(buf, sizeof(buf), "RSSI:%i", LoRa.packetRssi());
u8g2->drawStr(0, 40, buf);
snprintf(buf, sizeof(buf), "SNR:%.1f", LoRa.packetSnr());
u8g2->drawStr(0, 56, buf);
u8g2->sendBuffer();
}
#endif
}
}