Unverified Commit 7a4d4341 authored by Max Reble's avatar Max Reble Committed by GitHub
Browse files

Extendes UplinkEvent with DeviceProfileName, DeviceProfileID and its tags. (#621)

parent f5c8ccba
......@@ -5,7 +5,7 @@ go 1.16
require (
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/aws/aws-sdk-go v1.26.3
github.com/brocaar/chirpstack-api/go/v3 v3.12.3
github.com/brocaar/chirpstack-api/go/v3 v3.12.4
github.com/brocaar/lorawan v0.0.0-20210809075358-95fc1667572e
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/eclipse/paho.mqtt.golang v1.3.1
......
......@@ -323,9 +323,11 @@ func (ts *ASTestSuite) TestApplicationServer() {
Tags: map[string]string{
"foo": "bar",
},
ConfirmedUplink: true,
DevAddr: d.DevAddr[:],
PublishedAt: pl.PublishedAt,
ConfirmedUplink: true,
DevAddr: d.DevAddr[:],
PublishedAt: pl.PublishedAt,
DeviceProfileId: dpID.String(),
DeviceProfileName: dp.Name,
}, pl)
})
......
......@@ -249,22 +249,31 @@ func handleCodec(ctx *uplinkContext) error {
func handleIntegrations(ctx *uplinkContext) error {
pl := pb.UplinkEvent{
ApplicationId: uint64(ctx.device.ApplicationID),
ApplicationName: ctx.application.Name,
DeviceName: ctx.device.Name,
DevEui: ctx.device.DevEUI[:],
RxInfo: ctx.uplinkDataReq.RxInfo,
TxInfo: ctx.uplinkDataReq.TxInfo,
Dr: ctx.uplinkDataReq.Dr,
Adr: ctx.uplinkDataReq.Adr,
FCnt: ctx.uplinkDataReq.FCnt,
FPort: ctx.uplinkDataReq.FPort,
Data: ctx.data,
ObjectJson: ctx.objectJSON,
Tags: make(map[string]string),
ConfirmedUplink: ctx.uplinkDataReq.ConfirmedUplink,
DevAddr: ctx.device.DevAddr[:],
PublishedAt: ptypes.TimestampNow(),
ApplicationId: uint64(ctx.device.ApplicationID),
ApplicationName: ctx.application.Name,
DeviceProfileId: ctx.device.DeviceProfileID.String(),
DeviceProfileName: ctx.deviceProfile.Name,
DeviceName: ctx.device.Name,
DevEui: ctx.device.DevEUI[:],
RxInfo: ctx.uplinkDataReq.RxInfo,
TxInfo: ctx.uplinkDataReq.TxInfo,
Dr: ctx.uplinkDataReq.Dr,
Adr: ctx.uplinkDataReq.Adr,
FCnt: ctx.uplinkDataReq.FCnt,
FPort: ctx.uplinkDataReq.FPort,
Data: ctx.data,
ObjectJson: ctx.objectJSON,
Tags: make(map[string]string),
ConfirmedUplink: ctx.uplinkDataReq.ConfirmedUplink,
DevAddr: ctx.device.DevAddr[:],
PublishedAt: ptypes.TimestampNow(),
}
//set device profile tags
for k, v := range ctx.deviceProfile.Tags.Map {
if v.Valid {
pl.Tags[k] = v.String
}
}
// set tags
......
......@@ -100,9 +100,11 @@ func jsonv3MarshalUplinkEvent(msg *integration.UplinkEvent) ([]byte, error) {
}
m := models.DataUpPayload{
ApplicationID: int64(msg.ApplicationId),
ApplicationName: msg.ApplicationName,
DeviceName: msg.DeviceName,
ApplicationID: int64(msg.ApplicationId),
ApplicationName: msg.ApplicationName,
DeviceName: msg.DeviceName,
DeviceProfileName: msg.DeviceProfileName,
DeviceProfileID: msg.DeviceProfileId,
TXInfo: models.TXInfo{
Frequency: int(msg.TxInfo.Frequency),
DR: int(msg.Dr),
......
......@@ -46,10 +46,12 @@ func (ts *MarshalerTestSuite) GetUplinkEvent() integration.UplinkEvent {
tenSecondsPB := ptypes.DurationProto(tenSeconds)
return integration.UplinkEvent{
ApplicationId: 123,
ApplicationName: "test-application",
DeviceName: "test-device",
DevEui: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
ApplicationId: 123,
ApplicationName: "test-application",
DeviceName: "test-device",
DeviceProfileName: "test-profile",
DeviceProfileId: "f293e453-6d9c-4a22-8c4d-99b2dbe4e94f",
DevEui: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
RxInfo: []*gw.UplinkRXInfo{
{
GatewayId: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
......@@ -293,10 +295,12 @@ func (ts *MarshalerTestSuite) TestJSONV3() {
assert.NoError(json.Unmarshal(b, &pl))
assert.Equal(models.DataUpPayload{
ApplicationID: 123,
ApplicationName: "test-application",
DeviceName: "test-device",
DevEUI: lorawan.EUI64{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
ApplicationID: 123,
ApplicationName: "test-application",
DeviceName: "test-device",
DeviceProfileName: "test-profile",
DeviceProfileID: "f293e453-6d9c-4a22-8c4d-99b2dbe4e94f",
DevEUI: lorawan.EUI64{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
RXInfo: []models.RXInfo{
{
GatewayID: lorawan.EUI64{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
......
......@@ -34,19 +34,21 @@ type TXInfo struct {
// DataUpPayload represents a data-up payload.
type DataUpPayload struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
RXInfo []RXInfo `json:"rxInfo,omitempty"`
TXInfo TXInfo `json:"txInfo"`
ADR bool `json:"adr"`
FCnt uint32 `json:"fCnt"`
FPort uint8 `json:"fPort"`
Data []byte `json:"data"`
Object interface{} `json:"object,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Variables map[string]string `json:"-"`
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DeviceProfileName string `json:"deviceProfileName"`
DeviceProfileID string `json:"deviceProfileID"`
DevEUI lorawan.EUI64 `json:"devEUI"`
RXInfo []RXInfo `json:"rxInfo,omitempty"`
TXInfo TXInfo `json:"txInfo"`
ADR bool `json:"adr"`
FCnt uint32 `json:"fCnt"`
FPort uint8 `json:"fPort"`
Data []byte `json:"data"`
Object interface{} `json:"object,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Variables map[string]string `json:"-"`
}
// DataDownPayload represents a data-down payload.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment