Meshtastic.js
Overview
Meshtastic.js is a JavaScript library that provides an interface to Meshtastic devices. It can be used to build applications to interface with a Meshtastic network. Currently HTTP(S) and Bluetooth connections are supported.
Documentation/API Reference
Installation & Usage
The library is available from NPM and can be installed with:
yarn add @meshtastic/meshtasticjs
npm install @meshtastic/meshtasticjs
Usage
The library has a built in connection manager that will handle multiple devices of different connection types.
import {
Client,
Types,
SettingsManager,
} from "meshtasticjs";
const client = new Client();
SettingsManager.setDebugMode(Protobuf.LogLevelEnum.DEBUG);
const httpConnection = client.createHTTPConnection();
const bleConnection = client.createBLEConnection();
httpConnection.connect(...connectionParams);
bleConnection.connect(...connectionParams);
client.deviceInterfaces.forEach(connection => {
...
});
All events can be handled via any of the inbuilt onxEvent methods.
httpConnection.onFromRadioEvent.subscribe(event => {
...
});
Sending data
Data in multiple formats can be send over the radio
bleConnection.sendText("Message");
bleConnection.sendText("Message", 1234);
bleConnection.sendPacket(
new Uint8Array([...data]),
Protobuf.PortNumEnum.PRIVATE_APP
);
bleConnection.sendPosition(lat, lng, alt, time);
Compatibility
The Bluetooth connection option relies on the availability of the Web Bluetooth API, which is represented in the compatibility matrix below.