Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/anasnew99/mqtt-cli

Simple MQTT CLI Created in NodeJS
https://github.com/anasnew99/mqtt-cli

cli mqtt mqtt-cli mqtt-client pubsub

Last synced: 1 day ago
JSON representation

Simple MQTT CLI Created in NodeJS

Awesome Lists containing this project

README

        

# [mqtt-client-cli](https://github.com/Anasnew99/mqtt-cli)

> A simple MQTT Client CLI.

> This library is created and maintained by [Anas Aneeque](https://www.linkedin.com/in/anasnew99/)

> This library is written for Node.js

> Written in typescript.

# Features

- Connect to MQTT Server using broker url.
- Test MQTT Connections.
- Subscribe topic and receive messages.
- Publish message to topic.

# Usage

## Use it with CLI.

```
npm i -g mqtt-client-cli
mqtt-client-cli
```

or also you can use shorthand

```
mcc
```

Broker URL Example

```
protocol://user:password@host:8883/path
```

![Usage Example](https://raw.githubusercontent.com/Anasnew99/mqtt-cli/main/example/connect.jpg)

Subscribe to a topic

```
sub Hello
```

![Subscribe Example](https://raw.githubusercontent.com/Anasnew99/mqtt-cli/main/example/sub.jpg)

Now to check whether we are really subscribed, we will publish a message to Hello

```
pub Hello "Hello World"
```

![Publish Example](https://raw.githubusercontent.com/Anasnew99/mqtt-cli/main/example/pub.jpg)

Voila we received a message, output format of the recieved message is '@'

Any error occur in subscribing or publishing, a log will be received

![Error Example](https://raw.githubusercontent.com/Anasnew99/mqtt-cli/main/example/error.jpg)

At last, exit anytime by pressing e.

## Use as a package in other nodejs app.

Install it in your project.

```
npm install mqtt-client-cli
```

Use in your project with same interface as of cli.

```js
const { connectMQTT } = require("mqtt-client-cli");
connectMQTT("ws://localhost:1883");
```

# Support

Buy Me A Coffee