Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/84codes/mqtt-client.cr


https://github.com/84codes/mqtt-client.cr

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# MQTT-Client

A MQTT client built in Crystal.

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
dependencies:
mqtt-client:
github: 84codes/mqtt-client.cr
```

2. Run `shards install`

## Usage

```crystal
require "mqtt-client"

mqtt = MQTT::Client.new("localhost", 1883)

mqtt.on_message do |msg|
puts "Got a message, on topic #{msg.topic}: #{String.new(msg.body)}"
end

mqtt.subscribe("foo", qos: 1)

mqtt.publish("foo", "bar", qos: 1)

mqtt.close
```