Skip to content

MeshCoreSession

Defined in: src/session/session.ts:137

The protocol session core: owns the inbound-frame ingest, the reply- correlation FIFOs (ack + typed), the handshake, the liveness poll, and the transport-state lifecycle. Feature modules receive a FeatureContext bound to this session and own their own wire codes via the registry.

Ported verbatim from the donor ProtocolSession; the ~60 user-facing command methods are layered on in a later task.

new MeshCoreSession(opts): MeshCoreSession;

Defined in: src/session/session.ts:207

ParameterType
optsMeshCoreSessionOptions

MeshCoreSession

readonly admin: AdminSessionStore;

Defined in: src/session/session.ts:147

Repeater admin auth + pending-request store.


readonly events: Events;

Defined in: src/session/session.ts:143

Typed event bus the session and consumers subscribe to.


readonly log: Logger;

Defined in: src/session/session.ts:149

Structured logger (defaults to no-op).


readonly rt: SessionRuntime;

Defined in: src/session/session.ts:151

Per-session mutable feature state.


readonly state: SessionState;

Defined in: src/session/session.ts:145

In-memory session model.

addContactToRadio(publicKeyHex): Promise<void>;

Defined in: src/session/session.ts:883

Commit a discovered contact to the radio’s store (CMD_ADD_UPDATE_CONTACT). Awaits the radio’s RESP_OK/ERR before marking the contact on-radio.

ParameterType
publicKeyHexstring

Promise<void>


clearDefaultFloodScope(): Promise<void>;

Defined in: src/session/session.ts:1391

Clear the persisted default flood scope.

Promise<void>


deriveSecret(name): string;

Defined in: src/session/session.ts:1103

Derive the 16-byte secret for a public/hashtag channel by name. Callers supplying their own secret (e.g. private channel imported from a share link) should pass it directly to setChannel instead.

ParameterType
namestring

string


exportContact(destPublicKeyHex?): Promise<string | null>;

Defined in: src/session/session.ts:1486

Export an advert blob for the device (no arg) or a known contact, or null when the contact isn’t found.

ParameterType
destPublicKeyHex?string

Promise<string | null>


exportPrivateKey(): Promise<string>;

Defined in: src/session/session.ts:1414

Export the device’s 64-byte private key (hex). Rejects FeatureDisabledError on a firmware build with private-key export compiled out.

Promise<string>


factoryReset(): Promise<void>;

Defined in: src/session/session.ts:1431

Wipe the device to factory state. The link drops mid-reset, so there is no reply to await (like reboot()).

Promise<void>


findChannelByName(name):
| Channel
| null;

Defined in: src/session/session.ts:1017

Find a channel in current session state by exact name, or null.

ParameterType
namestring

| Channel | null


findChannelBySecret(secretHex):
| Channel
| null;

Defined in: src/session/session.ts:1023

Find a channel by its secret (hex, case-insensitive exact match). A mismatched-length input simply returns null (no validation).

ParameterType
secretHexstring

| Channel | null


findContactByName(name):
| Contact
| null;

Defined in: src/session/session.ts:1004

Find a contact in current session state by exact display name, or null.

ParameterType
namestring

| Contact | null


findContactByPublicKeyPrefix(prefixHex):
| Contact
| null;

Defined in: src/session/session.ts:1010

Find a contact whose public key starts with the given hex prefix (case-insensitive), or null.

ParameterType
prefixHexstring

| Contact | null


getAdvertPath(contactKey): Promise<
| AdvertPath
| null>;

Defined in: src/session/session.ts:1451

The device’s cached advert path for a contact, or null when none is cached.

ParameterType
contactKeystring

Promise< | AdvertPath | null>


getAllowedRepeatFreq(): Promise<RepeatFreqRange[]>;

Defined in: src/session/session.ts:1406

The frequency ranges the radio is allowed to repeat on (region-dependent).

Promise<RepeatFreqRange[]>


getChannel(idx): Promise<
| Channel
| null>;

Defined in: src/session/session.ts:1068

Actively re-query a single channel slot. Intended for use while connected; on a dead link it resolves only after the watchdog/request timeout.

