Datacake Docs
  • Welcome
  • Get Started
  • Changelog
  • Best practices
    • Best practices: Getting started
    • Best practices: Resolution (Timeframe)
    • Best practices: Dashboards
    • Best practices: Reports
    • Best practices: Grouping Devices
  • Datacake LNS
    • Getting Started
    • Gateways
      • Milesight LoRaWAN Gateway - UG6x
      • RAKwireless WisGate Edge Light 2
    • Devices
    • Add Devices without Gateway
  • Wireless IoT Hub
    • Overview
    • Datasheet
    • Getting Started
  • Device
    • Product
    • Configuration
    • Claiming
    • Historical Data
    • Database
      • Configuration Fields
      • Fields
        • Manual input
        • Field Roles
        • Formulas
        • Mapping Fields
      • Data retention & Datapoints
      • Examples
        • Mapping 4-20mA Signals
        • Converting Units
  • Dashboards
    • Global Dashboards
      • Setting Homepage
    • Device Dashboards
    • Multi-Device Dashboards
    • Widgets
      • Value Widget
      • Chart Widget
      • Image Map
      • Map Widget
      • Text Widget
      • SOS Widget
      • Boolean Widget
      • iFrame Widget
      • Downlink Widget
      • Set Value Widget
      • Measurement List Widget
      • Heatmap Widget
      • Table Widget
      • Image Widget
  • Portal
    • Multi-Tenancy (Workspaces)
    • Reports
      • Energy Report
    • Administrators
    • Members
      • API Users
    • Security & Privacy
    • Billing
      • Support Packages
      • VAT Exemption / Tax ID
      • SMS Credits
      • Access Invoices
      • Unused time and Remaining time in Invoices (Prorations)
      • Codes
    • White Label
    • Rules
      • Legacy Rule Engine
        • Sending notifications via Telegram
      • New Rule Engine
        • Rule Engine Table Overview
        • Copy/Paste and Template Functionality
        • Advanced Rule Engine E-Mail and Webhook Templates
        • Time Restrictions
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
    • Configuring LNS
      • The Things Stack (TTN / TTI) Automated Setup
      • The Things Stack (TTN / TTI) Manual Setup
      • Loriot
      • Kerlink Wanesy
      • Helium
      • ChirpStack
      • Tektelic
      • Actility ThingPark
      • Senet
      • Milesight Gateway
      • KPN
    • Downlinks (LoRaWAN)
      • Set Time Frame
    • Securing Webhooks
    • Payload Decoders
      • Location and GPS
      • Access Gateway Metadata
      • Access Measurements
      • Global Variables
    • Using Cayenne LPP
    • Converting Payload
  • Generic API Devices
    • HTTP Downlinks
  • Integrations
    • MQTT
    • Particle
      • Get Started
      • Adding Integrations
      • Decoding Payloads
      • Calling Functions
      • Templates
        • Particle Tracker One
    • Incoming Webhooks
    • Outgoing Webhooks
      • Securing Outgoing Webhooks in Datacake
    • Golioth
    • Blues Wireless Notecard
    • Sigfox
    • Swarm Asset Tracker
    • Grandcentrix Modbus Cloud Connect
    • YuDash LYNX IoT Gateway
    • Dragino NB-IoT
      • Changing NB-IoT Bands
    • Hardwario CHESTER
    • 1NCE OS
  • API
    • Exporting Data
    • Record Measurements via API
    • Node RED to Datacake
    • Generate Access Token
    • Internal MQTT
      • Get Started
      • MQTT Documentation
      • MQTT over WebSocket
      • Example Code
    • GraphQL API
      • Using GraphQL
      • Device Creation
      • Tutorials
        • Read Group via Tags
  • Guides
    • Python
    • Send Slack Notifications
    • Forward Data to Cake Red
    • Multiple Data Feeds
    • Automated Dynamic Downlinks
    • Ingesting JSON Data into Datacake API Devices
    • Working with Default HTTP Decoder on API Devices and Code Examples
    • Accessing Measurements in Decoders
    • Connecting Datacake to Notion Using Zapier
    • How to set up and use location on non-GPS devices
    • How to integrate with AWS IoT Core
    • How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
    • How to Map Sensor Values to Ranges or Booleans, Strings using Mapping Fields
    • Understanding Internal vs. External MQTT Brokers on Datacake
    • Sending UDP Messages between 1NCE OS and Datacake
    • Concepts of LoRaWAN Payload Decoders on Datacake
    • How to check if a value stays above or below limits for given time
