Versions Compared

Key

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

...

This tutorial shows how to configure the MQTT modules to publish and process filesfiles using both the manual and auto publish methods.

Table of Contents
minLevel3

...

    • Name
      • By default a unique name will be set for this File Record. You can edit this if you choose but it must be unique.
    • Tag Provider
      • This is the tag provider where the publish control and information tags will be created. In our example, set to 'default'.
    • Tag Folder Path 
      • This is the tag folder in the specified tag provider where the publish control and information tags will be created.
      • In our exampleexamples, set to 'files_manual' if configuring for manual publish or 'files_auto' if configuring for auto publish
    • Enable Auto-Publish
      • This will enable auto_publish. Leave unchecked if publishing manually
      • In our examples, leave unchecked if configuring for manual publish and check if configuring for auto publish.  
    • Group ID
      • Use the Group ID from your Transmitters Sparkplug ID. For this example, My MQTT Group
    • Edge Node ID:
      • Use the Edge Node ID from your Transmitters Sparkplug ID. For this example, Edge Node faec7e 


...

After the configuration is saved, it should look similar to below:

...

Manual Publish

...

of Files

With a File record created following the steps in Configure MQTT Transmission to publish files with the 'Enable Auto-Publish' unchecked and the Tag Folder Path set to "files_manual", everything should At this point, everything should be configured to send files from MQTT Transmission to MQTT Engine.

...

Note

The md5 sum file is only required when using the auto publish method. This is needed to ensure that the file to be transferred is complete and ready to be published.


Note

Certain If you are testing with a different file, certain characters have special meanings when used in filenames such as "*" for wildcards, and "\" in filename paths. If a file you are trying to publish contains any of the characters listed below, it will prevent files from being written to the file system.

" * : < > ? / \ |

Leading and trailing spaces in filenames and filenames ending in '.' are also not supported.

...

Note
The files will be left on the originating filesystem after a successful publish and will need to be removed manually

Auto Publish of Files

Create With a File record created following the steps in Configure MQTT Transmission to publish files checking the with 'Enable Auto-Publish' checked and configuring the Tag Folder Path set to "files_auto".
At this point, everything should be configured to send files from MQTT Transmission to MQTT Engine.

Open Ignition Designer on the system running MQTT Transmission. You should see the control and information tags created in the specified tag provider and folder as shown below:

...

The control and information tags created in the folder are:

Name

Type

Description

Last Published FileStringName of last published file
Last Published Sequence NumberIntegerSequence number of last published file since last reset of metrics
Percent CompletedBytePublish completion percent for file being published
Publish File CountLongNumber of files published since last reset of metrics
Publish File in TransitStringName of current file being published
Publish Files FolderStringFull path to the target folder containing the files to publish over MQTT
Publish Operation StatusStringStatus description of current publish operation
Publish Operation Status CodeIntegerStatus code for current publish operation
ResetBooleanTrigger to reset publish metrics


At this point, we just need to tell MQTT Transmission which folder contains the file(s) to

...

publish. Download and unzip this sample file to some location and note that location.

This sample_file.zip contains two text files which are:

  • sample_file.txt

    • This is a text file with an arbitrary string. But, it could be a file of any type. This is purely for demonstration purposes.
  • sample_file.txt.md5

    • This is a text file that contains only the md5 sum of the sample_file.txt
Note

Certain If you a testing with a different file, certain characters have special meanings when used in filenames such as "*" for wildcards, and "\" in filename paths. If a file you are trying to publish contains any of the characters listed below, it will prevent files from being written to the file system.

" * : < > ? / \ |

Leading and trailing spaces in filenames and filenames ending in '.' are also not supported.

...

Note

When transferring files using auto_publish, MQTT Transmission requires two files to be present before it will transfer the target file. The first is the file itself. The second is a file that has the same name as the target file followed by a '.md5' extension.   The file containing the md5 sum file is needed to ensure that the file to be transferred is complete and ready to be publishedof the target file will not be transferred.

The contents of that file must contain the Message Digest Algorithm 5 (or MD5 sum) of the file. The MD5 sum can be calculated using command line utilities on most operating systems or through scripting in Ignition. Here are some examples:

Linux

Code Block
languagebash
ubuntu@linux-host:~$ md5sum myfile.bin
07180622a24ebf905cf5f770cd54197a  myfile.bin

# In the above example, the md5 sum is: 07180622a24ebf905cf5f770cd54197a

OSX

Code Block
languagebash
user@osxhost:~$ md5 sample_file.txt
MD5 (sample_file.txt) = 85324ffbcc7d97c478adf53796aff787

# In the above example, the md5 sum is: 85324ffbcc7d97c478adf53796aff787

Windows

Code Block
languagepowershell
Get-FileHash -Algorithm MD5 .\some_file.iso

Algorithm       Hash                                                                   Path                                                                              
---------       ----                                                                   ----                                                                              
MD5             80FD169D3FDADBC97E66C168F796B1BF                                       C:\temp\some_file.iso

# In the above example, the md5 sum is: 80FD169D3FDADBC97E66C168F796B1BF

Ignition Script

Code Block
languagepy
import hashlib

# File to create md5 sum
file_name = "D:\MyFiles\test_file.txt"

# Open,close, read file and calculate MD5 on its contents 
with open(file_name, 'rb') as file_to_check:
    # read contents of the file
    data = file_to_check.read()    
    # pipe contents of the file through
    md5_returned = hashlib.md5(data).hexdigest()
    
# Save md5 sum file
f = open(file_name + ".md5", "w")
f.write(md5_returned)
f.close()


...