Skip to content

Commit 10bf7fe

Browse files
committed
examples/lora/lorawan: modify atcmd and basic demo to support choosing
any one of the supported regions at compile time by using ldflags. Signed-off-by: deadprogram <[email protected]>
1 parent 7b5bd73 commit 10bf7fe

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

examples/lora/lorawan/atcmd/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ Builds/flashes atcmd console application with simulator instead of actual LoRa r
2323
tinygo flash -target pico ./examples/lora/lorawan/atcmd/
2424
```
2525

26-
## PyBadge with LoRa Featherwing
26+
## PyBadge with LoRa Featherwing for EU868 region
2727

2828
Builds/flashes atcmd console application on PyBadge using LoRa Featherwing (RFM95/SX1276).
2929

3030
```
31-
tinygo flash -target pybadge -tags featherwing ./examples/lora/lorawan/atcmd/
31+
tinygo flash -target pybadge -tags featherwing -ldflags="-X main.reg=EU868" ./examples/lora/lorawan/atcmd/
3232
```
3333

34-
## LoRa-E5
34+
## LoRa-E5 for US915 region
3535

3636
Builds/flashes atcmd console application on Lora-E5 using onboard SX126x.
3737

3838
```
39-
tinygo flash -target lorae5 ./examples/lora/lorawan/atcmd/
39+
tinygo flash -target lorae5 -ldflags="-X main.reg=US915" ./examples/lora/lorawan/atcmd/
4040
```
4141

4242
## Joining a Public Lorawan Network

examples/lora/lorawan/atcmd/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var (
3232
defaultTimeout uint32 = 1000
3333
)
3434

35+
var reg string
36+
3537
func main() {
3638
uart.Configure(machine.UARTConfig{TX: tx, RX: rx})
3739

@@ -45,7 +47,16 @@ func main() {
4547
otaa = &lorawan.Otaa{}
4648
lorawan.UseRadio(radio)
4749

48-
lorawan.UseRegionSettings(region.EU868())
50+
switch reg {
51+
case "AU915":
52+
lorawan.UseRegionSettings(region.AU915())
53+
case "EU868":
54+
lorawan.UseRegionSettings(region.EU868())
55+
case "US915":
56+
lorawan.UseRegionSettings(region.US915())
57+
default:
58+
lorawan.UseRegionSettings(region.EU868())
59+
}
4960

5061
for {
5162
if uart.Buffered() > 0 {

examples/lora/lorawan/basic-demo/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ loraConnect: Connected !
2121
tinygo flash -target pico ./examples/lora/lorawan/basic-demo
2222
```
2323

24-
## PyBadge with LoRa Featherwing
24+
## PyBadge with LoRa Featherwing for EU868 region
2525

2626
```
27-
tinygo flash -target pybadge -tags featherwing ./examples/lora/lorawan/basic-demo
27+
tinygo flash -target pybadge -tags featherwing -ldflags="-X main.reg=EU868" ./examples/lora/lorawan/basic-demo
2828
```
2929

30-
## LoRa-E5
30+
## LoRa-E5 for US915 region
3131

3232
```
33-
tinygo flash -target lorae5 ./examples/lora/lorawan/basic-demo
33+
tinygo flash -target lorae5 -ldflags="-X main.reg=US915" ./examples/lora/lorawan/basic-demo
3434
```
3535

3636

examples/lora/lorawan/basic-demo/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import (
1212
"tinygo.org/x/drivers/lora/lorawan/region"
1313
)
1414

15-
var debug string
15+
var (
16+
reg string
17+
debug string
18+
)
1619

1720
const (
1821
LORAWAN_JOIN_TIMEOUT_SEC = 180
@@ -67,8 +70,16 @@ func main() {
6770

6871
// Connect the lorawan with the Lora Radio device.
6972
lorawan.UseRadio(radio)
70-
71-
lorawan.UseRegionSettings(region.EU868())
73+
switch reg {
74+
case "AU915":
75+
lorawan.UseRegionSettings(region.AU915())
76+
case "EU868":
77+
lorawan.UseRegionSettings(region.EU868())
78+
case "US915":
79+
lorawan.UseRegionSettings(region.US915())
80+
default:
81+
lorawan.UseRegionSettings(region.EU868())
82+
}
7283

7384
// Configure AppEUI, DevEUI, APPKey, and public/private Lorawan Network
7485
setLorawanKeys()

0 commit comments

Comments
 (0)