Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dragino CPL03-LB connector with logo and payload configuration #56

Merged
merged 4 commits into from
Jul 12, 2024
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions decoders/connector/dragino/cpl03lb/connector.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../../../schema/connector.json",
"name": "Dragino CPL03-LB",
"images": {
"logo": "./assets/logo.png"
},
"versions": {
"v1.0.0": {
"src": "./v1.0.0/payload.ts",
"manifest": "./v1.0.0/payload-config.jsonc"
}
}
}
1 change: 1 addition & 0 deletions decoders/connector/dragino/cpl03lb/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Dragino CPL03-LB/LS is a LoRaWAN Contact Sensor for IoT solutions.
26 changes: 26 additions & 0 deletions decoders/connector/dragino/cpl03lb/v1.0.0/payload-config.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "../../../../../schema/connector_details.json",
"description": "../description.md",
"install_text": "\nThe Dragino CPL03-LB/LS is a LoRaWAN Contact Sensor for Internet of Things solution. It detects dry contact status, open time, open counts, and then upload to IoT server via LoRaWAN wireless protocol.\nLoRaWAN 1.0.3 Class A.\n*Bands: CN470/EU433/KR920/US915/EU868/AS923/AU915/IN865.\n*Ultra-low power consumption.\n*Open/Close detect.\n*Open/Close statistics.\n*Supports open alarm feature.\n*Supports Datalog feature.\n*Support Bluetooth v5.1 and LoRaWAN remote configure.\n*Support wireless OTA update firmware.\n*Uplink on periodically and open/close event.\n*Downlink to change configure.\n*8500mAh Li/SOCl2 Battery (CPL03-LB).\n*Solar panel + 3000mAh Li-on battery (CPL03-LS).",
"install_end_text": "",
"device_annotation": "",
"device_parameters": [],
"networks": [
"../../../../network/lorawan-actility/v1.0.0/payload.js",
"../../../../network/lorawan-chirpstack/v1.0.0/payload.js",
"../../../../network/lorawan-citykinect/v1.0.0/payload.js",
"../../../../network/lorawan-everynet/v1.0.0/payload.js",
"../../../../network/lorawan-helium/v1.0.0/payload.js",
"../../../../network/lorawan-kerlink/v1.0.0/payload.js",
"../../../../network/lorawan-loriot/v1.0.0/payload.js",
"../../../../network/lorawan-machineq/v1.0.0/payload.js",
"../../../../network/lorawan-orbiwise/v1.0.0/payload.js",
"../../../../network/lorawan-senet/v1.0.0/payload.js",
"../../../../network/lorawan-swisscom/v1.0.0/payload.js",
"../../../../network/lorawan-senra/v1.0.0/payload.js",
"../../../../network/lorawan-tektelic/v1.0.0/payload.js",
"../../../../network/lorawan-ttittn-v3/v1.0.0/payload.js",
"../../../../network/https/v1.0.0/payload.js",
"../../../../network/lorawan-brdot/v1.0.0/payload.js"
]
}
186 changes: 186 additions & 0 deletions decoders/connector/dragino/cpl03lb/v1.0.0/payload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/* eslint-disable unicorn/numeric-separators-style */
import { describe, expect, test } from "vitest";

import { decoderRun } from "../../../../../src/functions/decoder-run";

const file_path =
"decoders/connector/dragino/cpl03lb/v1.0.0/payload.ts" as const;

function preparePayload(payloadHex: string, port: number) {
let payload = [
{ variable: "payload", value: payloadHex },
{ variable: "fport", value: port },
];
payload = decoderRun(file_path, { payload });

const datalog = payload.find((item) => item.variable === "datalog");
const tdc = payload.find((item) => item.variable === "tdc");
const disalarm = payload.find((item) => item.variable === "disalarm");
const keep_status = payload.find((item) => item.variable === "keep_status");
const keep_time = payload.find((item) => item.variable === "keep_time");
const trigger_mode = payload.find((item) => item.variable === "trigger_mode");
const ttrig_mod1 = payload.find((item) => item.variable === "ttrig_mod1");
const ttrig_mod2 = payload.find((item) => item.variable === "ttrig_mod2");
const ttrig_mod3 = payload.find((item) => item.variable === "ttrig_mod3");
const alarm_tdc = payload.find((item) => item.variable === "alarm_tdc");
const sensor_model = payload.find((item) => item.variable === "sensor_model");
const firmware_version = payload.find(
(item) => item.variable === "firmware_version"
);
const frequency_band = payload.find(
(item) => item.variable === "frequency_band"
);
const sub_band = payload.find((item) => item.variable === "sub_band");
const bat = payload.find((item) => item.variable === "bat");
const workmod = payload.find((item) => item.variable === "workmod");
const cmod = payload.find((item) => item.variable === "cmod");
const alarm = payload.find((item) => item.variable === "alarm");
const pin_status = payload.find((item) => item.variable === "pin_status");
const ttrig_mod = payload.find((item) => item.variable === "ttrig_mod");
const total_pulse = payload.find((item) => item.variable === "total_pulse");
const last_duration = payload.find(
(item) => item.variable === "last_duration"
);
const time = payload.find((item) => item.variable === "time");
const calculate_flag = payload.find(
(item) => item.variable === "calculate_flag"
);
const pa8_total_pulse = payload.find(
(item) => item.variable === "pa8_total_pulse"
);
const pa4_total_pulse = payload.find(
(item) => item.variable === "pa4_total_pulse"
);
const pb15_total_pulse = payload.find(
(item) => item.variable === "pb15_total_pulse"
);

const parse_error = payload.find((item) => item.variable === "parse_error");
return {
payload,
datalog,
tdc,
disalarm,
keep_status,
keep_time,
trigger_mode,
ttrig_mod1,
ttrig_mod2,
ttrig_mod3,
alarm_tdc,
sensor_model,
firmware_version,
frequency_band,
sub_band,
bat,
workmod,
cmod,
alarm,
pin_status,
ttrig_mod,
total_pulse,
last_duration,
time,
calculate_flag,
pa8_total_pulse,
pa4_total_pulse,
pb15_total_pulse,
// parse error
parse_error,
};
}

