Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

MQTTspB exercices and configuration

Tutorials → Tutorial | MQTT | How-to Guide | MQTT Tools Reference

Manage MQTT SpB connections to read and write data.

TutorialsMQTT Spb | Tutorial 

This Tutorial Teaches you to:

  • Start the MQTT internal broker
  • Start the MQTT SpB Simulator
  • Set up publishers using Device channels
  • Set up collectors using  TagProvider Services

Prerequisites



1. Setup MQTT Environment

Step 1: Set Up the MQTT Broker and Simulator

Start the Built-in

MQTT

Broker

  1. Go Navigate to DataExplorer Data Explorer → MQTT Tools
  2. Click Start button for Run Local Built-in Broker (check the message on the right side or the icons to make sure it's not already running)
  3. Status shows "TMQTTBroker is Running"

Start MQTT Simulator

  1. In same panel, find MQTT Publisher Simulator section
  2. Click Start for simulator
  3. Status show "Simulator is Running

2. Configure SpB Publisher with Devices

Create Device Channel

  1. Go to Devices → Channels
  2. Click New Channel
  3. Configure:
    • Protocol: Mqtt SparkplugB Publisher
    • Channel Name: SpbPublisher
    • Group ID: SpbPublisherGroup
  4. Click OK

Create Device Node

  1. to start the broker
  2. Connect to the broker (connection will show as established)

Run the MQTT Publisher Simulator

  1. Start the MQTT Publisher Simulator
  2. Verify data is publishing - you'll see:
    • Cities (e.g., Barcelona)
    • Solar panels with properties:
      • Name
      • Power
      • Temperature
      • Real-time changing values

Step 2: Map and Publish Data Using Devices

Create Device Mapping

  1. Select a panel (e.g., Panel 1) from the simulator
  2. Click Map to the Solution
  3. Choose Publisher and New DeviceNode
  4. Confirm to create tags automatically

Configure Channel Settings

  1. Go to Devices → Channels
  2. Confirm if all the setting are as expected, including the Group ID from the broker.

Configure Node Settings

  1. Go to Devices → Nodes
  2. Confirm if all the setting are as expected, including the Node ID from the broker.

Configure Points

  1. Check Points section for mapped tags (e.g., PAN01)
  2. Verify the address structure:
    • Group ID: cities
    • Node ID: Barcelona
    • Device ID: Panel_1
  3. Go to Devices → Nodes
  4. Click New Item
  5. Configure:
    • Node Name: SpB_Publisher_Node
    • Channel: SpbPublisher
    • Node ID: SpbNode
  6. Click OK
  7. On Primary Station, once its using the local broker, just by pressing Test  it should show the OK message


Info
titleMQTT Spb Tag Structure

If you are creating tags manually, instead of mapping directly from the Data Explorer, It is important to note that when using MQTT SpB, all the tag must be in a structure. It means that you need to create a user type and use the root level of the user type in the communication.

Step 3: Collect Data Using Tag Provider

Create Tag

User Type

Provider

  1. Go Navigate to Unified Namespace → User Types
  2. Click on Insert new
    1. New Name: MotorSpb
    2. Create new UserType
  3. In the MotorSpb UserType add:
NameTypeTemperatureDoublePressureDoubleRPMInteger
  1. Frameworks → Tag Provider Services
  2. Click Create New Tag Provider
  3. Select MQTT SparkPlug B Collector Connector
  4. Change the setting to connect to your broker
  5. Test the broker connection

Link to Asset Tree

  1. In Asset Tree, create a folder (e.g., "Barcelona")
  2. Link the tag provider to this folder
  3. Navigate the tree structure to see values

Access Asset Data

  1. Open Tools → Object Browser
  2. Navigate to your asset (e.g., Barcelona → Panel1 → Current)
  3. Copy the asset path using the top button
  4. Paste this path anywhere in the software to retrieve values

Step 4: Configure Runtime Publishing

Enable Local Tag Publishing

  1. In Runtime → Startup, before running the solution, check "Publish to MQTT Broker" option (Advanced settings)
  2. This automatically publishes public local tags to the broker

Create Local Tags (Optional)

  1. Go to Unified Namespace > Tags
  2. Create a new local tag (e.g., "LocalTagPower")
  3. Set visibility column to Public for read/write access
    • Public: Read and write access
    • Protected: Read-only access
    • Private: Tag not visible

Step 5: Run and Monitor the Solution

Start Runtime

  1. In Runtime → Startup, Click Run Startup
  2. Verify all connections are active

Monitor Data Flow

  1. Use Diagnostic Tools → Property Watch to monitor tag values
  2. Use Object Browser to:
    • Navigate to specific tags (e.g., Barcelona → Panel1 → Current)
    • Copy tag paths
    • Add tags to watch lists for testing

Verify Data Collection

  1. Check that asset values are updating in real-time
  2. Confirm data is flowing from:
    • Simulator → Broker
    • Broker → Device mappings
    • Tag Provider → Asset tree

Create Tag using UserType

  1. Go to Unified Namespace → Tags
  2. Add the tag Motor1 and set type to use MotorSpb UserType
  3. Add the tag MotorLocal and set type to use MotorSpb UserType

Map Tags to Publisher

  1. Go to Devices → Points
  2. Add:
    1. TagName: Motor1
    2. Node: SpB_Publisher_Node
    3. Address: Motor1SpB

3. Test Publisher

Select "Publish to bulit-in broker"

Start Runtime

  1. Go in Runtime > Start Application
  2. Open Property Watch
  3. Navigate to Tag.Motor1
  4. Change Values

Verify Publishing

  1. Return to DataExplorer → MQTT Tools
  2. Click Refresh on connected browser
  3. Navigate to topic:
    LocalBroker/spBv1.0/SpbPublisherGroup/SpbNode/Motor1SpB
    
  4. See published metrics:
    • Pressure
    • RPM
    • Temperature
  5. Change values in the property watch to see them reflecting here

4. Configure SpB Collector with TagProvider

Create TagProvider Services Connection

  1. Go to Unified Namespace TagProvider Services 
  2. Click New Item...
  3. Configure:
    • Name: MqttSpB_Collector
    • Provider: MQTT SparkplugB Collector
    • Access Mode: Read
    • Click Test (the OK message should show up)
  4. Click OK

5. Map Collected Data to Tags 

Create Asset Folder

  1. Go to Unified Namespace → AssetTree
  2. Create folder MqttSpb
  3. Click on Insert Data from TagProvider
  4. Navigate the tree TagProvider Services → MQTTspB and select this folder
  5. Now you can navigate into the tree and the entire structure will be available to use

In this section...

Page Tree
root@parent
spaces93DRAF