running MQTT client & broker on PLC next
Hallo,
I need to implement a MQTT client as well as an broker on the PLCnext. So im interested in what would be a good solution.
As i have read, i could use some "TCP & UDP Binding" to communicate between the IEC-Runtime and the OS. This "Bindung" for example is the TCP_SOCKET function in IEC or something else?
In this case I could run the broker and client on the OS itself and use a programming language of my choice.
The downside of this solution would be no bidirectional asynchronous communication and the need of some polling algorithm.
Because there is no pre build WebSocket implementation in PCWorx Eng. I think instead of implementing a C++ Add-In for WebSockets the more straight forward way would be to create a MQTT-Client C++ Add-In.
In this case I was thinking about using the "Eclipse Paho MQTT C++ Client Library". Would you recommand an other Client-Library?
I saw the itroduction videos for the first C++/C# Add-Ins. In C# a function block was created but C++ generates a programm. What are the main differences between C++ and C# Add-Ins? Whats the right choice for the MQTT client with GDS-access in my case?
As a broker solution I am unsure if I should use Mosca as node.js MQTT Broker or Mosquitto. But I guess Mosquitto is more efficient then some node.js implementation.
Is it save to increase processing load on the OS for the real-time-application and IEC-Programming Parts?
Thanks for your help,
Jimmy Pesto
Comments
Hello
I have installed an MQTT broker on node-Red on my AXC F 2152, and it works fine.
node-red-contrib-mqtt-broker
That's enough. then you can use MQTT in and MQTT out from NodeRed.
@mschneider:
I´ve already installed nodejs, running Mosca should not be a problem. So performance regarding automating a really small example application with up to 20 IOs should be ok?
But my main question is, how do i get my process data into MQTT on an easy and efficient way.
Thanks for your reply.
Hello Jimmy.
To make a link with the PlcNext application, the most simple should be to use OPCua.
This is explained in this Blog.
So, access to the PLC variables via OPC UA (OUT ports, OPC option checked), and send to MQTT broker via NODE-RED.
What I explain to you uses Node-Red (not nodejs). sorry, i have no experience with C++ or C# devellopment.
----------------------------
But if you know how to integrate a C++ or C# application in PlcNext Engineer (Eclipse/Visual Studio), you will be able to make the link with your application using simple In and Out ports (eclipse) or In and Out parameters of a FB (Visual studio).
Hi Jimmy,
As it happens we are currently working on an MQTT Client service for PLCnext Control, which we hope to have ready for the Hannover Fair in April. This will have a C++ API, but will also (probably) include a "connector" untility that exchanges data between MQTT Broker(s) and Global Data Space (GDS) Ports. The utility will be configured using a JSON file, so you can list a set of PLC Ports and specify where to Publish the data (for Output ports) or Subscribe to the data (for Input ports). In this respect it will be very similar to the Proficloud Time Series Data (TSD) service currently included with the PLC, but for MQTT (and with bi-directional data exchange).
But if you can't wait for this, then (as Michel mentioned) there are a few ways to get an MQTT Client and/or Broker running on an AXC F 2152, including python and node.js.
I agree that OPC UA would be a good way to exchange process data with real-time programs (including physical I/O), via Input and Output Global Data Space (GDS) ports.
Other data exchange options include:
If you're able to share progress on your project, I'm sure the Community would be interested to know how you get on.
- Martin.
Also, to answer the question about C++ and C# add-ins:
If you're experienced in both languages then the choice comes down to your application requirements.
If you want to develop a library of Function Blocks and/or Functions that can be used by real-time IEC-61131 programs in PLCnext Engineer, then the C# add-in is the correct choice. In this case the Function Blocks must be integrated into an IEC-61131 program using PLCnext Engineer.
If you want to develop your own deterministic real-time program(s) that run directly on the Execution and Synchronisation Manager (ESM), and that can exchange data with other programs via Global Data Space (GDS) ports, then the C++ add-in is the correct choice. Your C++ programs can include open-source libraries like MQTT libraries from Paho or Mosquitto. In this case PLCnext Engineer can be used to configure the ESM, and to schedule your program(s) to run on ESM Task(s), and to set up the GDS - but this setup can also be done without PLCnext Engineer, by editing the relevant XML files directly on the PLC. For people who want nothing to do with Windows, this is a very attracive prospect.
Hope this makes it clearer.
- Martin.
Hello,
thanks for the great feedback.
Im used to nodejs programming so node red is no choice for me. Therefore I would like to use some node broker running directly on the OS.
Or maybe use Mosquitto later for more performance.
Some time ago I was exchanging data via OPC UA to seperated devices. As I remember, latency wasnt that good.
This solution might be easy, but maybe another one would have a greater performance.
I have some basic C/C++ knowlegde and would like to use an add-in to get access to the GDS.
Furthermore I would still use the Engineer for quick ESM-configuration.
As development of the PLCnext enviroment is still in progress I lost track on how to do so.
What is the most stable and documented firmware version I should use?
Is there an updated example on how to access GDS from C++?
Is there an example on how to include open-source libraries like MQTT or WebSocket?
Thanks again,
Jimmy Pesto
Hi Jimmy,
The latest firmware on the AXC F 2152 download page is always a good bet.
You have the choice between the latest Long Term Support (LTS) version, released annually and updated with hot-fixes during the year, or the incremental updates released every 3 months. The next incremental update (version 2019.3) will be available next week.
An example of how to create GDS ports from C++ is shown in this video: https://youtu.be/IUGSZzuzm-c
You can link your C++ program ports to GDS ports from other programs, or to ports from I/O modules, using PLCnext Engineer.
The PLCnext Technology User Manual gives more information on the format of GDS Port Definitions in C++.
There will be an example of how to use open-source libraries on our Github channel next week. In fact, the source code for a new "MQTT Client" PLCnext Store App (based on Paho MQTT C++) will be posted there.
Stay tuned!
- Martin.
I am updating to version 2019.3 but there is no "PLCnext Technology C++ Toolchain". Only for version 2019.0.
Are these compatible?
The section "Building from source" in the readme of the official MqttGdsConnector-repo is confusing me. I have installed the .bat file for the PLCnext SDK, but I can not find the PLCnext Command Line Interface (CLI).
As I am already programming the PLCnext with Windows I would also like to build the MqttGdsConnector from Windows or on the target itself. From which command line interface in Windows can I build the Mqtt-project as it needs to be crosscompiled for linux? Or is it easier to ssh into the PLC and build the project on the target itself?
Thanks for your advice,
Jimmy Pesto
Hello Jimmy,
do you want to compile everything yourself?
There is a compiled version in the plcnext store which can be installed easily from the ProfiCloud to your PLCnext Control.
Building locally with the shell scripts written for Linux on a windows system might be troublesome.
1. you will need git to clone the dependencies
2. You need a bash to execute the scripts
3. You need symlink support.
4. you need the plcncli. (PLCnCLI_Win64_2019.0) phoenixcontact.com -> AXCF2152 -> Downloads -> Software
5. you need the SDK (SDK_WIN64_2019.3) phoenixcontact.com -> AXCF2152 -> Downloads -> Software
regards,
Oliver
This would be a great information in the repository.
How about building on the target?
I have found the MQTT-Client in the store but I have trouble with registration. I will see if this is gonna work with my students account but I can not do a "Company Registration".
Where can I find the correct Device ID for my axcf2152?
Hey Jimmy,
i added a feature request for windows build support...
https://github.com/PLCnext/MqttClient/issues/3
https://github.com/PLCnext/MqttGdsConnector/issues/2
To build on target you will first have to install all build-essentials make, gcc.
Take a look at the makers block from martin boers how to use the IPKG package manger for that.
You do not need company registration to download i think.
The mentioned ID is the UUID you can see it with for example PLCnext Engineer, the WBM, printed at the side of your PLC.
Hey Oliver,
thanks for your advice.
I was able to find the UUID and get the PLC into the new market place after activating the Proficloud connection in the WBM.
Installing the MQTT client from PLCnext Store was a breeze without any company registration. But now MQTT isn´t listed anymore and I dont know how to proceed.
Kind regards,
JimmyPesto
Hi Jimmy,
We're currently upgrading the MQTT app ... we hoped this would not take so long, but it should be back online soon.
If you have installed the MQTT app from the store, then the status of the app in the store does not matter. You simply need to follow the instructions in the Technical Manual, which (in case you didn't get it from the Store) I have attached here.
If you have any problems with these instructions, please raise an issue on the GitHub Issues page for the GDS Connector project.
- Martin.
Okay thanks for the technical manual, I did not download it at the day I installed the client.
Do you know why the client has fixed 500ms cycle time and publishes all data?
Wouldn´t it make sense to only publish the full data when a new client connects and subscribes the process data and afterwards just publish the data that has changed (faster then 500ms)?
Regards,
Jimmy
Hi Jimmy,
Good question.
For version 1.0, given the tight delivery deadline, we could only include core features. For MQTT publish items, we had the choice to update on change, or on a fixed frequency, or on a variable frequency, or (ideally) on some user-configurable combination of these. For version 1.0 we opted to publish more rather than less data, and then (hopefully) the subscriber could discard whatever data it didn't need (e.g. using change detection). In this respect the MQTT client is quite similar to the Proficloud TSD service, which publishes all configured data to the Proficloud at a similar frequency.
Version 1.1 will allow user-configurable update frequencies on each publish item, from 1 second to 1 day (or the default 500 ms).
It would be great if you could add your feature request as an "Issue" on the GDS Connector Github project, with some detail on exactly how you would like this feature to work, how it would be configured, and the real-world applications for this feature. This will then give me a good argument to have this feature proiritised for release 2.0, which is due later this year.
It's also worth mentioning that we are currently working on a PLCnext Engineer Function Block Library for MQTT, based on the same MQTT engine as the store app (i.e. the "MQTT Client" PLCnext service in Github). With these FBs, you will be able to publish whatever items you want from your IEC project, at whatever frequency you want.
- Martin.
Hi Martin,
I've been trying to compile the MqttGdsConnector from source using the master branch of the github repo,
but ran into some problems. My environment is Ubuntu 18.04.2 using the latest plcnext sdk and plcncli:
plcncli get sdks
Available SDKs are:
- /opt/pxc/sdk/AXCF2152/2019.3
I assume I have to execute the build-all.sh script in the tools directory, but when I run it I get the following output:
./build-all.sh
Version:
+ echo prepare Json
prepare Json
+ /home/gideon/Repositories/MqttGdsConnector/tools/../tools/prepare-json.sh
fatal: destination path '/home/gideon/Repositories/MqttGdsConnector/tools/../external/json' already exists and is not an empty directory.
....
Version:
CMAKE Configure
CMake Error: The source directory "/home/gideon/Repositories/MqttGdsConnector/build/external/_" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
Error: /home/gideon/Repositories/MqttGdsConnector/build/external/_ is not a directory
Error: /home/gideon/Repositories/MqttGdsConnector/build/external/_ is not a directory
+ set +x
Do I need to run the script with some options, and if so, what are the options ? I noticed the following options:
-t -a and -n
Best,
Gideon
Hi Gideon,
You are correct, the build script must be given the three parameters you mentioned.
In my case I am running the build script from within Visual Studio Code. Below is the
tasks.json
file in the project's.vscode
directory, where you can see the values I use for these parameters.We do it this way so that our Continuous Integration process can automatically build the application for all versions of all PLCnext platforms on every Commit to our repository, simply by changing the three parameters.
By the way, we are encouraging more activity on our Github channel, so please feel free to ask questions like this by opening a new Issue in this projects repository, where we can track the issue and the solution (i.e. better documentation!) when it is fixed in a future release.
Hello,
I have build the MqttGdsConnector from the GitHub sources within Linux environment, and followed the guideline to Install on target. However I do not see any output of the MqttGdsConnector within /opt/plcnext/logs/Output.log and no mqtt network traffic.
Do you have any hints how find the actually issue?
Best regards,
Oliver Feilner
Hi Oliver,
What directory on the PLC contains your .acf.config file?
Can you confirm that the name of this file ends in ".acf.config" ?
Can you post the contents of your .acf.config file?
Thanks!
Hello Martin,
thanks for the fast answer, here are the requested information, as I head trouble to paste an xml doc here I put it as a picture. I think it looks ok.
By the way I discovered that according to the README.md the mqtt_gds.schema.json has to be placed in /opt/plcnext/apps/60002172000048/ while according to the AwsClient_Technical_Details.md and AwsClient_Technical_Details.pdf it has te be placed in /opt/plcnext/apps/60002172000053/ . What is actually the meaning of this number, where does it come from and where is it referenced?
Best regards,
Oliver
Hi Oliver,
Can you confirm that you are working with firmware version 2019.3 ? (
cat /etc/plcnext/arpversion
)Just to double-check, can you please execute
sudo ldconfig
(to make sure the shared object library is known to the OS).After both these are checked, please restart the plcnext runtime (
sudo /etc/init.d/plcnext restart
).Now, you should definitely see something in the Output.log file related to this component. If not, please post the contents of the file
/opt/plcnext/projects/Default/Default.acf.config
.=========================
The two numbers you mention are the IDs of the two apps in the PLCnext Store - the MQTT Client app, and the AWS app. The corresponding directory is created when one of these apps is installed from the PLCnext Store (but please don't try installing both apps at once).
When you install the MqttGdsConnector library manually, you need to put the JSON schema file in the same location as the PLCnext Store would put it, because that's where the Component looks for this file. Hence the strange number. It actually makes no difference which of the two directories you use, the code looks for the schema in both of them. But I would recommend just sticking with 60002172000048, since this is the "generic" MQTT app, which can also be used to connect to AWS (with the correct certificates).
Hope this helps.
Martin.
Hi,
I also compiled the MqttGdsConnector from source and currently trying to deploy it on the AXC F.
I put all files according to the Readme section. However, after rebooting the PLC does not find libPxceTcs.Mqtt.Client.so:
However it is there:
Here are the ACF config files:
Do you have any idea what is going on here?
Regards,
Markus
Hello Markus,
Please try executing:
sudo ldconfig
from the plc command line, or restart the plc.
- Martin.
Hi Martin,
thanks for your quick help, this solved this issue for me.
Regards,
Markus