Skip to content

feat: Generalize SetOtherParams, add per-field setters, sync requestTelemetry, and re-export constants#25

Open
Yeraze wants to merge 3 commits into
meshcore-dev:masterfrom
Yeraze:feat/meshmonitor-helpers
Open

feat: Generalize SetOtherParams, add per-field setters, sync requestTelemetry, and re-export constants#25
Yeraze wants to merge 3 commits into
meshcore-dev:masterfrom
Yeraze:feat/meshmonitor-helpers

Conversation

@Yeraze
Copy link
Copy Markdown

@Yeraze Yeraze commented May 15, 2026

Summary

Three additions to support MeshMonitor's native JS integration, matching capabilities already present in python-meshcore. All follow existing code style and patterns.

Changes

1. Generalize sendCommandSetOtherParams + per-field convenience setters

sendCommandSetOtherParams previously only carried manualAddContacts. The firmware's opcode 38 (SetOtherParams) actually carries the full field set:

  • manualAddContacts (bool)
  • telemetryModeBase (uint8, 2-bit)
  • telemetryModeLoc (uint8, 2-bit)
  • telemetryModeEnv (uint8, 2-bit)
  • advLocPolicy (uint8)

This PR generalizes the method to pack all fields (telemetry modes into the single byte the firmware expects: base | loc<<2 | env<<4), matching python-meshcore's wire format.

New convenience methods using a read-modify-write pattern (AppStart read → patch one field → replay all):

  • setTelemetryModeBase(mode)
  • setTelemetryModeLoc(mode)
  • setTelemetryModeEnv(mode)
  • setAdvertLocPolicy(policy)

Also reworked setAutoAddContacts / setManualAddContacts to use the same safe read-modify-write pattern so they don't wipe sibling settings.

onSelfInfoResponse now decodes the 3 previously-reserved bytes into multiAcks, advLocPolicy, and telemetryMode (+ unpacked telemetryModeBase/Loc/Env). The reserved field is kept for backward compatibility.

New constants: Constants.TelemetryMode and Constants.AdvLocPolicy enums.

2. Sync requestTelemetry helper

requestTelemetry(contactOrPublicKey, timeoutMs = 10000) — sends BinaryRequestTypes.GetTelemetryData (0x03) via existing sendBinaryRequest, awaits the tagged BinaryResponse push, and returns parsed Cayenne LPP data. Accepts contact object, Uint8Array, or hex string.

This mirrors python-meshcore's req_telemetry_sync().

3. Top-level constant re-exports

TelemetryMode, BinaryRequestTypes, AdvLocPolicy, CommandCodes, ResponseCodes, PushCodes are now also exported as named top-level exports from src/index.js for cleaner imports. Constants itself is still exported.

Verification

  • node --check on all modified files
  • Runtime import smoke test
  • Tested end-to-end in MeshMonitor against real MeshCore hardware (two Companion nodes over USB)

Yeraze added 3 commits May 15, 2026 11:06
The existing sendCommandSetOtherParams only carried manualAddContacts,
but the firmware's SetOtherParams (opcode 38) payload also packs
telemetry_mode (base/loc/env in one byte, 2 bits each) and
adv_loc_policy. This brings meshcore.js to parity with
python-meshcore's set_other_params and the new set_*_from_infos helpers.

Changes:
- sendCommandSetOtherParams accepts (manualAddContacts, telemetryModeBase,
  telemetryModeLoc, telemetryModeEnv, advLocPolicy) and packs the three
  telemetry mode fields into a single byte as the firmware expects.
- setOtherParams accepts either the legacy boolean or a full options
  object, so existing callers (setAutoAddContacts / setManualAddContacts)
  keep working.
- onSelfInfoResponse now decodes the three bytes that used to be 'reserved'
  into multiAcks, advLocPolicy, and telemetryMode (plus unpacked
  telemetryModeBase/Loc/Env), matching python-meshcore's SELF_INFO parser.
  The original 'reserved' field is kept for backward compatibility.
- New convenience methods setTelemetryModeBase / setTelemetryModeLoc /
  setTelemetryModeEnv / setAdvertLocPolicy mirror python-meshcore: each
  reads current SelfInfo via getSelfInfo() (AppStart), patches the one
  field, and replays all fields. setAutoAddContacts / setManualAddContacts
  now use the same read-modify-write pattern so they no longer wipe the
  telemetry/adv_loc settings.
- Added Constants.TelemetryMode and Constants.AdvLocPolicy enums.
Mirrors python-meshcore's req_telemetry_sync. Sends a binary request of
type REQ_TYPE_GET_TELEMETRY_DATA (0x03) to the given contact via the
existing sendBinaryRequest plumbing (which correlates Sent → tagged
BinaryResponse push), then decodes the response payload using the
existing CayenneLpp.parse.

Accepts a contact object (uses its .publicKey), a 32-byte Uint8Array
public key, or a hex string. Returns the parsed Cayenne LPP sensor
array.
Constants.TelemetryMode / AdvLocPolicy / BinaryRequestTypes (and the
existing CommandCodes / ResponseCodes / PushCodes) are now also exposed
as named top-level exports from src/index.js, so downstream consumers
can write `import { TelemetryMode } from 'meshcore.js'` instead of
reaching through `Constants.TelemetryMode`. Constants itself is still
exported for backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant