# MQTT Client

A simple client to listen a broker.

## How to install

`npm intall [--save] mqtt-client`

## MQTT Client dependencies

1. bomo-logger
1. events
1. bh-configuration

## How to use

### Js core file
```js
var mqttClient = require('mqtt-client');
var loggerProto = require('bomo-logger');
var events = require('events');
var bhConfigurationProto = require('bh-configuration');

var emitter = new events();
var configuration = new bhConfigurationProto('conf/mqtt-live-object.json');

var logger = new loggerProto(
  configuration
    .asSection()
    .section('logger')
);

mqttClient
  .setLogger(logger)
  .setEmitter(emitter)
  .setConfig(
    configuration
      .asSection()
      .section('mqtt')
  )
  .init()
;
```

### Configuration file
```json
{
  "mqtt": {
    "protocol": "mqtt",
    "hostname": "localhost",
    "username": "",
    "password": "",
    "port": "1883",
    "subscriptions": [
      "#"
    ]
  }
}
```

You can refere on [official website](https://www.npmjs.com/package/mqtt#client) to know all available options. Just add them on this Json object.

### How to deal with messages

All messages are dispatched on `mqtt-client::message` channel

```js
emitter.on('mqtt-client::message', function(args) {
    console.log(args)
}

```
