Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.

Commit fce9dcc

Browse files
committed
Expose TX related fields for data up.
1 parent e865836 commit fce9dcc

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

docs/mqtt-topics.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ Topic for payloads received from your nodes. Example payload:
2929
"loRaSNR": 10 // signal to noise ratio
3030
}
3131
],
32+
"txInfo": {
33+
"frequency": 868100000, // frequency used for transmission
34+
"dataRate": {
35+
"modulation": "LORA", // modulation (LORA or FSK)
36+
"bandwidth": 250, // used bandwidth
37+
"spreadFactor": 5 // used SF (LORA)
38+
// "bitrate": 50000 // used bitrate (FSK)
39+
},
40+
"adr": false,
41+
"codeRate": "4/6"
42+
},
3243
"fCnt": 10, // frame-counter
3344
"fPort": 5, // FPort
3445
"data": "..." // base64 encoded payload (decrypted)

internal/api/application_server.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,20 @@ func (a *ApplicationServerAPI) HandleDataUp(ctx context.Context, req *as.HandleD
223223
pl := handler.DataUpPayload{
224224
DevEUI: devEUI,
225225
RXInfo: []handler.RXInfo{},
226-
FCnt: req.FCnt,
227-
FPort: uint8(req.FPort),
228-
Data: b,
226+
TXInfo: handler.TXInfo{
227+
Frequency: int(req.TxInfo.Frequency),
228+
DataRate: handler.DataRate{
229+
Modulation: req.TxInfo.DataRate.Modulation,
230+
Bandwidth: int(req.TxInfo.DataRate.BandWidth),
231+
SpreadFactor: int(req.TxInfo.DataRate.SpreadFactor),
232+
Bitrate: int(req.TxInfo.DataRate.Bitrate),
233+
},
234+
ADR: req.TxInfo.Adr,
235+
CodeRate: req.TxInfo.CodeRate,
236+
},
237+
FCnt: req.FCnt,
238+
FPort: uint8(req.FPort),
239+
Data: b,
229240
}
230241

231242
for _, rxInfo := range req.RxInfo {

internal/api/application_server_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ func TestApplicationServerAPI(t *testing.T) {
103103
LoRaSNR: 5,
104104
},
105105
},
106+
TxInfo: &as.TXInfo{
107+
Frequency: 868100000,
108+
DataRate: &as.DataRate{
109+
Modulation: "LORA",
110+
BandWidth: 250,
111+
SpreadFactor: 5,
112+
Bitrate: 50000,
113+
},
114+
Adr: true,
115+
CodeRate: "4/6",
116+
},
106117
}
107118
_, err := api.HandleDataUp(ctx, &req)
108119
So(err, ShouldBeNil)
@@ -119,6 +130,17 @@ func TestApplicationServerAPI(t *testing.T) {
119130
LoRaSNR: 5,
120131
},
121132
},
133+
TXInfo: handler.TXInfo{
134+
Frequency: 868100000,
135+
DataRate: handler.DataRate{
136+
Modulation: "LORA",
137+
Bandwidth: 250,
138+
SpreadFactor: 5,
139+
Bitrate: 50000,
140+
},
141+
ADR: true,
142+
CodeRate: "4/6",
143+
},
122144
FCnt: 10,
123145
FPort: 3,
124146
Data: []byte{67, 216, 236, 205},

internal/handler/mqtt_handler.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ const downlinkLockTTL = time.Millisecond * 100
2121

2222
var txTopicRegex = regexp.MustCompile(`application/(\w+)/node/(\w+)/tx`)
2323

24+
// DataRate contains the data-rate related fields.
25+
type DataRate struct {
26+
Modulation string `json:"modulation"`
27+
Bandwidth int `json:"bandwidth"`
28+
SpreadFactor int `json:"spreadFactor,omitempty"`
29+
Bitrate int `json:"bitrate,omitempty"`
30+
}
31+
2432
// RXInfo contains the RX information.
2533
type RXInfo struct {
2634
MAC lorawan.EUI64 `json:"mac"`
@@ -29,10 +37,19 @@ type RXInfo struct {
2937
LoRaSNR float64 `json:"loRaSNR"`
3038
}
3139

40+
// TXInfo contains the TX information.
41+
type TXInfo struct {
42+
Frequency int `json:"frequency"`
43+
DataRate DataRate `json:"dataRate"`
44+
ADR bool `json:"adr"`
45+
CodeRate string `json:"codeRate"`
46+
}
47+
3248
// DataUpPayload represents a data-up payload.
3349
type DataUpPayload struct {
3450
DevEUI lorawan.EUI64 `json:"devEUI"`
3551
RXInfo []RXInfo `json:"rxInfo"`
52+
TXInfo TXInfo `json:"txInfo"`
3653
FCnt uint32 `json:"fCnt"`
3754
FPort uint8 `json:"fPort"`
3855
Data []byte `json:"data"`

0 commit comments

Comments
 (0)