-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLora_Module.cpp
More file actions
93 lines (77 loc) · 2.29 KB
/
Copy pathLora_Module.cpp
File metadata and controls
93 lines (77 loc) · 2.29 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Lora_Module.h"
Lora_Module::Lora_Module() {
}
void Lora_Module::Init() {
if (!modem.begin(EU868)) {
while (1) {}
}
delay(1000);
//modem.dutyCycle(DutyCycle);
//modem.publicNetwork(PublicNetwork);
//modem.dataRate(DataRate);
//modem.setADR(ADR);
if(debug>2){
Serial.print("deviceEUI "); Serial.println(modem.deviceEUI());
}
if (OVER_THE_AIR_ACTIVATE) Lora_Module::Init_OTAA();
else Lora_Module::Init_ABP();
modem.sleep();
}
void Lora_Module::Init_OTAA() {
int connected = modem.joinOTAA(APP_EUI, APP_KEY);
if (!connected) {
Serial.println("Something went wrong; are you indoor? Move near a window and retry");
while (1) {}
}
modem.minPollInterval(60);
}
void Lora_Module::Init_ABP() {
int connected = modem.joinABP(DEVADDR, NWKSKEY, APPSKEY);
if (!connected) {
Serial.println("error:Joing failed");
while (1) {}
}
modem.minPollInterval(60);
}
void Lora_Module::info_connect() {
Serial.println("connection Lora:\n------------------------");
Serial.print("Data Rate="); Serial.println(modem.getDataRate());
Serial.print("ADR="); Serial.println(modem.getADR());
if (OVER_THE_AIR_ACTIVATE) {
Serial.println("----OTAA----");
Serial.print("appEUI "); Serial.println(APP_EUI);
Serial.print("appKey "); Serial.println(APP_KEY);
}
Serial.println("------------------------------------------");
Serial.print("devAddr "); Serial.println(modem.getDevAddr());
Serial.print("nwkSkey "); Serial.println(modem.getNwkSKey());
Serial.print("appSkey "); Serial.println(modem.getAppSKey());
Serial.println("------------------------------------------");
}
bool Lora_Module::send(uint8_t *buffer, int len) {
int err;
modem.beginPacket();
modem.write(buffer, len);
err = modem.endPacket(true);
modem.sleep();
if (err > 0) {
if(debug>3)Serial.println("message correctly send !");
return err;
}
else{
if(debug>0)Serial.println("Error sending message :(");
return err;
}
}
bool Lora_Module::receive(uint8_t *data, double temp, int Size) {
delay(temp);
if (!modem.available()) {
return 0;
}
int i = 0;
while (modem.available()) {
data[i++] = (uint16_t)modem.read();
}
return 1;
modem.sleep();
}