-
Notifications
You must be signed in to change notification settings - Fork 3
/
OTAA.ino
91 lines (65 loc) · 1.66 KB
/
OTAA.ino
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
#include <M5Stack.h>
#include <LoRaWan.h>
//LoRa
char buffer[256];
long sentMillis = 0;
long currentMillis = 0;
long interval = 15000;
//byte payload[2];
void setup() {
/* Prepare M5STACK */
M5.begin();
initlora();
Serial.println("Started");
}
void loop() {
currentMillis = millis();
if (currentMillis - sentMillis > interval) {
sendobject();
}
M5.update();
}
void initlora() {
lora.init();
delay(1000);
memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
Serial.print(buffer);
memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
Serial.print(buffer);
// void setId(char *DevAddr, char *DevEUI, char *AppEUI);
lora.setId(NULL, "1234567890", "1234567890");
// setKey(char *NwkSKey, char *AppSKey, char *AppKey);
lora.setKey(NULL, NULL, "12345678901234567890");
lora.setDeviceMode(LWOTAA);
lora.setDataRate(DR5, EU868);
lora.setChannel(0, 868.1);
lora.setChannel(1, 868.3);
lora.setChannel(2, 868.5);
lora.setChannel(3, 867.1);
lora.setChannel(4, 867.3);
lora.setChannel(5, 867.5);
lora.setChannel(6, 867.7);
lora.setChannel(7, 867.9);
lora.setReceiveWindowFirst(0, 868.1);
lora.setReceiveWindowSecond(869.525, DR3);
lora.setPower(14);
lora.setPort(1);
lora.setAdaptiveDataRate(true);
//lora.setDutyCycle(false);
//lora.setJoinDutyCycle(false);
while (!lora.setOTAAJoin(JOIN, 10));
}
void sendobject() {
bool result = false;
sentMillis = millis();
Serial.println("Sending");
result = lora.transferPacket("Hello World!", 5);
//result = lora.transferPacket(payload, sizeof(payload), 5);
if (result == true) {
Serial.println("Sent");
} else {
Serial.println("Error");
}
}