- Table of Contents
- Create an Api Key for netFIELD Data Service
- Retrieve MQTT credentials for netFIELD Data Service from netFIELD.io
- Retrieve credentials for netFIELD Data Service from netFIELD-API
- Connect to netFIELD Data Service with MQTT Explorer
- Configure a Device
- Topics
- Examples
- Troubleshooting
MQTT Explorer is a freely available MQTT client to connect to and work with MQTT brokers. The following guide helps to setup a connection to netFIELD Data Service with this tool.
To configure a device to send data via netFIELD Platform Connector reference to manual netFIELD App Platform Connector
.
To subscribe to messages of a specific device, a combination of baseTopic
and a device topic must be used. Reference to image below. The baseTopic
can be fetched from netFIELD-API (View examples or swagger of API).
The following diagram represents the workflow and structure of topics inside the netFIELD-Data-Service system.
To subscribe to a topic and start receiving its messages, you can do that from the netFIELD platform or locally on the device using the netFIELD App Platform Connector.
Provided examples perform the following steps:
-
Perform a GET request to
/keys/dataservice/info
of netFIELD API. Payload is an empty JSON object. A header withauthorization: APIKEY
and an ApiKey with permissiondevices: viewDeviceMessages
(to be able to subscribe and receive messages) anddevices: writeDeviceMessages
(to be able to publish messages). Those permissions can be set in netfield.io. -
The response is parsed. Received information contains an endpoint as well as username and password to connect to MQTT broker of netFIELD-Data-Service.
-
A connection to MQTT broker is established using endpoint, username and password from
/keys/dataservic/info
response. TLS must be used. Two protocols are supported:- MQTTS: MQTT Secure using port 8883.
- MQTT-WSS: MQTT over Websocket using port 443.
-
Devices base topic is looked up in
/keys/dataservice/devices
response and is combined with#
wildcard to subscribe all messages of this device. -
Subscription to previously calculated topic is performed and messages are received.
-
Publish a message to a provided topic with the special prefix
todevice/
to signal that the message is published from cloud to the device.
The following sequence diagrm illustrates performed interactions:
The example performs a request to netFIELD-API, connects via MQTT websocket or MQTTS to netFIELD-Data-Service then subscribe and publish messages to a device. MQTTnet is used as library to connect via MQTT.
Request to netFIELD-API is made using node-fetch and a connection to netFIELD-Data-Service broker is performed to subscribe and publish messages to a device using MQTT.js.
Using the HTTP library request a request is made to netFIELD-API and a connection to netFIELD-Data-Service broker is performed to subscribe and publish messages to a device using Eclipse Paho client library for MQTT Broker connection. https://www.eclipse.org/paho/index.php?page=clients/python/index.php
Receiving status code 404 from api.
Verify api endpoint url is correct. Access /dataservice/connectioninfo
.
Receiving status code 401 from api.
Used Key has no permission to access this information. Verify used key has viewDeviceMessages
. Verify there is no typo in submitted key.
MQTT client disconnects (imediately).
Multiple possible issues:
- Subscriptions are performed, that are not permitted.
- TLS is not used.
- Publishes to the broker are performed that are not permitted.