LoRa long-range communication system, similier similar to WIFI but working over very long distances (up to 10km). Unlike regular wifi, LoRa is designed to send only very small amounts of data, and pretty slowly.
LoRaWAN defines the communication protocol and system architecture for network based on LoRa.
The Things Network is a global collaborative Internet of Things ecosystem that creates networks, devices and solutions using LoRaWAN.
Hardware
The Arduino MKR WAN 1310 is a board that combines the functionality of the MKR Zero and LoRa / LoRaWANTM connectivity. Seting There are also modules that allow LoRa communication for almost any device, and several other Arduino based devices with inbuilt LoRa functionality.
For the experiments below we will also need:
Compatible Antena
Jumper wires
Breadboard
A sensor
Setting up the MKR WAN 1300
https://docs.arduino.cc/tutorials/mkr-wan-1310/the-things-network
Visualising Data on The Things Network
Data is stored on The Things Network for up to 7 days. The data can be exported, and it’s possible to integrate with many IOT platforms for handling live data streams.
https://www.thethingsnetwork.org/docs/applications/storage/api/
Terms:
OTAA: OTAA end devices are assigned a new DevAddr
at establishing each new session. This allows them to move to different networks/clusters.
ABP: ABPend devices use a fixed DevAdd
AppEUI and JoinEUI are the same things1310
For this experiment, we need need to LoRa devices. We need to have a compatible antenna connected to both our devices.
We will also need to install the Arduino Lora Library.
We also have to be aware of the radio frequency plan allowed in our region. It’s 868E6 for Europe, and you can find the full list of frequency bands are here.
Sender Code
The sender code sends a simple message w
Code Block |
---|
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
String myData = "my name";
void setup() {
Serial.begin(9600);// wait until serial has started
Serial.println("LoRa Sender");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
delay(1000);
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print(myData);
LoRa.print(" name");
LoRa.endPacket();
counter++;
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(4000);
} |
Receiver Code
Code Block |
---|
#include <SPI.h>
#include <LoRa.h>
String contents = "";
void setup() {
Serial.begin(9600);
while (!Serial); // wait until serial has started
Serial.println("LoRa Receiver");
if (!LoRa.begin(868E6)) {
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 '");
// read packet
while (LoRa.available()) {
contents += (char)LoRa.read();
}
Serial.println(contents);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
contents = "";
}
|