---
title: 'MGate 5105 and NPort IA5150A to Ignition (Sparkplug)'
---
MGate 5105 and NPort IA5150A to Ignition (Sparkplug)
===
:::info
**For Internal Use Only--Not for Pubic Distribution.**
:::
> [name=Anthony Ho, MUS Technical Support]
> [time=Wed, Jun 5, 2019 12:01 PM]
###### tags: `Application` `Documentation` `MQTT` `Sparkblug` `Node-RED` `IIoT`
## Table of Contents
[TOC]
## Introduction
This document demonstrates how to connect the MGate 5105 and NPort IA5150A to a Sparkplug B compliant broker. Demonstration includes details on how to publish fieldbus or serial data message to Ignition for monitoring.
For detailed steps on how to connect the MGate 5105 and NPort IA5150A to generic MQTT broker, refer to the Tech Notes from moxa.com.
System Topology
---

Prerequisites
---
### Generic MQTT Broker
- [MQTT Distributer](https://docs.chariot.io/display/CLD/Getting+Started%3A+Single+Ignition+Architecture)
- An MQTT Server that runs as an Ignition module.
- Any generic MQTT Broker will work as well such as Mosquitto or MOSCA.
### Node-RED
- To add Sparkplug B structure to the standard MQTT architecture.
- [Sparkplug B Node](https://www.npmjs.com/package/node-red-contrib-sparkplug)
- A node for an MQTT Edge Node client for MQTT device communication using the Sparkplug specification from Cirrus Link Solutions.
### Ignition
- [MQTT Engine](https://docs.chariot.io/display/CLD/Getting+Started%3A+Single+Ignition+Architecture)
- Engine is an MQTT Client that implements the Sparkplug specification and automatically creates Ignition tag structures for Edge Node and Device metadata and process variables.
Device Configurations
---
### MGate 5105


### NPort IA5150A

Sparkplug B
---
Sparkplug is a specification for MQTT enabled devices and applications to send and received messages in a stateful way. Generic MQTT doesn't ensure all data on a receiving MQTT application is current or valid. With Sparkplug, it can provide a mechanism for ensuring that the remote device is current and valid.
The MQTT function on the MGate 5105 and NPort IA5105 **does not include** the device lifecycle messages such as the *required birth and last will and testament message* that must be sent to ensure the device lifecycle and data and integrity. **However, it is still possible to send data to a Ignition (Sparkplug).**
Node-RED
---
The flow can be downloaded [here](https://flows.nodered.org/flow/864303231756610e5824082f988a8acd).

### Example (NPort IA5150A)
This javascript function returns the birth and data payload for the NPortIAW5150A-6I/O.
```javascript
var gwID = msg.payload.gwID,
devID = "RFID",
data = msg.payload.msgFrame,
msgFrame = " ",
timestamp = parseISO8601(msg.payload.dateTime)
function parseISO8601(n) {
var newDate = new Date(n)
var timestamp = newDate.getTime()
return timestamp
}
getTopic = function(type) {
return devID + "/" + type;
}
getBirthPayload = function() {
return {
"timestamp" : new Date().getTime(),
"metrics" : [
{
"name" : "Payload/gwID",
"value" : " ",
"type" : "string" },
{
"name" : "Payload/msgFrame",
"value" : " ",
"type" : "string" }
]
};
}
getDataPayload = function() {
return {
"timestamp" : timestamp,
"metrics" : [
{
"name" : "Payload/gwID",
"value" : gwID,
"type" : "string" },
{
"name" : "Payload/msgFrame",
"value" : data,
"type" : "string" }
]
};
};
if (msg.topic == "rebirth") {
return {
"topic" : getTopic("DBIRTH"),
"payload" : getBirthPayload()
};
}
if (msg.topic === "NPortIO/JSON/SPort1/Pub/Data") {
msg.topic = getTopic("DDATA");
msg.payload = getDataPayload();
return msg;
}
return null;
```
**Note**: *DBIRTH is required prior publishing data to Ignition. However, it is important to note that the timestamp on DBIRTH message is based on Node-RED. In other words, there isn't a way to confirm the MGate 5105 or the NPort IA5105 are current and valid.*
Igniton
---
From Ignition, the data published by the gateways are found under Tag Browser.

Contraints
---
- NPort IA5105 and MGate 5105 does not provide ready-to-run solution for Sparkplug.
- No viable timestamps to determine device validity and lifecycle.
- Unable to recieve and acknowledge "rebirth" request from Sparkplug.
- Online/Offline status is based on Node-RED
```tiddlywiki=
$ vim /etc/systemd/system/Node-Red.service
```