mirror of
https://github.com/Cyclenerd/meshcore-bot.git
synced 2026-03-28 17:42:46 +01:00
use CayenneLpp from meshcore.js 1.7.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { Constants, NodeJSSerialConnection } from "@liamcottle/meshcore.js";
|
||||
import { Constants, NodeJSSerialConnection, CayenneLpp } from "@liamcottle/meshcore.js";
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import fs from 'fs';
|
||||
@@ -9,35 +9,6 @@ function getTimestamp() {
|
||||
return new Date().toISOString().slice(0, -5) + 'Z';
|
||||
}
|
||||
|
||||
class LPPDecoder {
|
||||
// Decode Cayenne Low Power Payload (LPP) for LoraWan
|
||||
constructor() {
|
||||
this.sensors = [];
|
||||
}
|
||||
|
||||
decode(data) {
|
||||
const buffer = Buffer.from(data);
|
||||
let i = 0;
|
||||
while (i < buffer.length) {
|
||||
const channel = buffer[i++];
|
||||
const type = buffer[i++];
|
||||
switch (type) {
|
||||
// Source: https://discord.com/channels/1343693475589263471/1391673743453192242/1395240557176950876
|
||||
case 0x74: { // static const LPP_VOLTAGE = 116;
|
||||
const name = "lpp_volts";
|
||||
this.sensors.push({ channel, type, name, value: buffer.readInt16BE(i) / 100 });
|
||||
i += 2; // 2 bytes 0.01V unsigned
|
||||
break;
|
||||
}
|
||||
default:
|
||||
i = buffer.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this.sensors;
|
||||
}
|
||||
}
|
||||
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.option('port', {
|
||||
alias: 's',
|
||||
@@ -242,21 +213,16 @@ async function getRepeaterTelemetry(publicKeyPrefix, repeaterPassword) {
|
||||
console.log("Fetching telemetry...");
|
||||
const telemetry = await connection.getTelemetry(contact.publicKey);
|
||||
console.log(`[${getTimestamp()}] Repeater telemetry`, telemetry);
|
||||
let lpp_volts = 0.0;
|
||||
if (telemetry.lppSensorData) {
|
||||
try {
|
||||
const lpp = new LPPDecoder();
|
||||
const decoded = lpp.decode(telemetry.lppSensorData);
|
||||
console.log(`[${getTimestamp()}] Decoded repeater telemetry`, decoded);
|
||||
for (const sensor of decoded) {
|
||||
if (sensor.name === "lpp_volts") {
|
||||
lpp_volts = sensor.value;
|
||||
console.log(`LPP Voltage: ${lpp_volts} V`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error decoding repeater telemetry", e);
|
||||
}
|
||||
// parse telemetry
|
||||
const parsedTelemetry = CayenneLpp.parse(telemetry.lppSensorData);
|
||||
console.log(`[${getTimestamp()}] Decoded repeater telemetry`, parsedTelemetry);
|
||||
// find battery voltage telemetry on channel 1
|
||||
const lpp_volts = parsedTelemetry.find((item) => item.channel === 1 && item.type === CayenneLpp.LPP_VOLTAGE)?.value;
|
||||
|
||||
if(lpp_volts !== undefined) {
|
||||
console.log(`LPP Voltage: ${lpp_volts} V`);
|
||||
} else {
|
||||
console.log("LPP Voltage not found in telemetry");
|
||||
}
|
||||
|
||||
if (csvFile) {
|
||||
|
||||
16
package-lock.json
generated
16
package-lock.json
generated
@@ -5,15 +5,23 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "meshcore-bot",
|
||||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@liamcottle/meshcore.js": "^1.6.0",
|
||||
"@liamcottle/meshcore.js": "^1.7.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"bin": {
|
||||
"meshcore-bot": "meshcore-bot.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.34.0",
|
||||
"eslint": "^9.35.0",
|
||||
"globals": "^16.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint-community/eslint-utils": {
|
||||
@@ -237,9 +245,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@liamcottle/meshcore.js": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@liamcottle/meshcore.js/-/meshcore.js-1.6.0.tgz",
|
||||
"integrity": "sha512-aJToAlzoMA0OUOM+tp3LoxQzxPnYyV15oHDi3qDFWdznwkAmOyOcZHq40f1X+BAy7a13tbRiDecU6lwr3w65/g==",
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@liamcottle/meshcore.js/-/meshcore.js-1.7.0.tgz",
|
||||
"integrity": "sha512-GR43ZIMHXyfeCuuvS5wOaj1Q0bl3p0Epi9CPqHDx5UtVQZaCnQlem7XDDJxrKhqbAq7NkYkeoD9hsBtxkZwbxA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.8.1",
|
||||
|
||||
15
package.json
15
package.json
@@ -7,7 +7,7 @@
|
||||
"url": "https://github.com/Cyclenerd/meshcore-bot/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@liamcottle/meshcore.js": "^1.6.0",
|
||||
"@liamcottle/meshcore.js": "^1.7.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"description": "Command bot that connects to a MeshCore companion radio device via USB serial",
|
||||
@@ -16,9 +16,22 @@
|
||||
"eslint": "^9.35.0",
|
||||
"globals": "^16.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
},
|
||||
"files": [
|
||||
"meshcore-bot.js"
|
||||
],
|
||||
"homepage": "https://github.com/Cyclenerd/meshcore-bot",
|
||||
"keywords": [
|
||||
"bot",
|
||||
"cli",
|
||||
"iot",
|
||||
"meshcore"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"name": "meshcore-bot",
|
||||
"private": false,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Cyclenerd/meshcore-bot.git"
|
||||
|
||||
Reference in New Issue
Block a user