LORA
LoRa is a wireless technology that offers long range, low power and secure data transmission for M2M and IoT applications. LoRa is based on chirp spread spectrum modulation, which has low power characteristics like FSK modulation but can be used for long range communications. LoRa can be used to connect sensors, gateways, machines, devices, animals, people etc. wirelessly to the cloud.
LoRa Technologies operates in different frequency bands in different regions: In the United States it operates in the 915 MHz band, in Europe it operates in the 868 MHz band and in Asia it operates in the 865 to 867 MHz, 920 to 923 MHz band.
Library used
Example
Lora sender
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 | #include <SPI.h>
#include <LoRa.h>
#define SCK 18 // GPIO5 -- SX127x's SCK
#define MISO 19 // GPIO19 -- SX127x's MISO
#define MOSI 23 // GPIO27 -- SX127x's MOSI
#define SS 5 // GPIO18 -- SX127x's CS
#define RST 27 // GPIO14 -- SX127x's RESET
#define DI0 16 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
int counter = 0;
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(5000);
}
|
Lora Reciever callback
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 | #include <SPI.h>
#include <LoRa.h>
#ifdef ARDUINO_SAMD_MKRWAN1300
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
#endif
#define SCK 18 // GPIO5 -- SX127x's SCK
#define MISO 19 // GPIO19 -- SX127x's MISO
#define MOSI 23 // GPIO27 -- SX127x's MOSI
#define SS 5 // GPIO18 -- SX127x's CS
#define RST 27 // GPIO14 -- SX127x's RESET
#define DI0 16 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver Callback");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
// register the receive callback
LoRa.onReceive(onReceive);
// put the radio into receive mode
LoRa.receive();
}
void loop() {
// do nothing
}
void onReceive(int packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
for (int i = 0; i < packetSize; i++) {
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
|
Output