ArduinoArduino UnoExact chip

LoRa ping (RFM95W)

The LoRa library on an RFM95W at 868 MHz: a numbered ping every five seconds, and the other radio's answers with their RSSI.

LoRa ping (RFM95W) in Argynix Lab

The code

sketch.inoC++
// LoRa with Sandeep Mistry's library on an RFM95W (SX1276) at 868 MHz: NSS on 10,
// RESET on 9, DIO0 on 2. It sends "ping n" every 5 s and prints what comes back. The
// radio at the other end is the part's setting: one that answers, one that sends, none.
#include <SPI.h>
#include <LoRa.h>

int n = 0;
uint32_t last = 0;

void setup() {
  Serial.begin(115200);
  LoRa.setPins(10, 9, 2);
  if (!LoRa.begin(868E6)) {
    Serial.println("LoRa: no radio");
    while (true);
  }
  LoRa.setSpreadingFactor(7);
  Serial.println("LoRa ready at 868 MHz, SF7");
}

void loop() {
  if (millis() - last > 5000) {
    last = millis();
    LoRa.beginPacket();
    LoRa.print("ping ");
    LoRa.print(n++);
    LoRa.endPacket();
    Serial.print("Sent ping ");
    Serial.println(n - 1);
  }
  int size = LoRa.parsePacket();
  if (size) {
    Serial.print("Got \"");
    while (LoRa.available()) Serial.write(LoRa.read());
    Serial.print("\" RSSI ");
    Serial.print(LoRa.packetRssi());
    Serial.print(" dBm, SNR ");
    Serial.println(LoRa.packetSnr());
  }
}
libraries.txtC++
LoRa