reception-p2p.ino

Arduino MKR WAN 1300 · File : reception-p2p.ino · Language : Arduino · Use case : Recevoir et afficher des paquets LoRa

The point-to-point receiver: this MKR WAN 1300 listens on 868.1 MHz SF7, prints each packet with its RSSI and SNR, and re-initialises itself when the radio reports an error. Essential to validate a link before deployment.

Hardware

An Arduino MKR WAN 1300 (SAMD21 microcontroller, Semtech SX1272 LoRa modem for point-to-point links, no built-in LoRaWAN stack, 868/915 MHz antenna). One MKR WAN 1300 (receiver), a compatible LoRa transmitter with the same settings, 868 MHz antenna.

Wiring

No wiring; keep both boards a few metres apart for the first test, then move them apart progressively.

How it works

modem.available() returns the received packet size or 0; byte-by-byte reading drains the SX1272 FIFO. readRssi/readSnr give the link margins of the last packet.

Running it

Install Arduino SAMD Boards and the MKRWAN library, select the board, upload. You need TWO LoRa boards (two MKR WAN 1300s, or a 1300 and a 1310) to see exchanges; set the same frequency plan in the code.

Variants

Filter by preamble or address in the payload to ignore neighbouring transmissions, or log RSSI/time to characterise an antenna.

reception-p2p.ino

// Reception LoRa point a point sur la MKR WAN 1300 (MKRWAN).
#include <MKRWAN.h>

LoRaModem modem;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  if (!modem.begin(EU868)) {
    Serial.println(F("Modem SX1272 KO"));
    while (true);
  }
  // Doit correspondre a l'emetteur : canal et facteur detalement
  modem.setFrequency(868.1);
  modem.setSpreadingFactor(7);
  Serial.println(F("A l'ecoute sur 868.1 MHz SF7..."));
}

void loop() {
  int disponible = modem.available(); // 0 si rien a lire
  if (disponible > 0) {
    String recu = "";
    while (modem.available())
      recu += (char)modem.read();
    Serial.print(F("Recu ("));
    Serial.print(disponible);
    Serial.print(F(" o) : ") + recu);
    Serial.print(F("  RSSI="));
    Serial.print(modem.readRssi());
    Serial.print(F(" dBm SNR="));
    Serial.println(modem.readSnr());
  }
  // available() retourne -1 en cas d'erreur radio : on relance
  if (disponible < 0) {
    Serial.println(F("Erreur radio, reinitialisation"));
    modem.begin(EU868);
    modem.setFrequency(868.1);
  }
}

← Back to the board