Version     Dependency Status Code Climate Build Status Coverage

Mosca

A simple client for mqtt communication

Installation

Add this line to your application's Gemfile:

gem 'mosca'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mosca

Usage

Configure

You can configure the default timeout for response, and default mqtt broker.

  Mosca::Client.default_timeout = 10 # 10 seconds
  Mosca::Client.default_broker = "test.mosquitto.org"

New instance

  client = Mosca::Client.new user: "username", pass: "password", topic_in: "readings", topic_out: "commands", topic_base: "/device/"

Publishing

Single message

  client.publish "restart" # will be sent to topic /device/commands

Message with response

  response = client.publish "some_command", response: true, topic_in: "responses" # will publish and wait for a response on the /device/responses topic

Getting messages

  puts client.get # will wait up to Mosca.default_timeout (default 5) seconds. will return if no response comes.

  puts client.get timeout: 2, topic_in: "another_topic" # will wait up to 2 seconds for a response on the another_topic topic.

TO DO

Readme not complete yet

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request