Skip to content

Commit c63f0d0

Browse files
Merge pull request #199 from TheThingsNetwork/asian-frequency-plans
Asian frequency plans
2 parents c850955 + 4500ae7 commit c63f0d0

File tree

5 files changed

+89
-18
lines changed

5 files changed

+89
-18
lines changed

docs/TheThingsNetwork.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ TheThingsNetwork ttn(Stream& modemStream, Stream& debugStream, fp_ttn_t fp, uint
1414
1515
- `Stream& modemStream`: Stream for the LoRa modem ([see notes](https://www.thethingsnetwork.org/docs/devices/arduino/usage.html)).
1616
- `Stream& debugStream`: Stream to write debug logs to ([see notes](https://www.thethingsnetwork.org/docs/devices/arduino/usage.html)).
17-
- `fp_ttn_fp fp`: The frequency plan: `TTN_FP_EU868` or `TTN_FP_US915` depending on the region you deploy in.
18-
- `uint8_t sf = 7`: Optional custom spreading factor. Can be `7` to `12` for `TTN_FP_EU868` and `7` to `10` for `TTN_FP_US915`. Defaults to `7`.
19-
- `uint8_t fsb = 2`: Optional custom frequency sub-band. Can be `1` to `8`. Defaults to `2` (for US915).
17+
- `fp_ttn_fp fp`: The frequency plan: `TTN_FP_EU868`, `TTN_FP_US915`, `TTN_FP_AS920_923`, `TTN_FP_AS923_925` or `TTN_FP_KR920_923` depending on the region you deploy in. See [the wiki](https://www.thethingsnetwork.org/wiki/LoRaWAN/Frequencies/Frequency-Plans).
18+
- `uint8_t sf = 7`: Optional custom spreading factor. Can be `7` to `10` for `TTN_FP_US915` and `7` to `12` for other frequency plans. Defaults to `7`.
19+
- `uint8_t fsb = 2`: Optional custom frequency subband. Can be `1` to `8`. Defaults to `2` (for US915).
2020
2121
## Method: `reset`
2222

keywords.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ TTN_ERROR_UNEXPECTED_RESPONSE LITERAL1
7474
TTN_SUCCESSFUL_TRANSMISSION LITERAL1
7575
TTN_SUCCESSFUL_RECEIVE LITERAL1
7676
TTN_FP_EU868 LITERAL1
77-
TTN_FP_EU915 LITERAL1
77+
TTN_FP_US915 LITERAL1
78+
TTN_FP_AS920_923 LITERAL1
79+
TTN_FP_AS923_925 LITERAL1
80+
TTN_FP_KR920_923 LITERAL1
7881

7982
TTN_PIN_LED LITERAL1
8083

@@ -86,4 +89,4 @@ TTN_YELLOW LITERAL1
8689
TTN_CYAN LITERAL1
8790
TTN_MAGENTA LITERAL1
8891
TTN_WHITE LITERAL1
89-
TTN_BLACK LITERAL1
92+
TTN_BLACK LITERAL1

src/TheThingsNetwork.cpp

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,7 @@ bool TheThingsNetwork::provision(const char *appEui, const char *appKey)
486486
sendMacSet(MAC_DEVEUI, buffer);
487487
sendMacSet(MAC_APPEUI, appEui);
488488
sendMacSet(MAC_APPKEY, appKey);
489-
switch (fp)
490-
{
491-
case TTN_FP_AS920_923:
492-
// TODO: temporarily removed 'mac save' because RN2903AS crashes on this command!
493-
break;
494-
default:
495-
saveState();
496-
break;
497-
}
489+
saveState();
498490
return true;
499491
}
500492

@@ -658,6 +650,10 @@ void TheThingsNetwork::configureUS915(uint8_t fsb)
658650

659651
void TheThingsNetwork::configureAS920_923()
660652
{
653+
/* RN2903AS 1.0.3rc9 defaults
654+
* CH0 = 923.2MHz
655+
* CH1 = 923.4MHz
656+
*/
661657
sendMacSet(MAC_ADR, "off"); // TODO: remove when ADR is implemented for this plan
662658
sendMacSet(MAC_RX2, "2 923200000");
663659

@@ -681,10 +677,67 @@ void TheThingsNetwork::configureAS920_923()
681677
//sendChSet(MAC_CHANNEL_FREQ, 8, "922100000");
682678
//sendChSet(MAC_CHANNEL_DRRANGE, 8, "6 6");
683679
//sendChSet(MAC_CHANNEL_STATUS, 8, "on");
684-
// TODO: Add FSK channel
680+
// TODO: Add FSK channel on 921800000
685681
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_AS920_923);
686682
}
687683

684+
void TheThingsNetwork::configureAS923_925()
685+
{
686+
/* RN2903AS 1.0.3rc9 defaults
687+
* CH0 = 923.2MHz
688+
* CH1 = 923.4MHz
689+
*/
690+
sendMacSet(MAC_ADR, "off"); // TODO: remove when ADR is implemented for this plan
691+
sendMacSet(MAC_RX2, "2 923200000");
692+
693+
char buf[10];
694+
uint32_t freq = 923600000;
695+
uint8_t ch;
696+
for (ch = 0; ch < 8; ch++)
697+
{
698+
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
699+
if (ch > 1)
700+
{
701+
sprintf(buf, "%lu", freq);
702+
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
703+
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
704+
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
705+
freq = freq + 200000;
706+
}
707+
}
708+
// TODO: SF7BW250/DR6 channel, not properly supported by RN2903AS yet
709+
//sendChSet(MAC_CHANNEL_DCYCLE, 8, "799");
710+
//sendChSet(MAC_CHANNEL_FREQ, 8, "924500000");
711+
//sendChSet(MAC_CHANNEL_DRRANGE, 8, "6 6");
712+
//sendChSet(MAC_CHANNEL_STATUS, 8, "on");
713+
// TODO: Add FSK channel on 924800000
714+
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_AS923_925);
715+
}
716+
717+
void TheThingsNetwork::configureKR920_923()
718+
{
719+
sendMacSet(MAC_ADR, "off"); // TODO: remove when ADR is implemented for this plan
720+
sendMacSet(MAC_RX2, "0 921900000"); // KR still uses SF12 for now. Might change to SF9 later.
721+
722+
//disable two default LoRaWAN channels
723+
sendChSet(MAC_CHANNEL_STATUS, 0, "off");
724+
sendChSet(MAC_CHANNEL_STATUS, 1, "off");
725+
726+
char buf[10];
727+
uint32_t freq = 922100000;
728+
uint8_t ch;
729+
for (ch = 2; ch < 9; ch++)
730+
{
731+
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
732+
sprintf(buf, "%lu", freq);
733+
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
734+
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
735+
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
736+
freq = freq + 200000;
737+
}
738+
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_KR920_923);
739+
}
740+
688741
void TheThingsNetwork::configureChannels(uint8_t fsb)
689742
{
690743
switch (fp)
@@ -698,6 +751,12 @@ void TheThingsNetwork::configureChannels(uint8_t fsb)
698751
case TTN_FP_AS920_923:
699752
configureAS920_923();
700753
break;
754+
case TTN_FP_AS923_925:
755+
configureAS923_925();
756+
break;
757+
case TTN_FP_KR920_923:
758+
configureKR920_923();
759+
break;
701760
default:
702761
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_FP);
703762
break;
@@ -712,6 +771,8 @@ bool TheThingsNetwork::setSF(uint8_t sf)
712771
{
713772
case TTN_FP_EU868:
714773
case TTN_FP_AS920_923:
774+
case TTN_FP_AS923_925:
775+
case TTN_FP_KR920_923:
715776
dr = 12 - sf;
716777
break;
717778
case TTN_FP_US915:

src/TheThingsNetwork.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define TTN_PWRIDX_EU868 "1"
1616
#define TTN_PWRIDX_US915 "5"
1717
#define TTN_PWRIDX_AS920_923 "1" // TODO: should be 0, but the current RN2903AS firmware doesn't accept that value (probably still using EU868: 1=14dBm)
18+
#define TTN_PWRIDX_AS923_925 "1" // TODO: should be 0
19+
#define TTN_PWRIDX_KR920_923 "1" // TODO: should be 0
1820

1921
#define TTN_BUFFER_SIZE 300
2022

@@ -32,7 +34,9 @@ enum ttn_fp_t
3234
{
3335
TTN_FP_EU868,
3436
TTN_FP_US915,
35-
TTN_FP_AS920_923
37+
TTN_FP_AS920_923,
38+
TTN_FP_AS923_925,
39+
TTN_FP_KR920_923
3640
};
3741

3842
class TheThingsNetwork
@@ -60,6 +64,8 @@ class TheThingsNetwork
6064
void configureEU868();
6165
void configureUS915(uint8_t fsb);
6266
void configureAS920_923();
67+
void configureAS923_925();
68+
void configureKR920_923();
6369
void configureChannels(uint8_t fsb);
6470
bool setSF(uint8_t sf);
6571
bool waitForOk();

test/TheThingsNetwork/TheThingsNetwork.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const char *appSKey = "00000000000000000000000000000000";
1212

1313
TheThingsNetwork ttn(loraSerial, debugSerial, TTN_FP_EU868);
1414

15-
TheThingsNetwork ttn2(loraSerial, debugSerial, TTN_FP_EU868, 10);
15+
TheThingsNetwork ttn2(loraSerial, debugSerial, TTN_FP_US915, 10);
16+
17+
TheThingsNetwork ttn3(loraSerial, debugSerial, TTN_FP_AS923_925, 10, 4);
1618

17-
TheThingsNetwork ttn3(loraSerial, debugSerial, TTN_FP_EU868, 10, 4);
1819

1920
void setup()
2021
{

0 commit comments

Comments
 (0)