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

update payload dragine lse01 #35

Merged
merged 1 commit into from
Jun 25, 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
2 changes: 1 addition & 1 deletion decoders/connector/dragino/lse01/connector.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"versions": {
"v1.0.0": {
"src": "./v1.0.0/payload.ts",
"src": "./v1.0.0/payload.js",
"manifest": "./v1.0.0/payload-config.jsonc"
}
}
Expand Down
61 changes: 61 additions & 0 deletions decoders/connector/dragino/lse01/v1.0.0/payload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable prettier/prettier */
/* eslint-disable no-bitwise */
/*
* LSE01
* Payload total 11 bytes
* value -> BAT (unit V) - Size(bytes) = 2
* Temperature(RESERVED) - Size(bytes) = 2
* Soil Moisture - Size(bytes) = 2
* Soil Temperature - Size(bytes) = 2
* Soil Conductivity - Size(bytes) = 1
* Digital Interrupt- Size(bytes) = 1
*/
function Decoder(bytes) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
let value=(bytes[0]<<8 | bytes[1]) & 0x3FFF;
const batV=value/1000;

value=bytes[2]<<8 | bytes[3];
if(bytes[2] & 0x80)
{value |= 0xFFFF0000;}
const tempc_ds18b20=(value/10).toFixed(2);

value=bytes[4]<<8 | bytes[5];
const water_soil=(value/100).toFixed(2);

value=bytes[6]<<8 | bytes[7];
let temp_soil;

if((value & 0x8000)>>15 === 0)
temp_soil=(value/100).toFixed(2);
else if((value & 0x8000)>>15 === 1)
temp_soil=((value-0xFFFF)/100).toFixed(2);

value=bytes[8]<<8 | bytes[9];
const conduct_soil=(value);
return [
{variable:"bat",value:Number(batV),unit: "v"},
{variable:"tempc_ds18b20",value:Number(tempc_ds18b20),unit:"°c"},
{variable:"water_soil",value:Number(water_soil),unit:"%"},
{variable:"temp_soil",value:Number(temp_soil),unit:"°c"},
{variable:"conduct_soil",value:Number(conduct_soil),unit:"us/cm"},
];
}

const payload_raw = payload.find((x) => x.variable === "payload_raw" || x.variable === "payload" || x.variable === "data");

if (payload_raw) {
try {
// Convert the data from Hex to Javascript Buffer.
const buffer = Buffer.from(payload_raw.value, "hex");
const serie = new Date().getTime();
const payload_aux = Decoder(buffer);
payload = payload.concat(payload_aux.map((x) => ({ ...x, serie })));
} catch (e) {
// Print the error to the Live Inspector.
console.error(e);
// Return the variable parse_error for debugging.
payload = [{ variable: "parse_error", value: e.message }];
}
}
70 changes: 0 additions & 70 deletions decoders/connector/dragino/lse01/v1.0.0/payload.test.ts

This file was deleted.

42 changes: 0 additions & 42 deletions decoders/connector/dragino/lse01/v1.0.0/payload.ts

This file was deleted.

Loading