mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
No description
WebBleConnection's constructor calls init(), which is async. Constructors can't be async, so this means that callers who instantiate WebBleConnection can end up with it in an invalid state after construction if init() hasn't completed by the time the caller tries to access class members that depend on init.
I think the cleaner solution is to push the init() call to open(), which is async, so it can just await the results of init(), and the caller can trust that after calling open(), the connection is fully initialized.
This is a second attempt (see
|
||
|---|---|---|
| examples | ||
| src | ||
| .gitignore | ||
| .npmignore | ||
| index.html | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
MeshCore.js
A Javascript library for interacting with a MeshCore device running the Companion Radio Firmware.
This library can be used in a Web Browser to connect to MeshCore Companion devices over BLE or USB Serial.
It can also be used in NodeJS to connect to MeshCore Companion devices over TCP/WiFi or USB Serial.
Supported Connection Methods
- Web Browser
- BLE: WebBleConnection()
- USB/Serial: WebSerialConnection()
- NodeJS
- TCP/WiFi: TCPConnection("host", "port")
- USB/Serial: NodeJSSerialConnection("/dev/ttyUSB0")
Install
npm install @liamcottle/meshcore.js
Simple Example
import { TCPConnection, NodeJSSerialConnection } from "@liamcottle/meshcore.js";
// serial connections are supported by "companion_radio_usb" firmware
const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");
// tcp connections are supported by "companion_radio_wifi" firmware
// const connection = new TCPConnection("10.1.0.226", 5000);
// wait until connected
connection.on("connected", async () => {
// we are now connected
console.log("connected!");
// log contacts
const contacts = await connection.getContacts();
for(const contact of contacts) {
console.log(`Contact: ${contact.advName}`);
}
// disconnect
connection.close();
});
// connect to meshcore device
await connection.connect();
Examples
There's a few other examples scripts in the examples folder.
License
MIT