1.1.3 • Published 2 years ago

mqttsngw-mqttbroker v1.1.3

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

MQTT-SN Gateway: MQTTBroker

This module is part of mqttsngw. It is responsible for handling and maintaining connections to the MQTT broker.

Factory

const Broker = require('mqttsngw-mqttbroker');
mqttsngw.attach(Broker(opts));

Creates a new MQTTBroker factory and attaches it to an existing instance of mqttsngw. opts has the following fields:

  • log: Optional. An object containing logging callbacks for all log levels (error, warn, info, debug). Every callback is called with a human-readable message as the first argument followed by an object containing more information regarding the event: { error: (msg, info) => { ... }, ...}.
  • broker: Mandatory. Callback function for creation of individual client configuration based on the clientId: (clientId) => clientOpts. clientOpts is an object:
    • url: Mandatory. URL pointing to the broker.
    • All other options accepted by the connect method of MQTT.js

State Machines

MQTTBroker Main

  • listening: Listens for incoming connection requests from the event bus. If a request is received, a new instance of MQTTBroker Client is created and started.

MQTTBroker Client

Handles connection to the broker.

  • init: Preparing the state machine.
  • connect: Tries to connect to the broker.
  • connected: The connection has been successfully established.

Events

Several events are consumed and emitted by the MQTTBroker module on the event bus.

Consumed

EventState MachineDescription
brokerConnect,*,reqMQTTBroker MainConnection request
brokerSubscribe,*,reqMQTTBroker ClientRequest subscription to a topic
brokerUnsubscribe,*,reqMQTTBroker ClientRequest unsubscribing a topic
brokerPublishFromClient,*,reqMQTTBroker ClientA sensors publishes a message to the broker
brokerPublishToClient,*,resMQTTBroker ClientResponse whether a message has been published to a client
brokerDisconnect,*,callMQTTBroker ClientDisconnect from the broker

Emitted

EventState MachineDescription
brokerConnect,*,resMQTTBroker ClientResponse to a connection request
brokerSubscribe,*,resMQTTBroker ClientResponse to a subscription request
brokerUnsubscribe,*,resMQTTBroker ClientResponse to a unsubscribe request
brokerPublishFromClient,*,resMQTTBroker ClientResponse whether a message has been published to the broker
brokerPublishToClient,*,reqMQTTBroker ClientThe broker publishes a message to the client
brokerDisconnect,*,notifyMQTTBroker ClientInforms the client that the connection has been closed
1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago