How to use a SpringCore network device as a SmartReader/MQTT client

The aim of this tutorial is to configure a SpringPark as a Network SmartReader using MQTT. The SpringPark in this configuration acts as an MQTT client and sends its tags to the broker.

For this howto, we will assume that:

  • your SpringPark is using a default (from factory) configuration.
  • you have some networking basis.

Our SpringPark will output tag information using the SCRDR format (cf. SCRDR Protocol).

Understanding MQTT

MQTT is a client/server publish/subscribe messaging transport protocol. It is lightweight, open, simple, and designed to be easy to implement. These characteristics make it ideal for use in many situations, including constrained environments such as for communication in Machine to Machine (M2M) and Internet of Things (IoT) contexts where a small code footprint is required and/or network bandwidth is limited.

In MQTT a client publishes messages on a topic and another client must subscribe to that topic to view the message.

Publishers and subscribers do not communicate directly, they meet through a broker which contains the differents topics as shown in the diagram below:

Important points to note:

  • Messages are published to a broker on a topic.
  • The job of an MQTT broker is to organize messages based on topic, and then distribute them to subscribers.
  • A client can receive these messages by subscribing to that topic on the same broker
  • There is no direct connection between a publisher and subscriber.
  • All clients can publish (broadcast) and subscribe (receive).
  • MQTT brokers do not normally store messages, only the clients currently connected which have subscribed to the topic receives the message

To have a better understanding of the MQTT protocol and other features, you can follow theses series of articles:

You can find the official MQTT v5.0 documentation at this address:

http://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html

Your first connection to a public MQTT broker

First, we are going to test the springpark on a public MQTT broker for test purposes.

In this example we will use the broker provided by Hive MQ at the address: broker.hivemq.com:1883 (and port 8000 for the websocket)

Secondly, we need to configure our SpringPark to connect to the broker. 

To do so we will need to edit two registers:

  • register 0x86: MQTT Broker address or name, we set it to “broker.hivemq.com”
  • register 0xC0: Profile, we use the MQTT client along with the $SCRDR protocol

Below is the detail of the register 0xC:

Note: by default the SpringPark is a DHCP client, so it will not need any particular network configuration when you plug it into your network.

The JSON configuration file will look like this:

This file can be downloaded here: springcore-mqtt-hivemq.json

To upload the configuration, SpringCoreConfig can be used:

To known more about how to configure your network device through SpringCoreConfig; read this article:

How to setup and use a SpringPark as a smartreader HTTP client

Once configured the device will reboot and send the tags and the status messages to the broker.

To see the message we will need to subscribe to the broker. To do so, download mosquitto-clients.

On Debian/Ubuntu, you can use this command:

sudo apt-get install mosquitto-clients

Then, use this command to listen to the topics:

mosquitto_sub -t "springcard/springcore/#" -h broker.hivemq.com

The “-t” option is to specify the topic we will subscribe to. The “-h” option is for the hostname of the broker.

The port used is 1883, it is the default MQTT port so we don’t need to specify it at the command line.

The special character “#” is a multi-level wildcard covering many lower topic levels. 

There is also “+” that substitute any topic name but only on one level

Another solution to see the messages published: we can use the MQTT Browser client to connect to the websocket exposed by the broker on port 8000.

Below is an example of messages received by the broker, the websocket client can be found here:

http://www.hivemq.com/demos/websocket-client/

SpringCore SmartReader MQTT topics and data

You can find more relevant information about out to configure the SpringPark in MQTT client here:

https://docs.springcard.com/books/SpringCore/Host_interfaces/Physical_and_Transport/Network/MQTT_Client/Configuration

We will stop at the $SCRDR mode, but keep in mind that you can also use the SpringPark in MQTT client to use the PC/SC-like API and the SpringCore direct Protocol too.

There are 2 main topics:

  • springcard/springcore/{$id}/rdr/evt where the device publishes his event (ex: when a tag has been read)
  • springcard/springcore/{$id}/rdr/cmd to send some 

There is also some other topics shared with the other modes:

  • springcard/springcore/{$id}/status where the device periodically publishes its status (online, offline, uptime…)
  • springcard/springcore/{$id}/meta where the device publish some information about itself

The full list of all the topics used for all mode is here:

https://docs.springcard.com/books/SpringCore/Host_interfaces/Physical_and_Transport/Network/MQTT_Client/Topics

Going further

It is also possible to use SpringCard Companion to create a configuration and use some templates to specify the data we want to read from the NFC tags or phones.

To go further, you can read the article about TLS security in the SpringPark and how to use the SpringPark with AWS.


Posted

in

,

by