From 2922c313a31dff253a70fd784b996e5072e07742 Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 13 Sep 2025 14:53:59 +0200 Subject: [PATCH] use CayenneLpp from meshcore.js 1.7.0 --- meshcore-bot.js | 56 ++++++++++------------------------------------- package-lock.json | 16 ++++++++++---- package.json | 15 ++++++++++++- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/meshcore-bot.js b/meshcore-bot.js index f988cc5..816ea15 100755 --- a/meshcore-bot.js +++ b/meshcore-bot.js @@ -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) { diff --git a/package-lock.json b/package-lock.json index 4c7f710..4ca4abf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index f2c1ada..e9fd13e 100644 --- a/package.json +++ b/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"