emission-p2p.ino

Arduino MKR WAN 1300 · File : emission-p2p.ino · Language : Arduino · Use case : Envoyer des données en LoRa point à point

The simplest LoRa link with the MKR WAN 1300: a text packet every five seconds in point-to-point mode, no infrastructure or gateway. The receiver is a second MKR WAN; ACK mode confirms reception when the board is in range.

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). Two LoRa boards (two MKR WAN 1300s, or 1300 + 1310), two 868 MHz antennas, a USB cable for each.

Wiring

No wiring: antenna screwed on each board, USB for power and serial monitoring.

How it works

modem.begin(EU868) initialises the SX1272; beginPacket/endPacket(true) transmits while waiting for acknowledgement. The default SF (7) already covers several kilometres in clear sight.

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

Pass the second argument as false to transmit without ACK (soberer), or send binary structs to save airtime.

emission-p2p.ino

// Emission LoRa point a point avec la MKR WAN 1300 (MKRWAN).
// Il faut une seconde carte LoRa en reception pour voir les paquets.
#include <MKRWAN.h>

LoRaModem modem;

String message;
unsigned long dernier = 0;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  if (!modem.begin(EU868)) {
    Serial.println(F("Modem SX1272 KO"));
    while (true);
  }
  modem.beginPacket();
  Serial.print(F("Bande : "));
  Serial.println(modem.getBand());
  Serial.print(F("SF courant : "));
  Serial.println(modem.getSpreadingFactor());
}

void loop() {
  if (millis() - dernier < 5000) return;
  dernier = millis();
  message = "mk1300 " + String(millis() / 1000);
  modem.beginPacket();
  modem.print(message);
  int envoyes = modem.endPacket(true); // attente ACK si visible
  if (envoyes > 0) Serial.println("Envoye : " + message);
  else Serial.println(F("Echec d'emission"));
}

← Back to the board