MQTT-SN Gateway Library
Library that allows implementation of MQTT-SN gateway.
MQTT-SN Gateway Library

Overview

The MQTT-SN Gateway Library provides simple, asynchronous, non-blocking, and easy to use interface to implement and operate MQTT-SN gateway. The library doesn't make any assumption on the system it is running on, as well as on the type of I/O links being used to communicate with MQTT-SN clients as well as MQTT broker.

Having a gateway library instead of stand alone application allows implementation of any custom gateway that is suitable for the environment it is running on, working with any I/O link, and using any other additional transport protocol to exchange data with clients and/or broker.

The library is implemented in C++(11). It provides two separate APIs: C++ and C. The C interface is a wrapper around C++ one, but provides an interface to be used with any project developed using C.

Various I/O Links

MQTT-SN is designed to be a datagram protocol, i.e. if sent message is received by the other side, it is received in full and without errors. If sent over UDP link, it can be used as is. The UDP transport cares about all the rest. However, when sent over other I/O link, such as RS-232 serial connection, the protocol may require additional transport wrapping to insure correct delivery and differentiate between packets.

The interface, this MQTT-SN Gateway Library provides, allows any sent or received data to be wrapped with or unwrapped from additional independent transport data, that insures safe and correct delivery.

Headers

To use the C++ interface, use the following include statement:

Accumulates all the necessary includes for C++ interface.

Per-entity includes can also be used (see Entities)

Contains interface of cc_mqttsn_gateway::Config class.
Contains interface of cc_mqttsn_gateway::Gateway class.
Contains interface of cc_mqttsn_gateway::Session class.

And for C interface, use the the following include statement:

C interface for MQTT-SN Gateway library.

Entities

The gateway library works with and provides an interface for three intependent entities.

  • Gateway - Its main responsibility to advertise presence of the MQTT-SN gateway to all the clients on the network. If there is no need to advertise a presence, this entity may not be created or used. Example for such case would be UDP/IP network where the clients know up front the address of the gateway, and do not require gateway advertising its presence. For API description and tutorial, please read the Gateway page.
  • Session - It is responsible to inteligently forward traffic between single client and the broker. New "session" object must be created when message from new client has been received. Once the relevant client gets disconnected, the "session" object needs to be deleted. For API description and tutorial, please read the Session page.
  • Config - It is responsible to provide a common way to parse the configuration file and provide a convenient interface to retrieve any configuration values, which can later be applied to the Gateway and/or Session entities. The format of the configuration file is described in the example config file provided with the project. For API description and tutorial, please read the Config page.

Thread Safety

Parallel access to the distinct objects is safe, but parallel access to the same one is NOT.