examples/networking/mqtt/emcute_mqttsn/README.md
This application demonstrates the usage of the emCute (MQTT-SN) module in RIOT.
For using this example, two prerequisites have to be fulfilled:
In general, any MQTT-SN capable broker or broker/gateway setup will do. Following a quick instruction on how-to setup the Mosquitto Real Simple Message Broker:
git clone https://github.com/eclipse/mosquitto.rsmb.git
cd mosquitto.rsmb/rsmb/src
make
config.conf:# add some debug output
trace_output protocol
# listen for MQTT-SN traffic on UDP port 1885
listener 1885 INADDR_ANY mqtts
ipv6 true
# listen to MQTT connections on tcp port 1886
listener 1886 INADDR_ANY
ipv6 true
./broker_mqtts config.conf
You can refer to https://rawgit.com/MichalFoksa/rsmb/master/rsmb/doc/gettingstarted.htm for more configuration options.
nativeWhen running this example under native, we must configure some global addresses, as the RSMB doesn't seems to be able to handle link-local addresses. So for a single RIOT native instance, we can do the following:
tap and tapbr devices using RIOT's tapsetup script:sudo ./RIOTDIR/dist/tools/tapsetup/tapsetup
tapbr0 interface (the name could be
different on your machine etc):sudo ip a a fec0:affe::1/64 dev tapbr0
native
instance (open first with BOARD=native make term):ifconfig 5 add fec0:affe::99
This example maps all available MQTT-SN functions to shell commands. Simply type
help to see the available commands. The most important steps are explained
below:
con command:con fec0:affe::1 1885
sub with the topic name as parameter, e.g.sub hello/world
pub command:pub hello/world "One more beer, please."
That's it, happy publishing!
Each node that connects to the broker must have a unique node ID string set. Per
default, this example sets this statically ID to gertrud. If you want to
connect more than one node to the broker, you need to set a custom ID for each
node during compile time. Simply use the EMCUTE_ID environment variable for
this, e.g. build with EMCUTE_ID=horst make all.
The UDP socket handling for IPv6 based endpoints in the Mosquitto.rsmb
implementation is buggy when it comes to handling link local addresses,
as the implementation does not remember the interface on which data comes in,
hindering it from sending out any responses.
Workaround: either use global IPv6 addresses or ULAs.
It also seems that the Mosquitto.rsmb implementation has a bug when it comes
to subscribing to topics: if a topic name was formerly registered and the same
topic name is later used for issuing a subscription request, the gateway will
assign a new topic ID to the same topic name, so publish messages to the
initially assigned topic ID will not be seen by that subscription.