How to get "time" from uplink message when "time" field is not a fixed element in the message array

Hi,

Shared is the rxinfo of the uplink msg. Im extracting this uplink message through http integration. When I have multiple gateways I can see time getting appended randomly to the rxinfo object. Could you please help me undestand this. Sometimes, I can find time in rxInfo[0] or rxInfo[1].

Is there a way to get the time of the message received as a fixed key of the uplink message object. This looks like I have to search every time through rxInfo to get the “time”.

example 1 rxInfo:
[
{
gatewayID: ‘00800000a0002833’,
name: ‘’,
rssi: -42,
loRaSNR: 10.5,
location: [
Object
]
},
{
gatewayID: ‘008000000000b21f’,
name: ‘gateway1-55’,
time: ‘2018-11-06T13:24:23.187304Z’,
rssi: -61,
loRaSNR: 11.2,
location: [
Object
]
}
]

example2 rxinfo:

“rxInfo”: [
{
“gatewayID”: “008000000000b21f”,
“loRaSNR”: 9,
“location”: {
“altitude”: 0,
“latitude”: 52.13798320000001,
“longitude”: -10.274643399999999
},
“name”: “multitech55”,
“rssi”: -71,
"time": "2018-11-14T17:17:41.392672Z"
},
{
“gatewayID”: “00800000a0002833”,
“loRaSNR”: 9,
“location”: {
“altitude”: 0,
“latitude”: 52.1361045,
“longitude”: -10.2726325
},
“name”: “multitech58”,
“rssi”: -80
}
],

If you check internal/api/application_server.go at lora-app-server, you’ll see that the HandleUplinkData method collects all possible rxInfo (as you may get the same message from multiple gateways) and checks for their time:

     for _, rxInfo := range req.RxInfo {
		var mac lorawan.EUI64
		copy(mac[:], rxInfo.GatewayId)

		row := handler.RXInfo{
			GatewayID: mac,
			RSSI:      int(rxInfo.Rssi),
			LoRaSNR:   rxInfo.LoraSnr,
		}

		if rxInfo.Location != nil {
			row.Location = &handler.Location{
				Latitude:  rxInfo.Location.Latitude,
				Longitude: rxInfo.Location.Longitude,
				Altitude:  rxInfo.Location.Altitude,
			}
		}

		if gw, ok := gws[mac]; ok {
			row.Name = gw.Name
		}

		if rxInfo.Time != nil {
			ts, err := ptypes.Timestamp(rxInfo.Time)
			if err != nil {
				log.WithField("dev_eui", devEUI).WithError(err).Error("parse timestamp error")
			} else {
				row.Time = &ts
			}
		}

		pl.RXInfo = append(pl.RXInfo, row)
	}

I’m taking a wild guess here (I’d have to check this at loraserver's code and don’t have the time right now), but maybe the network server only appends the time to the rxInfo that corresponds to the first message that arrived during the deduplication time. But even if this wasn’t the case, it’s clearly possible to have an rxInfo with null time, so I’d say you should loop through the rxInfo array and check if time is present in them for extraction.

It depends on the packet-forwarder providing this timestamp. In most cases it is only added when the gateway has a GPS synced time-source and has a GPS fix.

Ok will test that thank you

@iegomez thank very much