ParameterType
idxnumber

Promise< | Channel | null>


getChannels(): Promise<Channel[]>;

Defined in: src/session/session.ts:1057

Actively re-enumerate channel slots (GET_CHANNEL 0..N-1) and resolve the fresh list. Intended for use while connected; on a dead link it resolves only after the watchdog/request timeout.

Promise<Channel[]>


getContactByKey(destPublicKeyHex): Promise<
| ContactRecord
| null>;

Defined in: src/session/session.ts:999

Look up a single contact on the radio by public key, or null if absent.

ParameterType
destPublicKeyHexstring

Promise< | ContactRecord | null>


getContacts(): Promise<Contact[]>;

Defined in: src/session/session.ts:1043

Actively re-enumerate the radio’s contact store (GET_CONTACTS) and resolve the fresh list. Reuses the handshake’s contact-stream waiters. Intended for use while connected; on a dead link it resolves only after the watchdog/request timeout.

Promise<Contact[]>


getDefaultFloodScope(): Promise<
| DefaultFloodScope
| null>;

Defined in: src/session/session.ts:1396

Read the persisted default flood scope, or null when none is set.

Promise< | DefaultFloodScope | null>


getDevicePresence(): string[];

Defined in: src/session/session.ts:560

Snapshot of channel keys currently present on the radio. Empty when the transport is disconnected.

string[]


getDeviceTime(): Promise<number>;

Defined in: src/session/session.ts:1346

Read the radio’s RTC clock (unix seconds).

Promise<number>


getSelfInfo(): Promise<SelfInfo>;

Defined in: src/session/session.ts:1031

Actively re-query the radio’s self-info (APP_START → RESP_SELF_INFO), publish it as the Owner, and return it. Intended for use while connected; on a dead link it resolves only after the watchdog/request timeout.

Promise<SelfInfo>


getSyncProgress(): SyncProgress;

Defined in: src/session/session.ts:565

Snapshot of handshake progress.

SyncProgress


getTransportState(): TransportState;

Defined in: src/session/session.ts:268

Current transport connection state.

TransportState


getTuningParams(): Promise<TuningParams>;

Defined in: src/session/session.ts:1364

Read the radio airtime/backoff tuning params (CMD_GET_TUNING_PARAMS).

Promise<TuningParams>


hasConnection(destPublicKeyHex): Promise<boolean>;

Defined in: src/session/session.ts:1401

Whether the radio reports an active connection to a node.

ParameterType
destPublicKeyHexstring

Promise<boolean>


importContact(blobHex): Promise<void>;

Defined in: src/session/session.ts:1491

Import a contact from a serialized advert blob (CMD_IMPORT_CONTACT).

ParameterType
blobHexstring

Promise<void>


importPrivateKey(privKeyHex): Promise<void>;

Defined in: src/session/session.ts:1420

Import a 64-byte private key (hex), replacing the device identity. Rejects ProtocolError on a bad key / FS error.

ParameterType
privKeyHexstring

Promise<void>


markChannelAbsent(idx): void;

Defined in: src/session/session.ts:1091

Mark a slot as no longer on the device (paired with a zero-key write). Frees the slot for pickFreeSlot and clears the presence flag.

ParameterType
idxnumber

void


markChannelPresent(channel): void;

Defined in: src/session/session.ts:1085

Mark a channel as present on the device. Call after a successful SET_CHANNEL ack — the firmware doesn’t echo CHANNEL_INFO back, so without this the new channel would stay grayed-out in the UI until the next full re-enumeration.

ParameterType
channelChannel

void


pickFreeSlot(): number | null;

Defined in: src/session/session.ts:1096

Lowest unused slot index in 0..15, or null if all 16 are taken.

number | null


reboot(): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:1291

Reboot the connected device. The link drops within a few hundred ms; the transport state machine will reflect that via its own state push.

Promise<{ error?: string; ok: boolean; }>


registerChannelSend(params): void;

Defined in: src/session/session.ts:778

Track an outgoing channel send so heard repeater relays (0x88) are attributed back to it (emits ‘messagePathHeard’). Call after sendChannelText returns a channelHash, passing your message id.

