Simulate message from the Gateway => Gateway Bridge

The data rate you provided in the example script seems to be wrong for your configuration, which probably has a different band than mine. So again, go back to the docs, you need these settings to be correct and I can’t do that for you.

is this?

jul 19 14:47:22 diogo loraserver[3133]: time=“2018-07-19T14:47:22+01:00” level=info msg=“backend/gateway: rx packet received”
jul 19 14:47:23 diogo loraserver[3133]: time=“2018-07-19T14:47:23+01:00” level=warning msg=“get device-sessions for dev_addr error: object does not exist” dev_addr=07262b83 dev_eui=0102030405060708
jul 19 14:47:23 diogo loraserver[3133]: time=“2018-07-19T14:47:23+01:00” level=error msg=“processing rx packet error: get data-rate error: lorawan/band: data-rate not found” data_base64=“QIMrJgcAAAAB0tn1oOPghGtZnFs=”

And my frequency band is 863_870, so I put frequency":869000000

Why the error still here?

As I said, you probably have a DR (data rate) set at the example script that isn’t valid for that band. Here’s the function that checks data rates at the lorawan package:

func (b *band) GetDataRateIndex(uplink bool, dataRate DataRate) (int, error) {
	for i, d := range b.dataRates {
		// some bands implement different data-rates with the same parameters
		// for uplink and downlink
		if uplink {
			if d.uplink == true && d.Modulation == dataRate.Modulation && d.Bandwidth == dataRate.Bandwidth && d.BitRate == dataRate.BitRate && d.SpreadFactor == dataRate.SpreadFactor {
				return i, nil
			}
		}
		if !uplink {
			if d.downlink == true && d.Modulation == dataRate.Modulation && d.Bandwidth == dataRate.Bandwidth && d.BitRate == dataRate.BitRate && d.SpreadFactor == dataRate.SpreadFactor {
				return i, nil
			}
		}
	}
	return 0, errors.New("lorawan/band: data-rate not found")
}

As you can tell, it looks for the given data rate among those of the band you declared but doesn’t find it. Be sure to define a correct data rate in the script.

1 Like

Good morning,

It gives me this error

command-line-arguments

./uplink_example.go:132:10: undefined: band
./uplink_example.go:132:55: undefined: DataRate

I had that in end of the script.

I need to change this?

No, you need to create a valide data rate for the band you’re working with here: https://github.com/iegomez/loraserver-device-sim/blob/master/example/uplink_example.go#L98

So this needs to change to adapt to your settings (check LoRaWAN docs regional parameters for your band):

dataRate := &lds.DataRate{
		Bandwidth:    500,
		Modulation:   "LORA",
		SpreadFactor: 8,
		BitRate:      0}

I think CodeRate at the RxInfo struct needs to change too.

All these settings are mentioned in the LoRaWAN specification and the regional parameters documents. You may find those here: https://www.lora-alliance.org/lorawan-for-developers

I change it for :

dataRate := &lds.DataRate{
// Bandwidth: 500,
Bandwidth: 865,
Modulation: “LORA”,
SpreadFactor: 8,
BitRate: 0}

and then

jul 23 17:21:55 diogo loraserver[3102]: time=“2018-07-23T17:21:55+01:00” level=error msg=“processing rx packet error: get data-rate error: lorawan/band: data-rate not found” data_base64=“QIMrJgcAAAAB1Oj0u8LZicPxm9o=”

Once again, go back to the docs: 865 kHz isn’t a valid bandwidth in any band that I know of, certainly not in EU863-870. The frequency band (like US 915, EU863-870, etc.) is not the same as a channels’s bandwidth (e.g., 125 kHz, 500 kHz, etc.).

Thanks for your support I change it for 125kHz as said in the document and the result it was:

jul 24 08:59:27 diogo loraserver[3263]: time=“2018-07-24T08:59:27+01:00” level=info msg=“backend/gateway: rx packet received”
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=warning msg=“get device-sessions for dev_addr error: object does not exist” dev_addr=07262b83 dev_eui=0102030405060708
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“device-session saved” dev_addr=07262b83 dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=warning msg=“frame counters reset” dev_addr=07262b83 dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“rx info sent to network-controller” dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“device-session saved” dev_addr=07262b83 dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“finished unary call with code OK” grpc.code=OK grpc.method=GetDevice grpc.service=ns.NetworkServer grpc.start_time=“2018-07-24T08:59:28+01:00” grpc.time_ms=0.778 peer.address=“127.0.0.1:35360” span.kind=server system=grpc
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“device updated” dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“finished unary call with code OK” grpc.code=OK grpc.method=UpdateDevice grpc.service=ns.NetworkServer grpc.start_time=“2018-07-24T08:59:28+01:00” grpc.time_ms=8.405 peer.address=“127.0.0.1:35360” span.kind=server system=grpc
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“finished client unary call” grpc.code=OK grpc.method=HandleUplinkData grpc.service=as.ApplicationServer grpc.time_ms=45.324 span.kind=client system=grpc
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“pending mac-command block set” cid=RXTimingSetupReq commands=1 dev_eui=0000000000000002
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“backend/gateway: publishing tx packet” qos=0 topic=gateway/b827ebfffeb13d1f/tx
jul 24 08:59:28 diogo loraserver[3263]: time=“2018-07-24T08:59:28+01:00” level=info msg=“device-session saved” dev_addr=07262b83 dev_eui=0000000000000002

another question :

in UI we can see the specs about the package and I receive two in this area Live LoRaWAN frame logs connected

1 uplink and another downlink what it means that my loraserver for any message that receive can send a message? :confused:

@iegomez Thank you so much for the script. I got it working and the information is being received on my lora app server. However I am having some issues adding the payload where you commented to create the object. Can you provide some assistance?

Hi! Could you elaborate on what’s your issue?

@iegomez Inside the uplink_example.go file from your github repo, there is a section of code that is used to include simulated payload data.

.
When I try to uncomment the obj and run the script i get the following error 12%20PM
This is my first time working with go so I am not really experienced with the syntax. Any assistance will be greatly appreciated.

Oh, well, it’s commented for a reason: that’s not Go code. It’s a sample javascript object that could be used in a decoding function at lora-app-server. It actually has a typo, but again, it’s not important as you should write the correct decoding function for your use. The Go code that generates the payload is this:

temp := [2]byte{uint8(rand.Intn(25)), uint8(rand.Intn(100))}
pressure := [3]byte{uint8(rand.Intn(2)), uint8(rand.Intn(20)), uint8(rand.Intn(100))}
humidity := [2]byte{uint8(rand.Intn(100)), uint8(rand.Intn(100))}

payload := []byte{temp[0], temp[1], pressure[0], pressure[1], pressure[2], humidity[0], humidity[1]}

As you see, it’s a slice of bytes that are randomly generated. Why? Because how your data is encoded into a bytes array depends on you (or your device) really, so as an example I just created some random values that fitted. The Uplink method of the Device struct doesn’t really care how data is encoded, it only needs a byte slice in order to encrypt and send, which will later be decrypted and made available at lora-app-server as the same array of bytes for you to decode accordingly with your codec function. So when running this, whatever payload contains will be fine as long as it’s a byte slice:

err = device.Uplink(client, lorawan.UnconfirmedDataUp, 1, rxInfo, payload)

@iegomez Noted. By chance do you have the javascript version of the encrypt and decrypt code you sent a screenshot of in this topic?

:thinking: I don’t think I’ve sent a screenshot of code.

Sorry about that lol not a screenshot. https://forum.loraserver.io/t/simulate-message-from-the-gateway-gateway-bridge/831/10?u=nicholas @iegomez

I see. Sorry, I don’t, we decode it in Go, not using the js payload codec. But as stated on that post, that decoding function is suited for our way of encoding data, it’s not a general one. I think it’s best for you to see how you’ll encode data at your devices, simulate that encoding in your script and then write the corresponding js decoding function at lora-app-server.

@iegomez for my project I need to build an application to interface with the lora app server and I need to get the data from the devices. However, the person who is in charge of setting up the network with the devices etc is a little behind so I don’t want to have to wait before I can test. This is why I am just trying to receive sample payload data at the lora app server. But thanks so much for the help.

For anyone interested, I bumped the simulator to support LoRaWAN 1.0 and 1.1 (among other fixes), and added a simple GUI to configure everything and send messages. I deprecated the original repo in favor of this one: https://github.com/iegomez/lds-gui.

1 Like