Powered by GitBook
On this page
  • Connecting to the Broker
  • Authentication
  • Manage Read/Write Access
  • MQTT Client-ID
  • Topic structure
  • Subscribe
  • Publish
  • Topic Elements
  • The Product-Slug (/<product_slug>)
  • Device-ID (/<device_id>)
  • Field-Name (/<field_name>)
  • Examples
  • Subscription
  • Publish
  • M2M
  • Example
  • Product-wide M2M
  • Connecting external Brokers

Was this helpful?

  1. API
  2. Internal MQTT

MQTT Documentation

Datacake provides an TLS-enabled MQTT broker that can be used to both subscribe to Device measurements as well as record them.

Last updated 5 years ago

Was this helpful?

The Datacake platform offers an MQTT broker with TLS encryption, which allows both subscription and recording of data.

With the help of this broker you can:

  • Forward incoming device data to external services via MQTT

  • Store data via MQTT into the Datacake Cloud

In conjunction with integrations such as Particle.io or TheThingsNetwork integration:

  • Set up a Device-to-MQTT-Bridge without any programming

Each Datacake device automatically publishes changes in the database fields via MQTT. If a new measured value is written into a database field, this is also published via MQTT.

Connecting to the Broker

The broker is running on mqtt.datacake.co on ports 1883 and 8883. Port 1883 is unsecured and should not be used in production environments. Port 8883 uses a CA signed server certificate.

Authentication

You will need an access token to log into the Datacake MQTT Broker. You can use your own personal token or create a token explicitly for individual devices or groups of devices.

We recommend that you use your personal Access Token only for development purposes. If you are using devices in the field through MQTT, it is recommended that you create your own token through Datacake Teams and API users.

All information about tokens can be found under the following link:

Now use this token to log in to the Datacake MQTT Broker. To do this, enter your token as both username and password, as shown as an example in the following screenshot.

Manage Read/Write Access

If you create your own API Access Token, make sure that it has the required rights and roles.

Read more about how to create API Tokens and set permission here:

MQTT Client-ID

The Datacake Broker manages the client IDs internally. You do not need to worry about a client ID. If your client optionally supports the specification of a client ID, please leave this specification blank. Your client then creates a randomly generated ID.

If you still want to use (oder need to use) a unique client ID, it can happen that e.g. with multiple connections, the older connections are cut off. Therefore, make sure that your client ID is unique and is not used multiple times.

Topic structure

Subscribe

Data is published according to the following structure:

dtck/<product_slug>/<device_id>/<field_name>

Subscribe to topics using this structure to receive messages via MQTT when readings (via API or MQTT) arrive in the Datacake Cloud. Messages are published whenever there is a change to a corresponding database field.

Publish

To upload data into the Datacake Cloud and into a specific device, you publish the data to the respective topic structure.

Due to the nature of MQTT, the topic prefix differs as follows:

dtck-pub/<product_slug>/<device_id>/<field_name>

Pay attention to the prefix! Always use this prefix to import measured values:dtck-pub/

Topic Elements

The Product-Slug (/<product_slug>)

For each device you create on the Datacake platform, a corresponding product is created. In addition, multiple devices can inherit from only one product type.

For this reason, the name or path of the product must be specified in the Topic Structure. The reason for this is as follows:

If you manage a fleet of devices, which all originate from the same product type, then you can use this product path to receive the measurement changes and messages of all devices assigned to this product.

This would look like the following: dtck/<product_slug>/*/+

Record Product Measurement Values

Publishing or importing product-wide measured values via dtck-pub/<product_slug>/*/+ is currently not supported. If you have such a requirement, please contact us.

