lorawan cleanup and optimizations:

- Remove all default loraconf default initialisation in lorawan examples (Region Settings takes care of this now)
- Remove retries while receiving JoinAccept and increase LoraRX to 10s (no need to wait more than 10s)
- Add constants for RegionSetting default frequencies
- Standardize all lora default configurations in lora examples
- Add new AT+LW=NET,(ON|OFF) command in atcmd example
This commit is contained in:
Olivier Fauchon
2023-01-30 16:50:24 +01:00
committed by deadprogram
parent 4e687b29c3
commit fa0cf6ec7f
16 changed files with 89 additions and 102 deletions
+22 -16
View File
@@ -24,7 +24,7 @@ var (
const (
LORA_TX_TIMEOUT = 2000
LORA_RX_TIMEOUT = 5000
LORA_RX_TIMEOUT = 10000
)
var (
@@ -33,10 +33,12 @@ var (
regionSettings region.RegionSettings
)
// UseRegionSettings sets current Lorawan Regional parameters
func UseRegionSettings(rs region.RegionSettings) {
regionSettings = rs
}
// UseRadio attaches Lora radio driver to Lorawan
func UseRadio(r lora.Radio) {
if ActiveRadio != nil {
panic("lorawan.ActiveRadio is already set")
@@ -44,15 +46,25 @@ func UseRadio(r lora.Radio) {
ActiveRadio = r
}
func ApplyChannelConfig(ch *region.Channel) {
// SetPublicNetwork defines Lora Sync Word according to network type (public/private)
func SetPublicNetwork(enabled bool) {
ActiveRadio.SetPublicNetwork(enabled)
}
// ApplyChannelConfig sets current Lora modulation according to current regional settings
func applyChannelConfig(ch *region.Channel) {
ActiveRadio.SetFrequency(ch.Frequency)
ActiveRadio.SetBandwidth(ch.Bandwidth)
ActiveRadio.SetCodingRate(ch.CodingRate)
ActiveRadio.SetSpreadingFactor(ch.SpreadingFactor)
ActiveRadio.SetPreambleLength(ch.PreambleLength)
ActiveRadio.SetTxPower(ch.TxPowerDBm)
// Lorawan defaults to explicit headers
ActiveRadio.SetHeaderType(lora.HeaderExplicit)
ActiveRadio.SetCrc(true)
}
// Join tries to connect Lorawan Gateway
func Join(otaa *Otaa, session *Session) error {
var resp []uint8
@@ -73,8 +85,7 @@ func Join(otaa *Otaa, session *Session) error {
}
// Prepare radio for Join Tx
ApplyChannelConfig(regionSettings.JoinRequestChannel())
ActiveRadio.SetCrc(true)
applyChannelConfig(regionSettings.JoinRequestChannel())
ActiveRadio.SetIqMode(lora.IQStandard)
ActiveRadio.Tx(payload, LORA_TX_TIMEOUT)
if err != nil {
@@ -82,18 +93,13 @@ func Join(otaa *Otaa, session *Session) error {
}
// Wait for JoinAccept
ApplyChannelConfig(regionSettings.JoinAcceptChannel())
ActiveRadio.SetCrc(true)
applyChannelConfig(regionSettings.JoinAcceptChannel())
ActiveRadio.SetIqMode(lora.IQInverted)
for i := 0; i < Retries; i++ {
resp, err = ActiveRadio.Rx(LORA_RX_TIMEOUT)
if err != nil {
return err
}
if resp != nil {
break
}
resp, err = ActiveRadio.Rx(LORA_RX_TIMEOUT)
if err != nil {
return err
}
if resp == nil {
return ErrNoJoinAcceptReceived
}
@@ -106,6 +112,7 @@ func Join(otaa *Otaa, session *Session) error {
return nil
}
// SendUplink sends Lorawan Uplink message
func SendUplink(data []uint8, session *Session) error {
if regionSettings == nil {
@@ -117,8 +124,7 @@ func SendUplink(data []uint8, session *Session) error {
return err
}
ApplyChannelConfig(regionSettings.UplinkChannel())
ActiveRadio.SetCrc(true)
applyChannelConfig(regionSettings.UplinkChannel())
ActiveRadio.SetIqMode(lora.IQStandard)
ActiveRadio.Tx(payload, LORA_TX_TIMEOUT)
if err != nil {
+3 -3
View File
@@ -15,19 +15,19 @@ type RegionSettingsAU915 struct {
func AU915() *RegionSettingsAU915 {
return &RegionSettingsAU915{
joinRequestChannel: &Channel{916800000,
joinRequestChannel: &Channel{lora.MHz_916_8,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
AU915_DEFAULT_PREAMBLE_LEN,
AU915_DEFAULT_TX_POWER_DBM},
joinAcceptChannel: &Channel{923300000,
joinAcceptChannel: &Channel{lora.MHz_923_3,
lora.Bandwidth_500_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
AU915_DEFAULT_PREAMBLE_LEN,
AU915_DEFAULT_TX_POWER_DBM},
uplinkChannel: &Channel{868500000,
uplinkChannel: &Channel{lora.MHz_868_5,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
+3 -3
View File
@@ -15,19 +15,19 @@ type RegionSettingsEU868 struct {
func EU868() *RegionSettingsEU868 {
return &RegionSettingsEU868{
joinRequestChannel: &Channel{868100000,
joinRequestChannel: &Channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
EU868_DEFAULT_PREAMBLE_LEN,
EU868_DEFAULT_TX_POWER_DBM},
joinAcceptChannel: &Channel{868100000,
joinAcceptChannel: &Channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
EU868_DEFAULT_PREAMBLE_LEN,
EU868_DEFAULT_TX_POWER_DBM},
uplinkChannel: &Channel{868100000,
uplinkChannel: &Channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,