Registry / communication / meshblu-websocket

meshblu-websocket

JSON →
library4.0.0jsnpmunverified

A pure WebSocket implementation of the Meshblu client for connecting to the Octoblu IoT platform (v4.0.0). This package provides a lightweight, browser-compatible alternative to the HTTP-based Meshblu client, enabling real-time communication over WebSockets. It supports key Meshblu operations such as device registration, message publishing/subscribing, and config updates. The library has low release cadence (last updated 2021) and is designed for use with Node.js or in the browser via bundlers. Key differentiators: no HTTP dependencies, full duplex communication, and direct use of native WebSocket API.

npm install meshblu-websocket
INSTALL
IMPORT
SIG · MESHBLU-WEBSOCKET
M
meshblu-websocket
communicationjavascriptv4.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MeshbluWebsocket
const MeshbluWebsocket = require('meshblu-websocket');
import MeshbluWebsocket from 'meshblu-websocket';
Package uses CommonJS; default export is a constructor. ESM import may fail without a default wrapper.
MeshbluWebsocket (TypeScript)
import MeshbluWebsocket = require('meshblu-websocket');
import * as MeshbluWebsocket from 'meshblu-websocket';
In TypeScript, use import = require for CJS modules. The package does not ship type definitions.
MeshbluWebsocket (browser)
const MeshbluWebsocket = window.MeshbluWebsocket;
import { MeshbluWebsocket } from 'meshblu-websocket';
In browser, the package attaches to window when loaded via script tag. Named imports from bundle won't work.

Initializes a Meshblu WebSocket client, connects to the Octoblu platform, subscribes to device config updates, and pushes data.

const MeshbluWebsocket = require('meshblu-websocket'); const MeshbluConfig = require('meshblu-config'); const meshbluConfig = new MeshbluConfig().toJSON(); const meshblu = new MeshbluWebsocket(meshbluConfig); meshblu.connect(function(error) { if (error) { console.error(error.message); return; } meshblu.subscribe({ uuid: meshbluConfig.uuid }); meshblu.on('config', function(data) { console.log('config', data); }); meshblu.updateDangerously({ uuid: meshbluConfig.uuid, token: meshbluConfig.token }, { '$push': { stuff: { foo: 'bar' } } }); });
Debug
Known issues
breakingModification of meshbluConfig object after client creation may cause unexpected behavior
fix
Store a copy of meshbluConfig or do not mutate after passing to constructor.
affects: >=4.0.0
deprecatedThe 'updateDangerously' method is deprecated in newer Meshblu versions; use 'update' instead
fix
Replace updateDangerously calls with meshblu.update() for safe updates.
affects: >=4.0.0
gotchaPackage does not handle reconnection automatically; client must manually reconnect on disconnect
fix
Listen for 'close' event and call meshblu.connect() to re-establish connection.
affects: >=4.0.0
gotchaIn Node.js, the 'ws' module is required; in browser, native WebSocket is used. Ensure correct environment setup
fix
For Node.js, 'npm install ws'. For browser, include a polyfill if needed.
affects: >=4.0.0
breakingThe 'connect' callback is called before subscription is actually established; subscribing inside callback may fail if server not ready
fix
Use the 'ready' event instead of connect callback to ensure subscriptions are active.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'uuid' of undefined
meshbluConfig object is empty or not initialized correctly
fix
Ensure MeshbluConfig is instantiated with proper environment variables or config file.
Error: connect ECONNREFUSED <host>:<port>
WebSocket server is not running or unreachable
fix
Verify Meshblu server URL and port in configuration; ensure server is running.
ReferenceError: WebSocket is not defined
Running in Node.js without 'ws' package installed
fix
Run 'npm install ws' or use a browser environment where WebSocket is native.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
wsoptionalWebSocket implementation for Node.js; not needed in browser
meshblu-configoptionalUsed in examples for configuration, not a runtime dependency
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
meshblu-websocket — npm install meshblu-websocket · libregistry