Skip to content

Commit 24fe75f

Browse files
Merge pull request #226 from alexbn71/patch-4
Link check command feature
2 parents 4f20df9 + e035522 commit 24fe75f

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

docs/TheThingsNetwork.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,37 @@ void sleep(unsigned long mseconds);
175175
```
176176
177177
- `unsigned long mseconds`: number of milliseconds to sleep.
178+
179+
## Method: `wake`
180+
181+
Wake up the LoRa module from sleep before the expiration of the defined time.
182+
183+
```c
184+
void wake();
185+
```
186+
187+
## Method: `linkCheck`
188+
189+
Sets the time interval for the link check process to be triggered.
190+
191+
```c
192+
void linkCheck(uint16_t seconds);
193+
```
194+
195+
- `uint16_t seconds`: the time interval in seconds. A value of 0 will disable the link check process.
196+
197+
## Method: `getLinkCheckGateways`
198+
199+
Gets the number of gateways that successfully received the last Link Check Request frame.
200+
201+
```c
202+
uint8_t getLinkCheckGateways();
203+
```
204+
205+
## Method: `getLinkCheckMargin`
206+
207+
Gets the demodulation margin as received in the last Link Check Answer frame.
208+
209+
```c
210+
uint8_t getLinkCheckMargin();
211+
```

src/TheThingsNetwork.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ const char mac_band[] PROGMEM = "band";
190190
const char mac_ar[] PROGMEM = "ar";
191191
const char mac_rx2[] PROGMEM = "rx2";
192192
const char mac_ch[] PROGMEM = "ch";
193+
const char mac_gwnb[] PROGMEM = "gwnb";
194+
const char mac_mrgn[] PROGMEM = "mrgn";
193195

194-
const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch};
196+
const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch, mac_gwnb, mac_mrgn};
195197

196198
#define MAC_DEVADDR 0
197199
#define MAC_DEVEUI 1
@@ -211,6 +213,8 @@ const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui,
211213
#define MAC_AR 15
212214
#define MAC_RX2 16
213215
#define MAC_CH 17
216+
#define MAC_GWNB 18
217+
#define MAC_MRGN 19
214218

215219
const char mac_join_mode_otaa[] PROGMEM = "otaa";
216220
const char mac_join_mode_abp[] PROGMEM = "abp";
@@ -963,3 +967,30 @@ void TheThingsNetwork::wake()
963967
{
964968
autoBaud();
965969
}
970+
971+
void TheThingsNetwork::linkCheck(uint16_t seconds)
972+
{
973+
clearReadBuffer();
974+
debugPrint(SENDING);
975+
sendCommand(MAC_TABLE, MAC_PREFIX, true);
976+
sendCommand(MAC_TABLE, MAC_SET, true);
977+
sendCommand(MAC_GET_SET_TABLE, MAC_LINKCHK, true);
978+
979+
sprintf(buffer, "%u", seconds);
980+
modemStream->write(buffer);
981+
modemStream->write(SEND_MSG);
982+
debugPrintLn(buffer);
983+
waitForOk();
984+
}
985+
986+
uint8_t TheThingsNetwork::getLinkCheckGateways()
987+
{
988+
readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer));
989+
return strtol(buffer, NULL, 10);
990+
}
991+
992+
uint8_t TheThingsNetwork::getLinkCheckMargin()
993+
{
994+
readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer));
995+
return strtol(buffer, NULL, 10);
996+
}

src/TheThingsNetwork.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class TheThingsNetwork
9494
void sleep(uint32_t mseconds);
9595
void wake();
9696
void saveState();
97+
void linkCheck(uint16_t seconds);
98+
uint8_t getLinkCheckGateways();
99+
uint8_t getLinkCheckMargin();
97100
};
98101

99102
#endif

0 commit comments

Comments
 (0)