Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fix wrong docker hub link (#164)
- Fix example dummy-sensor script
- Fix issue removing a device (#165)
- Fix CayenneLpp message support for TTN v3 (#170)

### Documentation

Expand Down
47 changes: 38 additions & 9 deletions docs/users_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,48 @@ This script will send a JSON message to the mqtt broker as defined by TTN api, e

```json
{
"app_id": "demoTTN",
"dev_id": "myDevice",
"hardware_serial": "0102030405060708",
"port": 1,
"counter": 2,
"is_retry": false,
"confirmed": false,
"payload_raw": "AHMnSwFnARYCaFADAGQEAQAFAdc=",
"end_device_ids": {
"device_id": "myDevice",
"application_ids": {
"application_id": "demoTTN"
},
"dev_eui": "70B3D57ED00561EC",
"join_eui": "8CF957200005727C",
"dev_addr": "0102030405060708"
},
...
"received_at": "2022-11-18T10:33:42.184221407Z",
"uplink_message": {
"session_key_id": "AYSKRe0U59x4b0lMtYqubw==",
"f_port": 8,
"f_cnt": 46,
"frm_payload": "AHMnSwFnARYCaFADAGQEAQAFAdc=",
...
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "867900000",
"timestamp": 915329612
},
"received_at": "2022-11-18T10:33:41.976442498Z",
"confirmed": true,
"consumed_airtime": "0.087296s",
"network_ids": {
"net_id": "000013",
"tenant_id": "ttn",
"cluster_id": "eu1",
"cluster_address": "eu1.cloud.thethings.network"
}
}
}
```

The `payload_raw` field contains a base64 encoded version of the binary encoding of the CayenneLPP payload.
The `frm_payload` field contains a base64 encoded version of the binary encoding of the CayenneLPP payload.

The topic used by TTN v3 API has the following format: `v3/{application_id}/devices/{device_id}/up`.

Expand Down
4 changes: 3 additions & 1 deletion examples/dummy-devices/test-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ docker exec -ti dummy-devices-mqtt-1 mosquitto_pub -h mqtt -u admin -P password
"counter": 2,
"is_retry": false,
"confirmed": false,
"payload_raw": "AHMnSwFnARYCaFADAGQEAQAFAdc="
"uplink_message": {
"frm_payload": "AHMnSwFnARYCaFADAGQEAQAFAdc="
}
}'

sleep 5
Expand Down
22 changes: 18 additions & 4 deletions lib/applicationServers/ttnAppService.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ class TtnAppService extends appService.AbstractAppService {
deviceEui = message.hardware_serial;
}

if (dataModel === 'application_server' && message.payload_fields) {
intoTrans(localContext, this.messageHandler)(this, deviceId, deviceEui, message.payload_fields);
} else if (message.payload_raw) {
intoTrans(localContext, this.messageHandler)(this, deviceId, deviceEui, message.payload_raw);
if (
dataModel === 'application_server' &&
message.uplink_message &&
message.uplink_message.decoded_payload
) {
intoTrans(localContext, this.messageHandler)(
this,
deviceId,
deviceEui,
message.uplink_message.decoded_payload
);
} else if (message.uplink_message && message.uplink_message.frm_payload) {
intoTrans(localContext, this.messageHandler)(
this,
deviceId,
deviceEui,
message.uplink_message.frm_payload
);
} else if (message.uplink_message && message.uplink_message.decoded_payload) {
intoTrans(localContext, this.messageHandler)(
this,
Expand Down
34 changes: 33 additions & 1 deletion test/activeAttributes/cayenneLpp.json
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{"app_id":"ari_ioe_app_demo1","dev_id":"lora_n_003","hardware_serial":"3339343771356214","port":99,"counter":243,"payload_raw":"AHMAAAFnARACaAADAGQEAQA=","payload_fields":{"barometric_pressure_0":0,"digital_in_3":100,"digital_out_4":0,"relative_humidity_2":0,"temperature_1":27.2},"metadata":{"time":"2018-04-01T13:43:31.591541572Z","frequency":868.5,"modulation":"LORA","data_rate":"SF12BW125","airtime":1646592000,"coding_rate":"4/5","gateways":[{"gtw_id":"ari_ioe_lab_gateway_3","gtw_trusted":true,"timestamp":2577141228,"time":"2018-04-01T13:48:46Z","channel":2,"rssi":-5,"snr":6.75,"rf_chain":1,"latitude":43.44151,"longitude":-3.859349,"location_source":"registry"}]}}
{
"app_id": "ari_ioe_app_demo1",
"dev_id": "lora_n_003",
"hardware_serial": "3339343771356214",
"port": 99,
"counter": 243,
"uplink_message": {
"frm_payload": "AHMAAAFnARACaAADAGQEAQA="
},
"metadata": {
"time": "2018-04-01T13:43:31.591541572Z",
"frequency": 868.5,
"modulation": "LORA",
"data_rate": "SF12BW125",
"airtime": 1646592000,
"coding_rate": "4/5",
"gateways": [
{
"gtw_id": "ari_ioe_lab_gateway_3",
"gtw_trusted": true,
"timestamp": 2577141228,
"time": "2018-04-01T13:48:46Z",
"channel": 2,
"rssi": -5,
"snr": 6.75,
"rf_chain": 1,
"latitude": 43.44151,
"longitude": -3.859349,
"location_source": "registry"
}
]
}
}
34 changes: 33 additions & 1 deletion test/activeAttributes/cayenneLpp2.json
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{"app_id":"ari_ioe_app_demo1","dev_id":"lora_n_001","hardware_serial":"3339344771356214","port":99,"counter":243,"payload_raw":"AWcA1AMAZA==","payload_fields":{"barometric_pressure_0":0,"digital_in_3":100,"digital_out_4":0,"relative_humidity_2":0,"temperature_1":21.2},"metadata":{"time":"2018-04-01T13:43:31.591541572Z","frequency":868.5,"modulation":"LORA","data_rate":"SF12BW125","airtime":1646592000,"coding_rate":"4/5","gateways":[{"gtw_id":"ari_ioe_lab_gateway_3","gtw_trusted":true,"timestamp":2577141228,"time":"2018-04-01T13:48:46Z","channel":2,"rssi":-5,"snr":6.75,"rf_chain":1,"latitude":43.44151,"longitude":-3.859349,"location_source":"registry"}]}}
{
"app_id": "ari_ioe_app_demo1",
"dev_id": "lora_n_001",
"hardware_serial": "3339344771356214",
"port": 99,
"counter": 243,
"uplink_message": {
"frm_payload": "AWcA1AMAZA=="
},
"metadata": {
"time": "2018-04-01T13:43:31.591541572Z",
"frequency": 868.5,
"modulation": "LORA",
"data_rate": "SF12BW125",
"airtime": 1646592000,
"coding_rate": "4/5",
"gateways": [
{
"gtw_id": "ari_ioe_lab_gateway_3",
"gtw_trusted": true,
"timestamp": 2577141228,
"time": "2018-04-01T13:48:46Z",
"channel": 2,
"rssi": -5,
"snr": 6.75,
"rf_chain": 1,
"latitude": 43.44151,
"longitude": -3.859349,
"location_source": "registry"
}
]
}
}
34 changes: 33 additions & 1 deletion test/activeAttributes/cayenneLpp3.json
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{"app_id":"ari_ioe_app_demo1","dev_id":"lora_n_001","hardware_serial":"3339344771356214","port":99,"counter":243,"payload_raw":"AWcBGA==","payload_fields":{"barometric_pressure_0":0,"digital_in_3":100,"digital_out_4":0,"relative_humidity_2":0,"temperature_1":21.2},"metadata":{"time":"2018-04-01T13:43:31.591541572Z","frequency":868.5,"modulation":"LORA","data_rate":"SF12BW125","airtime":1646592000,"coding_rate":"4/5","gateways":[{"gtw_id":"ari_ioe_lab_gateway_3","gtw_trusted":true,"timestamp":2577141228,"time":"2018-04-01T13:48:46Z","channel":2,"rssi":-5,"snr":6.75,"rf_chain":1,"latitude":43.44151,"longitude":-3.859349,"location_source":"registry"}]}}
{
"app_id": "ari_ioe_app_demo1",
"dev_id": "lora_n_001",
"hardware_serial": "3339344771356214",
"port": 99,
"counter": 243,
"uplink_message": {
"frm_payload": "AWcBGA=="
},
"metadata": {
"time": "2018-04-01T13:43:31.591541572Z",
"frequency": 868.5,
"modulation": "LORA",
"data_rate": "SF12BW125",
"airtime": 1646592000,
"coding_rate": "4/5",
"gateways": [
{
"gtw_id": "ari_ioe_lab_gateway_3",
"gtw_trusted": true,
"timestamp": 2577141228,
"time": "2018-04-01T13:48:46Z",
"channel": 2,
"rssi": -5,
"snr": 6.75,
"rf_chain": 1,
"latitude": 43.44151,
"longitude": -3.859349,
"location_source": "registry"
}
]
}
}
34 changes: 33 additions & 1 deletion test/activeAttributes/cayenneLpp_bad_raw.json
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{"app_id":"ari_ioe_app_demo1","dev_id":"lora_n_001","hardware_serial":"3339344771356214","port":99,"counter":243,"payload_raw":"1234","payload_fields":{"barometric_pressure_0":0,"digital_in_3":100,"digital_out_4":0,"relative_humidity_2":0,"temperature_1":21.2},"metadata":{"time":"2018-04-01T13:43:31.591541572Z","frequency":868.5,"modulation":"LORA","data_rate":"SF12BW125","airtime":1646592000,"coding_rate":"4/5","gateways":[{"gtw_id":"ari_ioe_lab_gateway_3","gtw_trusted":true,"timestamp":2577141228,"time":"2018-04-01T13:48:46Z","channel":2,"rssi":-5,"snr":6.75,"rf_chain":1,"latitude":43.44151,"longitude":-3.859349,"location_source":"registry"}]}}
{
"app_id": "ari_ioe_app_demo1",
"dev_id": "lora_n_001",
"hardware_serial": "3339344771356214",
"port": 99,
"counter": 243,
"uplink_message": {
"frm_payload": "1234"
},
"metadata": {
"time": "2018-04-01T13:43:31.591541572Z",
"frequency": 868.5,
"modulation": "LORA",
"data_rate": "SF12BW125",
"airtime": 1646592000,
"coding_rate": "4/5",
"gateways": [
{
"gtw_id": "ari_ioe_lab_gateway_3",
"gtw_trusted": true,
"timestamp": 2577141228,
"time": "2018-04-01T13:48:46Z",
"channel": 2,
"rssi": -5,
"snr": 6.75,
"rf_chain": 1,
"latitude": 43.44151,
"longitude": -3.859349,
"location_source": "registry"
}
]
}
}
35 changes: 34 additions & 1 deletion test/activeAttributes/emptyCbor.json
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
{"app_id":"ari_ioe_app_demo1","dev_id":"lora_n_003","hardware_serial":"3339343771356214","port":99,"counter":243,"payload_raw":"","metadata":{"time":"2018-04-01T13:43:31.591541572Z","frequency":868.5,"modulation":"LORA","data_rate":"SF12BW125","airtime":1646592000,"coding_rate":"4/5","gateways":[{"gtw_id":"ari_ioe_lab_gateway_3","gtw_trusted":true,"timestamp":2577141228,"time":"2018-04-01T13:48:46Z","channel":2,"rssi":-5,"snr":6.75,"rf_chain":1,"latitude":43.44151,"longitude":-3.859349,"location_source":"registry"}]}}
{
"app_id": "ari_ioe_app_demo1",
"dev_id": "lora_n_003",
"hardware_serial": "3339343771356214",
"port": 99,
"counter": 243,
"uplink_message": {
"frm_payload": "",
"decoded_payload": ""
},
"metadata": {
"time": "2018-04-01T13:43:31.591541572Z",
"frequency": 868.5,
"modulation": "LORA",
"data_rate": "SF12BW125",
"airtime": 1646592000,
"coding_rate": "4/5",
"gateways": [
{
"gtw_id": "ari_ioe_lab_gateway_3",
"gtw_trusted": true,
"timestamp": 2577141228,
"time": "2018-04-01T13:48:46Z",
"channel": 2,
"rssi": -5,
"snr": 6.75,
"rf_chain": 1,
"latitude": 43.44151,
"longitude": -3.859349,
"location_source": "registry"
}
]
}
}
6 changes: 3 additions & 3 deletions test/unit/applicationServerDecoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ describe('CBOR Attributes', function () {
};

const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = null;
attributesExample.payload_fields = rawJSONPayload;
attributesExample.uplink_message.frm_payload = null;
attributesExample.uplink_message.decoded_payload = rawJSONPayload;
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish(
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('CBOR Attributes', function () {
};

const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_fields = rawJSONPayload;
attributesExample.uplink_message.decoded_payload = rawJSONPayload;
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish('v3/ari_ioe_app_demo1/devices/lora_n_003/up', JSON.stringify(attributesExample));
Expand Down
6 changes: 3 additions & 3 deletions test/unit/cborAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('CBOR Attributes', function () {

const encodedBuffer = CBOR.encode(rawJSONPayload);
const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = encodedBuffer.toString('base64');
attributesExample.uplink_message.frm_payload = encodedBuffer.toString('base64');
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish(
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('CBOR Attributes', function () {

const encodedBuffer = CBOR.encode(rawJSONPayload);
const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = encodedBuffer.toString('base64');
attributesExample.uplink_message.frm_payload = encodedBuffer.toString('base64');
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish('v3/ari_ioe_app_demo1/devices/lora_n_003/up', JSON.stringify(attributesExample));
Expand All @@ -238,7 +238,7 @@ describe('CBOR Attributes', function () {
describe('Active attributes are reported with incorrect format', function () {
it('Should process correctly active attributes', function (done) {
const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = 'no_cbor_payload';
attributesExample.uplink_message.frm_payload = 'no_cbor_payload';
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish('v3/ari_ioe_app_demo1/devices/lora_n_003/up', JSON.stringify(attributesExample));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/groupProvisioningTTN.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ describe('Configuration provisioning API: Provision groups (TTN)', function () {

const encodedBuffer = CBOR.encode(rawJSONPayload);
const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = encodedBuffer.toString('base64');
attributesExample.uplink_message.frm_payload = encodedBuffer.toString('base64');
attributesExample.dev_id = devId;
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/multientityPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('Multientity plugin', function () {

const encodedBuffer = CBOR.encode(rawJSONPayload);
const attributesExample = utils.readExampleFile('./test/activeAttributes/emptyCbor.json');
attributesExample.payload_raw = encodedBuffer.toString('base64');
attributesExample.uplink_message.frm_payload = encodedBuffer.toString('base64');
const client = mqtt.connect('mqtt://' + testMosquittoHost);
client.on('connect', function () {
client.publish(
Expand Down