Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

ionia-corporation/mosca

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"

Environment variables

The following environment variables are used when creating clients, so you can use something like dotenv to put them on a file:

MOSCA_BROKER
MOSCA_USER
MOSCA_PASS
MOSCA_TIMEOUT

New instance

  # Params (all optional)
  # user
  # pass
  # broker
  # topic_in
  # topic_out
  # topic_base (topics out and in are appended to this)

  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. Returns nil if timed out.
  client.publish! "restart" # Raises Timeout::Error if timed out.

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 nil 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.
  client.get! # Raises exception if timed out

###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

About

A simple client for mqtt communication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages