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.
The library is available from NPM and can be installed with:
yarn add @meshtastic/meshtasticjs
npm install @meshtastic/meshtasticjs
If you prefer a pre-bundled version you can generate one with the following command from inside the projects folder:
npm run build && npm install --global webpack-cli && webpack-cli --entry ./dist -o dist/bundle.js
yarn build && yarn global add webpack-cli && webpack-cli --entry ./dist -o dist/bundle.js
The library has a built in connection manager that will handle multiple devices of different connection types.
import { Client } from "meshtasticjs";
// Instantiate a new device manager
const client = new Client();
// Create the connection type of your choice
const httpConnection = client.createHTTPConnection();
const bleConnection = client.createBLEConnection();
// connect to the device with the desired paramaters
httpConnection.connect(...connectionParams);
bleConnection.connect(...connectionParams);
// Device can now be accessed individually or via `deviceInterfaces`
client.deviceInterfaces.forEach(connection => {
...
})
All events can be handled via any of the inbuilt on**x**Event methods.
// Avaliable methods: onFromRadioEvent, onDataPacketEvent, onUserPacketEvent,
// onPositionPacketEvent, onConnectedEvent, onDisconnectedEvent, onConfigDoneEvent
httpConnection.onFromRadioEvent.subscribe(event => {
...
})
Data in multiple formats can be send over the radio
// Plain text message
bleConnection.sendText("Message");
// With recipient
bleConnection.sendText("Message", 1234);
// Arbitrary data
bleConnection.sendData(new Uint8Array([...data]));
// Send custom location
bleConnection.sendPosition(lat, lng, alt, time);
The Bluetooth connection option relies on the availability of the Web Bluetooth API, which is represented in the compatibility matrix below.