ParameterType
params{ channelHash: number; messageId: string; sentAt?: number; }
params.channelHashnumber
params.messageIdstring
params.sentAt?number

void


removeContactFromRadio(publicKeyHex): Promise<void>;

Defined in: src/session/session.ts:936

Delete a contact from the radio’s store (CMD_REMOVE_CONTACT). Keeps it in the discovered pool, flagged off-radio.

ParameterType
publicKeyHexstring

Promise<void>


repeaterGetLocalStats(subtype): Promise<LocalStats>;

Defined in: src/session/session.ts:1584

CMD_GET_STATS — local stats for the directly-connected device.

ParameterType
subtype"CORE" | "RADIO" | "PACKETS"

Promise<LocalStats>


repeaterLogin(contactKey, password): Promise<LoginSuccess & object>;

Defined in: src/session/session.ts:1512

Login to a repeater via CMD_SEND_LOGIN — the radio routes it (direct when the contact’s out_path is known, flood otherwise). An empty password is a guest login. Returns the effective mode so the UI can label the toast (Direct / Flood / N-hop).

ParameterType
contactKeystring
passwordstring

Promise<LoginSuccess & object>


repeaterLogout(contactKey): Promise<void>;

Defined in: src/session/session.ts:1519

ParameterType
contactKeystring

Promise<void>


repeaterRequestAcl(contactKey): Promise<AclEntry[]>;

Defined in: src/session/session.ts:1524

Request the ACL list. Admin-only (firmware returns nothing if guest).

ParameterType
contactKeystring

Promise<AclEntry[]>


repeaterRequestAvgMinMax(contactKey, opts): Promise<AvgMinMaxResult>;

Defined in: src/session/session.ts:1566

Request a min/max/avg series window from a sensor contact.

ParameterType
contactKeystring
opts{ endSecsAgo: number; startSecsAgo: number; }
opts.endSecsAgonumber
opts.startSecsAgonumber

Promise<AvgMinMaxResult>


repeaterRequestClock(contactKey): Promise<number>;

Defined in: src/session/session.ts:1554

Public anon CLOCK request — the repeater’s RTC clock (unix seconds).

ParameterType
contactKeystring

Promise<number>


repeaterRequestNeighbours(contactKey, opts?): Promise<NeighboursPage>;

Defined in: src/session/session.ts:1528

ParameterType
contactKeystring
opts{ count?: number; offset?: number; orderBy?: number; prefixLen?: number; }
opts.count?number
opts.offset?number
opts.orderBy?number
opts.prefixLen?number

Promise<NeighboursPage>


repeaterRequestOwnerInfo(contactKey): Promise<
| OwnerInfo
| null>;

Defined in: src/session/session.ts:1537

Fetch a repeater’s owner info via the PUBLIC anon OWNER request (works without a login). Returns null if the response can’t be parsed.

ParameterType
contactKeystring

Promise< | OwnerInfo | null>


repeaterRequestRegions(contactKey): Promise<string>;

Defined in: src/session/session.ts:1549

Public anon REGIONS request — the repeater’s region-name listing.

ParameterType
contactKeystring

Promise<string>


repeaterSendCli(contactKey, command): Promise<string>;

Defined in: src/session/session.ts:1574

Send a remote CLI command; the reply is routed back by sender prefix.

ParameterType
contactKeystring
commandstring

Promise<string>


repeaterTracePath(opts): Promise<TraceData>;

Defined in: src/session/session.ts:1579

CMD_SEND_TRACE_PATH — diagnostic trace along a known path.

ParameterType
opts{ authCode: number; flags?: number; pathHex: string; tag: number; }
opts.authCodenumber
opts.flags?number
opts.pathHexstring
opts.tagnumber

Promise<TraceData>


requestAutoAddConfig(): Promise<void>;

Defined in: src/session/session.ts:1254

Ask the radio for its current auto-add flags. RESP_AUTOADD_CONFIG lands in the feature handler → updates state + emits.

Promise<void>


requestBattAndStorage(): Promise<void>;

Defined in: src/session/session.ts:1302

Query battery + storage. Replies land in onPacket and update DeviceInfo.