Where do I find the product-slug specification?

Currently, you can find the specification of the Product-Slug in the metadata section of the device view.

Device-ID (/<device_id>)

By specifying the Device ID, you identify a specific Device via the topic. You can also find this ID in the metadata of the device view and also in the URL of the currently open device.

The Device ID is generated internally and is usually an absolutely unique UUID (exceptions are white label products of our customers).

Field-Name (/<field_name>)

The last element in the topic structure is the field name of the measured value, as it appears in the database or as it was created by you via e.g. an API device.

The upper/lower case of the field name is not important here, but it is recommended that you always use it in CAPITAL LETTERS, as specified in the portal.

The field name should not be mistaken for the displayed name of a field. The field name / field identifier is assigned once when the field is created and cannot be changed afterwards. If you still want to or have to change this identifier, you have to delete and recreate the field.

Examples

Subscription

To subscribe to all measurements of a Device with the Product slug my-product and the id 6b98a3bb-9ae1-418f-9375-f23091a849cd, subscribe to dtck/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/+.

To subscribe to all temperature measurements of all Devices with the Product slug my-product, subscribe to dtck/my-product/+/TEMPERATURE.

Publish

To publish a single measurement to a specific Database Field of a Device with the Product-Slug my-product, the Device-ID 6b98a3bb-9ae1-418f-9375-f23091a849cd, and the Field-Identifier TEMPERATURE, publish a message to:

dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE

The Payload is holding the Value which you want to be recorded into that specific Database-Field.

publish("dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE", 22.003)

M2M

You can use the Datacake MQTT Broker to exchange readings or messages between devices. The exchanged information is always related to the fields created for the device.

You can only exchange information that is stored in a field.

To exchange messages between two different devices, simply subscribe to a specific measured value field of the respective other device.

Example

The following example uses a pseudo code to show how you can use the Datacake MQTT structure to exchange messages between two devices.

In this example, this is the message transmission of a temperature from device 1, which sends the measurement data to the Datacake platform via MQTT.

Device 2 subscribed to the topic of device 1 and thus receives the measured value from device 1 as well.

Pseudo-Code for Device 1

# Device 1 (device id 000001):
publish("dtck-pub/my-product/000001/TEMPERATURE", 23.02)

Pseudo-Code for Device 2

# Device 2 (device id 000002):
subscribe("dtck/my-product/000001/+", handler)

def handler(topic, payload):
    print(f"Received Payload from Device 1: {payload}")

If the respective device now transmits one or more readings (whether via MQTT or API) to the Datacake platform, this change will be forwarded via MQTT to all subscribers who also subscribe to the device or topic.

Product-wide M2M

If your devices come from the same product type, you can also subscribe to the respective product on the devices to receive all messages from all devices in the field.

The following Pseudo-Code should clarify the concept:

subscribe("dtck/my-product/*/+", handler)

def handler(topic, payload):
    print(f"Received payload: {payload}, from Topic: {topic}")

Just make sure that your device has sufficient processing power if the number of active devices is large.

Since creating your own Product-IDs on Datacake is an advanced feature and if you have a use case for product-wide M2M, please contact our sales to arrange a discussion how we can set this up for you!

Connecting external Brokers

If you want to use a client functionality from the Datacake Cloud, e.g. to connect (and exchange data with) an external broker, then usually an adapter is required, which brings the topic structure of the external broker to the structure of the Datacake Broker.

There are two different ways to do this:

  • Use Cake Red to use Node-RED and graphical programming to create an adapter to connect both brokers (foreign broker and datacake broker).

  • Develop a server-based service that connects both brokers in the background and that maps the topic structure programatically.

We can take over the development of such a Broker 2 Broker Adapter (via Cake Red or an independent service) for you or would be happy to support you in its implementation. Please contact us!

Are you interested in having your own product slugs for your devices? As this is an advanced feature, you will need to contact our sales team who will provide you with all the information you need to get started. Contact us:

API Users
sales@datacake.de
sales@datacake.de
Generate Access Token
Product-Slug Name in Metadata-Section of a Device