2025-02-12 23:08:24 +13:00
# MeshCore.js
2025-12-09 19:54:39 -08:00
A Javascript library for interacting with a [MeshCore ](https://github.com/meshcore-dev/MeshCore ) device running the [Companion Radio Firmware ](https://github.com/meshcore-dev/MeshCore/blob/main/examples/companion_radio/main.cpp ).
2025-02-12 23:08:24 +13:00
2025-03-04 16:50:47 +13:00
This library can be used in a Web Browser to connect to MeshCore Companion devices over BLE or USB Serial.
2025-04-08 13:27:25 +12:00
It can also be used in NodeJS to connect to MeshCore Companion devices over TCP/WiFi or USB Serial.
2025-03-04 16:50:47 +13:00
2025-04-08 13:49:42 +12:00
## Supported Connection Methods
- Web Browser
2025-12-09 19:54:39 -08:00
- BLE: [WebBleConnection() ](./src/connection/web_ble_connection.js )
- USB/Serial: [WebSerialConnection() ](./src/connection/web_serial_connection.js )
2025-04-08 13:49:42 +12:00
- NodeJS
2025-12-09 19:54:39 -08:00
- TCP/WiFi: [TCPConnection("host", "port") ](./src/connection/tcp_connection.js )
- USB/Serial: [NodeJSSerialConnection("/dev/ttyUSB0") ](./src/connection/nodejs_serial_connection.js )
2025-04-08 13:49:42 +12:00
2025-03-04 17:42:20 +13:00
## Install
```
npm install @liamcottle/meshcore .js
```
## Simple Example
```
2025-04-08 14:54:10 +12:00
import { TCPConnection, NodeJSSerialConnection } from "@liamcottle/meshcore .js";
2025-03-04 17:42:20 +13:00
2025-04-08 14:54:36 +12:00
// serial connections are supported by "companion_radio_usb" firmware
2025-04-08 14:54:10 +12:00
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);
2025-03-04 17:42:20 +13:00
// 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 ](./examples ) folder.
2025-02-12 23:08:24 +13:00
## License
MIT