Promise<void>


requestCustomVars(key?): Promise<void>;

Defined in: src/session/session.ts:1323

Query the firmware’s custom-var store (“gps”, “gps_interval”, etc.). Empty key requests all known keys. Reply: RESP_CUSTOM_VARS.

ParameterTypeDefault value
keystring''

Promise<void>


requestDeviceInfo(): Promise<void>;

Defined in: src/session/session.ts:1312

Re-issue DEVICE_QUERY to refresh DeviceInfo + capabilities.

Promise<void>


resetContactPath(contactKey): Promise<void>;

Defined in: src/session/session.ts:862

Drop a contact’s path back to flood. Mirrors CMD_RESET_PATH.

ParameterType
contactKeystring

Promise<void>


sendAnonReq(contactKey, anonType): Promise<Buffer<ArrayBufferLike>>;

Defined in: src/session/session.ts:1544

Low-level public anon request (CMD_SEND_ANON_REQ). anonType is one of Protocol.ANON_REQ_TYPE (REGIONS=1, OWNER=2, BASIC/CLOCK=3). Resolves the tagged response body. Prefer the typed wrappers below where they exist.

ParameterType
contactKeystring
anonTypenumber

Promise<Buffer<ArrayBufferLike>>


sendBinaryRequest(
contactKey,
reqData,
opts?): Promise<Buffer<ArrayBufferLike>>;

Defined in: src/session/session.ts:1561

Send a generic binary request to a contact and resolve the raw response body. reqData is [REQ_TYPE byte, …params]. The ACL/neighbours/owner/ avg-min-max helpers are thin wrappers over this.

ParameterType
contactKeystring
reqDataBuffer
opts{ timeoutMs?: number; }
opts.timeoutMs?number

Promise<Buffer<ArrayBufferLike>>


sendChannelData(opts): Promise<void>;

Defined in: src/session/session.ts:1468

Broadcast a group-channel datagram (CMD_SEND_CHANNEL_DATA, flood).

ParameterType
opts{ channelIdx: number; dataType: number; payload: Buffer; }
opts.channelIdxnumber
opts.dataTypenumber
opts.payloadBuffer

Promise<void>


