mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 19:03:42 +00:00
lora/lorawan: completed functions needed for Join OTAA process
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+15
-10
@@ -6,10 +6,22 @@ import (
|
||||
"tinygo.org/x/drivers/lora"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoJoinAcceptReceived = errors.New("no JoinAccept packet received")
|
||||
ErrNoRadioAttached = errors.New("no LoRa radio attached")
|
||||
ErrInvalidEuiLength = errors.New("invalid EUI length")
|
||||
ErrInvalidAppKeyLength = errors.New("invalid AppKey length")
|
||||
ErrInvalidPacketLength = errors.New("invalid packet length")
|
||||
ErrInvalidDevAddrLength = errors.New("invalid DevAddr length")
|
||||
ErrInvalidMic = errors.New("invalid Mic")
|
||||
ErrFrmPayloadTooLarge = errors.New("FRM payload too large")
|
||||
)
|
||||
|
||||
const LORA_RXTX_TIMEOUT = 1000
|
||||
|
||||
var (
|
||||
ActiveRadio lora.Radio
|
||||
Retries = 15
|
||||
)
|
||||
|
||||
func UseRadio(r lora.Radio) {
|
||||
@@ -23,7 +35,7 @@ func Join(otaa *Otaa, session *Session) error {
|
||||
var resp []uint8
|
||||
|
||||
if ActiveRadio == nil {
|
||||
return errors.New("no LoRa radio attached")
|
||||
return ErrNoRadioAttached
|
||||
}
|
||||
|
||||
otaa.Init()
|
||||
@@ -42,9 +54,8 @@ func Join(otaa *Otaa, session *Session) error {
|
||||
}
|
||||
|
||||
// Wait for JoinAccept
|
||||
//println("lorawan: Wait for JOINACCEPT for 10s")
|
||||
ActiveRadio.SetIqMode(1) // IQ Inverted
|
||||
for i := 0; i < 15; i++ {
|
||||
for i := 0; i < Retries; i++ {
|
||||
resp, err = ActiveRadio.Rx(LORA_RXTX_TIMEOUT)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -54,19 +65,13 @@ func Join(otaa *Otaa, session *Session) error {
|
||||
}
|
||||
}
|
||||
if resp == nil {
|
||||
return errors.New("no JoinAccept packet received")
|
||||
return ErrNoJoinAcceptReceived
|
||||
}
|
||||
//println("lorawan: Received packet: len=", len(resp), "payload=", bytesToHexString(resp))
|
||||
|
||||
err = otaa.DecodeJoinAccept(resp, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// println("lorawan: Valid JOINACCEPT, now connected")
|
||||
// println("lorawan: | DevAddr: ", bytesToHexString(r.Session.DevAddr[:]), " (LSB)")
|
||||
// println("lorawan: | NetID : ", bytesToHexString(r.Otaa.NetID[:]))
|
||||
// println("lorawan: | NwkSKey: ", bytesToHexString(r.Session.NwkSKey[:]))
|
||||
// println("lorawan: | AppSKey: ", bytesToHexString(r.Session.AppSKey[:]))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user