Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ethymoney/kaluma-mqtt

Kaluma library for the MQTT protocol
https://github.com/ethymoney/kaluma-mqtt

javascript kaluma mqtt mqtt-client pico-w raspberry-pi-pico

Last synced: about 1 month ago
JSON representation

Kaluma library for the MQTT protocol

Awesome Lists containing this project

README

        

# kaluma-mqtt
Kaluma library for the MQTT protocol

### This library is NOT stable and still very much active development. DO NOT use until this is updated to say so.

# Basic Example:
```javascript
const { WiFi } = require('wifi');
const { MQTTClient } = require('mqtt');

const wifi = new WiFi();
cont mqttClient = new MQTTClient('myClientId', 'myBrokerIp');

// Connect to WiFi and then connect to MQTT broker
wifi.connect({ ssid: 'my-wifi-name', password: 'my-password' }, (err) => {
if (err) {
console.error(err);
} else {
console.log('connected to wifi, connecting to MQTT broker');
mqttClient.connect();
}
});

// MQTT client event handlers
mqttClient.on('connect', () => {
console.log('Connected to MQTT broker');
mqttClient.publish('my-topic', 'hello world!');
});

// data is an object that contains the message and topic as properties
mqttClient.on('message', (data) => {
console.log('Received message:', data.message.toString(), 'on topic:', data.topic);
});

mqttClient.on('disconnect', () => {
console.log('Disconnected from MQTT broker');
});

mqttClient.on('error', (err) => {
console.error('Error:', err);
});

```