MQTT-SN Gateway Library
Library that allows implementation of MQTT-SN gateway.
|
The Gateway object is responsible to advertise the gateway presence to all the possible clients on MQTT-SN network. If such advertisement is not needed, there is no need to create or use the Gateway object.
When using C++ interface, just instantiate object of cc_mqttsn_gateway::Gateway class. The destruction of the object will clean up all acquired resources.
When using C interface, the allocation is performed using cc_mqttsn_gw_alloc()
and de-allocation is performed using cc_mqttsn_gw_free() functions.
As was stated, the Gateway object is responsible to periodically broadcast ADVERTISE messages to all MQTT-SN clients on the network to advertise its presence. The library just generates the binary data, that needs to be sent, and uses a callback function to request the driving code to send this data over I/O link being used. The required callback needs to be provided by the driving code.
C++ interface:
C interface:
As was mentioned earlier there is a need to send ADVERTISE messages periodically. As the result the Gateway object needs to perform some time measurement. It relies on the driving code to provide such service. There is a need to set appropriate callback:
C++ interface:
C interface:
After the requested time expires, the driving code needs to notify the Gateway object. It must call the appropriate tick() function.
C++ interface:
C interface:
The ADVERTISE message must be sent periodically. The message itself contains information when next ADVERTISE message will be sent. The Gateway object cannot operate without the advertise period being set.
C++ interface:
C interface:
It is also possible to retrieve the current configuration:
C++ interface:
C interface:
The ADVERTISE message also contain 1 byte of numeric gateway ID. If the actual gateway ID differs from default value 0. It must be provided to the Gateway object.
C++ interface:
C interface:
It is also possible to retrieve the current configuration:
C++ interface:
C interface:
After all the callbacks have been set and the advertise period was provided, the operation of the Gateway object needs to be properly started.
C++ interface:
C interface:
If the start is successful, the Gateway object will immediatelly request to send new ADVERTISE message and will request a time measurement for the next time.
If the Gateway's operation needs to be paused for a while, use cc_mqttsn_gateway::Gateway::stop() or cc_mqttsn_gw_stop() functions. The operation can be resumed using cc_mqttsn_gateway::Gateway::start() or cc_mqttsn_gw_start() respectively.
C++ interface:
C interface: