Method to send downlink MAC Commands to End Node


#1

Hi All,

With the go script shown below, I am currently trying to figure out how to send downlink messages with MAC Commands to my end node: STM32L0 (b-l072z-lrwan1). At the LoRa App Server our device profile is LoRaWan Mac version 1.0.3 regional parameter 3, OTAA enabled, Class C device and the frame counter validation is disabled.

Firstly, I have been communicating to the LoRa server api through gRPC as mentioned in the code below. Here are a few issues currently that I would like help with:

  1. When I send downlink messages from the LoRa Server a downlink message is successfully sent out, but it fails to send the downlink with our MAC Command payload shown below in the script. Why is this occuring?

  2. I am unable to send downlink messages arbitrarily whenever I want. Is there a method to enable me to send whenever I’d like? grin:

Please find our code shown below for our go script with what the mac payload contains along with our Loraserver.toml script:

Go script:

package main
import(
“context”
“log”
“loraserver/api/ns”
google.golang.org/grpc
“fmt”
“lorawan”
)
func main() {
grpcOpts := []grpc.DialOption{
grpc.WithInsecure(),
}

asConn, err := grpc.Dial("0.0.0.0:8004", grpcOpts...)
if err != nil {
	log.Fatal(err)
	}
fmt.Printf("%v\n",err)

NetworkServiceclient := ns.NewNetworkServerServiceClient(asConn)

ctx  := context.Background()

devEUI:= [8]byte{0,0,0,0,0,0,0,1}

mac := lorawan.MACCommand{
	CID: lorawan.LinkADRReq,
	Payload: &lorawan.LinkADRReqPayload{
		DataRate: uint8(0),
		TXPower: uint8(1),
		ChMask:[16]bool{true,true,true,true,true,true,true,true,true,true,true,true,false,true,true},
		Redundancy: lorawan.Redundancy{
			ChMaskCntl: uint8(0),
			NbRep: uint8(2),
		},
	},
}
b,err := mac.MarshalBinary()

resp,err :=  NetworkServiceclient.CreateMACCommandQueueItem(ctx,&ns.CreateMACCommandQueueItemRequest{
	DevEui: devEUI[:],
	Cid: uint32(lorawan.LinkADRReq), // command id is in hexidecimal 0x00
	Commands: [][]byte{b},

})
fmt.Printf("%s",resp)

    _, err = NetworkServiceclient.CreateDeviceQueueItem(ctx,&ns.CreateDeviceQueueItemRequest{
            Item: &ns.DeviceQueueItem{
                    DevEui: devEUI[:],
                    FrmPayload: []byte{1,2,3,4},
                    FCnt: 3005,
                    FPort: 1,
                    Confirmed: false,
	},
})

}

“”""""""""""""""""""""""""""""""""""""

Loraserver.toml script:

[general]
log_level=4

[postgresql]
dsn=“postgres://loraserver_ns:dbpassword@localhost/loraserver_ns?sslmode=disable”

automigrate=true

[redis]
url=“redis://localhost:6379”

max_idle=10

idle_timeout=“5m0s”

[network_server]
net_id=“000000”

deduplication_delay=“200ms”

device_session_ttl=“744h0m0s”

get_downlink_data_delay=“100ms”

[network_server.band]
name=“US_902_928”

dwell_time_400ms=false

repeater_compatible=false

[network_server.network_settings]
installation_margin=10

rx_window=0

rx1_delay=1

rx1_dr_offset=0

rx2_dr=-1

rx2_frequency=-1

downlink_tx_power=-1

disable_mac_commands=false

disable_adr=false

enabled_uplink_channels=[]

[network_server.network_settings.class_b]
ping_slot_dr=0

ping_slot_frequency=0

[network_server.network_settings.rejoin_request]
enabled=true

max_count_n=0

max_time_n=0

[network_server.scheduler]
scheduler_interval=“1s”

[network_server.scheduler.class_c]
downlink_lock_duration="2s"

[network_server.api]
bind=“0.0.0.0:8004”

ca_cert=""

tls_cert=""

tls_key=""

[network_server.gateway.stats]
create_gateway_on_stats=true

timezone=""

aggregation_intervals=[“minute”, “hour”, “day”]

[network_server.gateway.backend]
type=“mqtt”

[network_server.gateway.backend.mqtt]
uplink_topic_template="gateway/+/rx"
downlink_topic_template="gateway/{{ .MAC }}/tx"
stats_topic_template="gateway/+/stats"
ack_topic_template="gateway/+/ack"
config_topic_template="gateway/{{ .MAC }}/config"

server="tcp://localhost:1883"

username=""

password=""

qos=0

clean_session=true

client_id=""

ca_cert=""

tls_cert=""

tls_key=""


[network_server.gateway.backend.gcp_pub_sub]
credentials_file=""

project_id=""

uplink_topic_name=""

downlink_topic_name=""

uplink_retention_duration="24h0m0s"

[geolocation_server]
server=""

ca_cert=""

tls_cert=""

tls_key=""

[join_server.default]
server=“http://localhost:8003

ca_cert=""

tls_cert=""

tls_key=""

[network_controller]
server=""

ca_cert=""

tls_cert=""

tls_key=""


#2

Any solution to this, having a similar problem with issuing the linkadr mac command and not showing up in the downlink messages being issued