// time can be tested
// describe("Port 3 unit tests", () => {
// const payloadHex =
// "4100000100003264AE52C241000020000064AE52C96100000C00000064AE53456400001200003D64AE54117800000000000064AE544B6800001700000564AE54864C0000170000564AE54AB4C0000170000564AE54B74C0000170000564AE54E0";
// const port = 3;
// const result = preparePayload(payloadHex, port);

// test("Port 3 variable values", () => {
// expect(result.datalog?.value).toBe(
// "[CPL01,SUM,NO,FALSE,OPEN,1,1,1,50,2023-07-12 04:14:10],[CPL01,SUM,NO,FALSE,OPEN,1,1,32,100,1926-07-30 20:23:13],[CPL01,SUM,NO,FALSE,CLOSE,0,0,3072,100,1926-07-31 05:12:20],[CPL01,SUM,NO,FALSE,CLOSE,0,0,4608,15716,1926-07-31 19:43:04],[CPL01,SUM,NO,FALSE,CLOSE,0,0,0,100,1926-07-31 23:50:16],[CPL01,SUM,NO,FALSE,CLOSE,0,0,5888,1380,1926-08-01 04:01:32],[CPL01,SUM,NO,FALSE,CLOSE,0,0,5888,22090,1955-10-20 15:51:44],[CPL01,SUM,NO,FALSE,CLOSE,0,0,94208,353454,2015-01-15 03:11:28],[CPL01,SUM,NO,FALSE,CLOSE,0,0,1507328,5655269,2011-06-20 23:20:48],"
// );
// });
// });

describe("Port 4 unit tests", () => {
const payloadHex = "001C200000000001000001";
const port = 4;
const result = preparePayload(payloadHex, port);

test("Port 4 variable values", () => {
expect(result.disalarm?.value).toBe(0);
expect(result.keep_status?.value).toBe(0);
expect(result.keep_time?.value).toBe(0);
expect(result.ttrig_mod1?.value).toBe(1);
expect(result.ttrig_mod2?.value).toBe(0);
expect(result.ttrig_mod3?.value).toBe(0);
expect(result.alarm_tdc?.value).toBe(1);
});
});

describe("Port 5 unit tests", () => {
const payloadHex = "20010002010B45";
const port = 5;
const result = preparePayload(payloadHex, port);

test("Port 5 variable values", () => {
expect(result.sensor_model?.value).toBe("CPL03-LB");
expect(result.firmware_version?.value).toBe("1.0.0");
expect(result.frequency_band?.value).toBe("US915");
expect(result.sub_band?.value).toBe(1);
expect(result.bat?.value).toBe(2.885);
});
});

describe("Port x unit tests 11 byte size", () => {
const payloadHex = "190012340023455F982EC8";
const port = 2;
const result = preparePayload(payloadHex, port);

test("Port x variable values", () => {
expect(result.workmod?.value).toBe("CPL03");
expect(result.cmod?.value).toBe("SUM");
expect(result.tdc?.value).toBe("YES");
expect(result.alarm?.value).toBe("FALSE");
expect(result.pin_status?.value).toBe("OPEN");
expect(result.ttrig_mod?.value).toBe(0);
expect(result.total_pulse?.value).toBe(4660);
expect(result.last_duration?.value).toBe(9029);
});
});

describe("Port x unit tests 10 byte size", () => {
const payloadHex = "00010102000123000456";
const port = 6;
const result = preparePayload(payloadHex, port);

test("Port x variable values", () => {
expect(result.workmod?.value).toBe("CPL01");
expect(result.cmod?.value).toBe("SUM");
expect(result.tdc?.value).toBe("NO");
expect(result.calculate_flag?.value).toBe(0);
expect(result.pa8_total_pulse?.value).toBe(65794);
expect(result.pa4_total_pulse?.value).toBe(291);
expect(result.pb15_total_pulse?.value).toBe(1110);
});
});

describe("Shall not be parsed", () => {
let payload = [
{ variable: "shallnotpass", value: "04096113950292" },
{ variable: "fport", value: 9 },
];
payload = decoderRun(file_path, { payload });
test("Output Result", () => {
expect(Array.isArray(payload)).toBe(true);
});

test("Not parsed Result", () => {
expect(payload).toEqual([
{ variable: "shallnotpass", value: "04096113950292" },
{ variable: "fport", value: 9 },
]);
});
});
Loading