sendChannelText(channelKey, text): Promise<{
channelHash?: number;
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:793

Returns ok on transport-level write success. When ok, channelHash is the byte the firmware tags GRP_TXT packets with on this channel — the caller uses it to register a pending-send entry so subsequent PUSH_CODE_LOG_RX_DATA observations matching that byte can be attributed back to the outgoing message (repeater relays we hear over the air).

ParameterType
channelKeystring
textstring

Promise<{ channelHash?: number; error?: string; ok: boolean; }>


sendControlData(payload): Promise<void>;

Defined in: src/session/session.ts:1463

Send a zero-hop control datagram (CMD_SEND_CONTROL_DATA).

ParameterType
payloadBuffer

Promise<void>


sendDmText(
contactKey,
text,
messageId,
opts?): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:800

Send a DM to a contact. Returns ok on transport-level write success; the message state machine continues asynchronously: RESP_SENT flips ‘sending’ → ‘sent’, PUSH_SEND_CONFIRMED flips ‘sent’ → ‘ack’.

ParameterType
contactKeystring
textstring
messageIdstring
opts{ attempt?: number; }
opts.attempt?number

Promise<{ error?: string; ok: boolean; }>


sendDmTextWithRetry(
contactKey,
text,
messageId): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:811

Send a DM with retry + flood fallback, mirroring the official client’s behavior.

ParameterType
contactKeystring
textstring
messageIdstring

Promise<{ error?: string; ok: boolean; }>


sendPathDiscoveryReq(contactKey): Promise<DiscoveredPath>;

Defined in: src/session/session.ts:1446

Discover the round-trip mesh path to a contact (floods a request, then awaits PUSH_PATH_DISCOVERY_RESPONSE). Rejects on dispatch error/timeout.

ParameterType
contactKeystring

Promise<DiscoveredPath>


sendRawData(opts): Promise<void>;

Defined in: src/session/session.ts:1458

Send raw bytes DIRECT along a known path (CMD_SEND_RAW_DATA).

ParameterType
opts{ pathHex: string; payload: Buffer; }
opts.pathHexstring
opts.payloadBuffer

Promise<void>


sendRawPacket(opts): Promise<void>;

Defined in: src/session/session.ts:1473

Transmit a fully-formed mesh packet (CMD_SEND_RAW_PACKET).

ParameterType
opts{ packetHex: string; priority: number; }
opts.packetHexstring
opts.prioritynumber

Promise<void>


sendSelfAdvert(flood?): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:1334

Send a self-advert. flood=true propagates many hops (so DM-able by distant peers); flood=false is zero-hop (cheap, only direct neighbors).

ParameterTypeDefault value
floodbooleantrue

Promise<{ error?: string; ok: boolean; }>


sendStatusReq(contactKey): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:1499

Request a status snapshot from a repeater/room/contact. The actual snapshot arrives later via PUSH_STATUS_RESPONSE → emit.repeaterStatus().

ParameterType
contactKeystring

Promise<{ error?: string; ok: boolean; }>


sendTelemetryReq(contactKey): Promise<{
error?: string;
ok: boolean;
}>;

Defined in: src/session/session.ts:1504

Request a CayenneLPP telemetry blob from a contact. See sendStatusReq.

ParameterType
contactKeystring

Promise<{ error?: string; ok: boolean; }>


setAdvertLatLon(
lat,
lon,
alt?): Promise<boolean>;

Defined in: src/session/session.ts:1193

Push device GPS coords used in self-adverts.

ParameterType
latnumber
lonnumber
alt?number

Promise<boolean>


setAdvertName(name): Promise<boolean>;

Defined in: src/session/session.ts:1168

Push the device’s advertised display name.

ParameterType
namestring

Promise<boolean>


setAutoAddConfig(flags): Promise<boolean>;

Defined in: src/session/session.ts:1247

Push the auto-add flags byte. App-side mode/maxHops/pullToRefresh/ showPublicKeys are stored locally and don’t go on the wire.

ParameterType
flagsAutoAddFlagsInput

Promise<boolean>


setChannel(
idx,
name,
secretHex): Promise<boolean>;

Defined in: src/session/session.ts:1077

Write a channel slot (add / edit / delete). Delete = empty name + zero key, which our enumerator filters as empty. Returns true if the radio acked, false on RESP_ERR / timeout / disconnect.

ParameterType
idxnumber
namestring
secretHexstring

Promise<boolean>


setContactFavourite(publicKeyHex, favourite): Promise<void>;

Defined in: src/session/session.ts:948

Toggle the favourite flag (contact flags bit 0). For on-radio contacts, round-trips CMD_ADD_UPDATE_CONTACT so the firmware persists the flag (protects from overwrite-oldest). Discovered-only contacts update locally.

ParameterType
publicKeyHexstring
favouriteboolean

Promise<void>


setContactPath(
contactKey,
outPathHex,
opts?): Promise<void>;

Defined in: src/session/session.ts:821

Write a contact’s out_path back to the radio so the firmware uses it for future source-routed sends. Round-trips the contact’s current type/flags/ name (firmware replaces on update, not merges). On RESP_OK, updates local state with the new path + pathManual.

ParameterType
contactKeystring
outPathHexstring
opts{ manual: boolean; preferDirect?: boolean; }
opts.manualboolean
opts.preferDirect?boolean

Promise<void>


setContactPreferDirect(contactKey, preferDirect): void;

Defined in: src/session/session.ts:980

Toggle the per-contact “always use direct (companion-side) login” flag. Local-only; no firmware write.

ParameterType
contactKeystring
preferDirectboolean

void


setDefaultFloodScope(name, keyHex): Promise<void>;

Defined in: src/session/session.ts:1386

Persist the default flood scope (CMD_SET_DEFAULT_FLOOD_SCOPE).

ParameterType
namestring
keyHexstring

Promise<void>


setDevicePin(pin): Promise<void>;

Defined in: src/session/session.ts:1425

Set the BLE pairing PIN (0 disables it; otherwise a 6-digit number).

ParameterType
pinnumber

Promise<void>


setDeviceTime(epochSecs): Promise<void>;

Defined in: src/session/session.ts:1352

Set the radio’s RTC clock (unix seconds). Rejects ProtocolError if the radio returns RESP_ERR (e.g. a clock earlier than its own → ILLEGAL_ARG).

ParameterType
epochSecsnumber

Promise<void>


setFloodScopeKey(input): Promise<void>;

Defined in: src/session/session.ts:1374

Override the send-scope key for outgoing flood packets (set / clear / unscoped).

ParameterType
inputFloodScopeInput

Promise<void>


setFloodScopeRegion(region): Promise<void>;

Defined in: src/session/session.ts:1381

Derive the 16-byte scope key for a public hashtag region (SHA-256(“#name”)[:16]) and set it as the send-scope override. Equivalent to setFloodScopeKey({ keyHex: deriveFloodScopeKey(region) }).

ParameterType
regionstring

Promise<void>


setGpsConfig(cfg): Promise<boolean>;

Defined in: src/session/session.ts:1261

Toggle the GPS module / change interval via custom-var KV. The firmware ignores intervals outside [60, 86399]; we clamp client-side too.

ParameterType
cfg{ enabled: boolean; intervalSec: number; }
cfg.enabledboolean
cfg.intervalSecnumber

Promise<boolean>


setOtherParams(policy, sharePositionInAdvert): Promise<boolean>;

Defined in: src/session/session.ts:1214

Push telemetry policy + multi-acks + advert-location-policy as one frame. The advert-location-policy flag mirrors DeviceIdentity.sharePositionInAdvert and TelemetryPolicy fields drive the rest.

ParameterType
policy{ base: 0 | 1 | 2; env: 0 | 1 | 2; loc: 0 | 1 | 2; multiAcks: number; }
policy.base0 | 1 | 2
policy.env0 | 1 | 2
policy.loc0 | 1 | 2
policy.multiAcksnumber
sharePositionInAdvertboolean

Promise<boolean>


setPathHashMode(size): Promise<void>;

Defined in: src/session/session.ts:990

Set the radio’s global path-hash mode (bytes per hop). Persists on the radio and updates local RadioSettings on RESP_OK.

ParameterType
size1 | 2 | 3

Promise<void>


setRadioParams(opts): Promise<boolean>;

Defined in: src/session/session.ts:1113

Push LoRa modulation params (freq/bw/sf/cr) and TX power to the radio. Sent as two separate frames since the firmware splits them. Includes the trailing clientRepeat byte only when the connected firmware supports it (ver_code ≥ 9 — surfaced via DeviceCapabilities.repeatMode).

ParameterType
opts{ bandwidthHz: number; codingRate: number; frequencyHz: number; repeatMode: boolean; spreadingFactor: number; txPowerDbm: number; }
opts.bandwidthHznumber
opts.codingRatenumber
opts.frequencyHznumber
opts.repeatModeboolean
opts.spreadingFactornumber
opts.txPowerDbmnumber

Promise<boolean>


setTuningParams(params): Promise<void>;

Defined in: src/session/session.ts:1369

Write the radio airtime/backoff tuning params (CMD_SET_TUNING_PARAMS).

ParameterType
paramsTuningParams

Promise<void>


shareContact(destPublicKeyHex): Promise<void>;

Defined in: src/session/session.ts:1480

Re-broadcast a known contact’s advert zero-hop (CMD_SHARE_CONTACT).

ParameterType
destPublicKeyHexstring

Promise<void>


signData(data): Promise<string>;

Defined in: src/session/session.ts:1438

Sign arbitrary bytes with the device’s ed25519 identity. Drives the CMD_SIGN_START → CMD_SIGN_DATA× → CMD_SIGN_FINISH state machine and returns the 64-byte signature (hex).

ParameterType
dataBuffer

Promise<string>


start(): void;

Defined in: src/session/session.ts:227

void


stop(): void;

Defined in: src/session/session.ts:257

void


syncDeviceTime(): Promise<void>;

Defined in: src/session/session.ts:1357

Push the host’s current time to the radio.

Promise<void>