Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tiagostutz/simple-mqtt-client
Simple mqtt client that links subscriptions directly to callbacks
https://github.com/tiagostutz/simple-mqtt-client
Last synced: 22 days ago
JSON representation
Simple mqtt client that links subscriptions directly to callbacks
- Host: GitHub
- URL: https://github.com/tiagostutz/simple-mqtt-client
- Owner: tiagostutz
- Created: 2018-10-21T19:27:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-01T17:02:28.000Z (over 5 years ago)
- Last Synced: 2024-10-10T23:16:14.161Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple MQTT Client
A simple MQTT client that allows you to link your subscriptions directly to callback functions.
## How to use?
First, install the lib:
`npm i --save simple-mqtt-client`
Then use it as follows:
```javascript
const mqttProvider = require('simple-mqtt-client')
mqttProvider.new().init("https://iot.eclipse.org/ws", "", "", "simple-mqtt-client/test", (mqttClient) => {
mqttClient.subscribe("simpleTest", (msg) => {
console.log("message:", msg.text)
})mqttClient.publish("simpleTest", { text: "HelloWorld!" })
});
```The parameters you provide to the `init` function are:
- mqttBrokerHost: MQTT broker to connect; it can be a TCP address connection (_mqtt://_), **Websocket** (_http://_) or **Websocket Secure** (_https://_)
- mqttUserName: Used if your broker requires authentication
- mqttPassord: Used if your broker requires authentication
- baseTopic: A base topic to append to the topic passed as parameter to every `publish`, `subscribe` or `unsubscribe` invocation
- readyCallback(mqttClient): callback function invoked when the MqttClient is prepared