From 66d3beafe07186f35daaa9afab2f8ffd57c1e1c6 Mon Sep 17 00:00:00 2001 From: JP Meijers Date: Mon, 14 Oct 2019 21:11:34 +0200 Subject: [PATCH] Do not fall back to SF12 when activated using OTAA. Fixes #767 --- core/networkserver/activation.go | 1 + core/networkserver/device/device.go | 5 +++-- core/networkserver/uplink_mac.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/networkserver/activation.go b/core/networkserver/activation.go index d130ed55d..199b094c9 100644 --- a/core/networkserver/activation.go +++ b/core/networkserver/activation.go @@ -134,6 +134,7 @@ func (n *networkServer) HandleActivate(activation *pb_handler.DeviceActivationRe dev.LastSeen = time.Now() dev.UpdatedAt = time.Now() + dev.ActivatedAt = time.Now() dev.DevAddr = *lorawan.DevAddr dev.NwkSKey = *lorawan.NwkSKey dev.FCntUp = 0 diff --git a/core/networkserver/device/device.go b/core/networkserver/device/device.go index bed9c22de..c8d90f229 100644 --- a/core/networkserver/device/device.go +++ b/core/networkserver/device/device.go @@ -36,8 +36,9 @@ type Device struct { Options Options `redis:"options"` ADR ADRSettings `redis:"adr,include"` - CreatedAt time.Time `redis:"created_at"` - UpdatedAt time.Time `redis:"updated_at"` + CreatedAt time.Time `redis:"created_at"` + UpdatedAt time.Time `redis:"updated_at"` + ActivatedAt time.Time `redis:"activated_at"` // Indicates whether the device was activated via OTAA method } // ADRSettings contains the (desired) settings for a device that uses ADR diff --git a/core/networkserver/uplink_mac.go b/core/networkserver/uplink_mac.go index a10457660..4ea4aec06 100644 --- a/core/networkserver/uplink_mac.go +++ b/core/networkserver/uplink_mac.go @@ -97,7 +97,7 @@ func (n *networkServer) handleUplinkMAC(message *pb_broker.DeduplicatedUplinkMes } // We did not receive an ADR response, the device may have the wrong RX2 settings - if dev.ADR.ExpectRes && dev.ADR.Band == "EU_863_870" && viper.GetInt("eu-rx2-dr") != 0 { + if dev.ADR.ExpectRes && dev.ADR.Band == "EU_863_870" && viper.GetInt("eu-rx2-dr") != 0 && dev.ActivatedAt.IsZero() { settings := message.GetResponseTemplate().GetDownlinkOption() if settings.GetGatewayConfiguration().Frequency == 869525000 { if loraSettings := settings.ProtocolConfiguration.GetLoRaWAN(); loraSettings != nil {