Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » MQTT(MQTT Example)
MQTT [message #1721820] Sun, 31 January 2016 14:25 Go to next message
Venkatesh Majeti is currently offline Venkatesh MajetiFriend
Messages: 1
Registered: January 2016
Junior Member
Hi,

I am new to 4DIAC and it looks very interesting using for Distributed Industrial processing.

My Application needs to communicate between 2 different controlles over with MQTT Protocol using external MQTT Broker and I need some example of using MQTT pub / sub fbt's.

I could not locate the help files for function blocks available.

Any help appreciated.

Thank you,
Venkatesh
Re: MQTT [message #1722011 is a reply to message #1721820] Tue, 02 February 2016 09:05 Go to previous messageGo to next message
Monika Wenger is currently offline Monika WengerFriend
Messages: 18
Registered: September 2015
Junior Member
I added a short tutorial for you to the 4diac help files (ide source, will be contained within any new release) and the documentation provided on the 4diac website. please find it under Using Communication Protocols/MQTT with Eclipse Paho
Re: MQTT [message #1725997 is a reply to message #1722011] Tue, 08 March 2016 22:13 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi,

I have a project around MQTT and I'm investigating how I could use 4DIAC.
I've compiled already FORTE to add PAHO MQTT client and using Posix mode.
I can start this FORTE on Linux (Debian).
I had a look at the MQTT item in 4DIAC documentation but I'm still trying to understand how I could use it from the application point of view.
I've understood that I need to define one subscriber per MQTT topic with
the proper ID (which embed th MQTT broker and topic).
However, it is not clear to me if I should define a publisher also ?
I'd like to start with a simple application which reports a temperature sensor value.
Thanks in advance for your help.
Regards.
Re: MQTT [message #1726158 is a reply to message #1725997] Thu, 10 March 2016 08:40 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Hi,

may I ask soem question to better understand your use case?
Where is the temperature is coming from? Do you read it from one FORTE and want to comunicate it between two FORTEs via MQTT? If yes you also need to define a Publisher as well.
Are you providing the temperature value to someone else or is someon providing you the temperature value via MQTT? In this case you would need more information on the data format of your MQTT payload. Unfortunately MQTT does not define a payload format.

Cheers,
Alois
Re: MQTT [message #1726181 is a reply to message #1726158] Thu, 10 March 2016 11:32 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Alois,

Thanks for your reply.
In fact, all my design is around a MQTT broker.
I have several temperature, pressure and flow sensors and switches which report their values or state to a MQTT broker. Temperature sensors can be PTC or DS18B20 for example.
The same broker will be used to turn some relays on/off or PWM values.
This is a convenient way for me to get the "physical world" independent from the Control System.
This part is already in place and I'm now focusing on the Control System.
So, I was planning to use a FORTE instance to perform:
- the MQTT subscriptions for the topics used to report sensors value
- the MQTT publish of the relays states and PWM out values.

Then I would need a controller run time connected to this FORTE instance
and some IHM.
Thanks in advance for your help.
Regards.
/joseph
Re: MQTT [message #1726196 is a reply to message #1726181] Thu, 10 March 2016 13:50 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Ok,

in this case you would have publishers in FORTE for the sensor topics and publshers for the PWM outputs. However you can not use the simple form as descirbed in the docs (i.e., fbdk[].mqtt[xxxx]) . You would need to implement your own communication layer that will take the mqtt packet and transform it to IEC datatypes and vice versa. If you have plain strings you maybe can go with Monika's raw layer.

Cheers,
Alois
Re: MQTT [message #1726200 is a reply to message #1726196] Thu, 10 March 2016 14:16 Go to previous messageGo to next message
Monika Wenger is currently offline Monika WengerFriend
Messages: 18
Registered: September 2015
Junior Member
in case you want to send and receive STRING values you can use the raw layer by just specifying raw[].mqtt[...] please consider that you have to use a publisher with one SD_1 input and a subscriber with one RD_1 output

[Updated on: Thu, 10 March 2016 14:17]

Report message to a moderator

Re: MQTT [message #1726210 is a reply to message #1726200] Thu, 10 March 2016 14:39 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Monika, Alois,

Thanks for your answer.
Unfortunately, it sounds that a STRING2REAL, STING2BOOL FB don't exist, so
I might need to look for a different solution then.
BTW, any tips to debug what is happening on the FORTE side regarding
the MQTT notifications processing ?

Regards.

/joseph
Re: MQTT [message #1726230 is a reply to message #1726210] Thu, 10 March 2016 16:12 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
HI,

STRING_TO_x FBs and functions are existing. The FBs can be found in the IEC 61131-3 folder as they are defined in IEC 61131-3. The functions can directly be used in any ST code you write (e.g., myRealVar = STRING_TO_REAL(myStringvar)Wink.

I hope this helps.

Alois
Re: MQTT [message #1726232 is a reply to message #1726210] Thu, 10 March 2016 16:17 Go to previous messageGo to next message
Martin Melik-Merkumians is currently offline Martin Melik-MerkumiansFriend
Messages: 45
Registered: March 2016
Member
Hi Joseph,
I am the guy who added the MQTT support.

Could you please specify what you exactly want to debug?

Basic collectability information are given via the STATUS output of the Publish and Subscribe FBs.

Martin
Re: MQTT [message #1726265 is a reply to message #1726230] Thu, 10 March 2016 20:12 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Thanks Alois, this does help.
Regards.

/joseph
Re: MQTT [message #1726266 is a reply to message #1726232] Thu, 10 March 2016 20:15 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Martin,

I would simply need to trace the MQTT Broker registration events and the
received notifications to make sure that everything works as expected
on the MQTT side.
Thanks for your help.
Regards,

/joseph
Re: MQTT [message #1726336 is a reply to message #1726266] Fri, 11 March 2016 14:20 Go to previous messageGo to next message
Martin Melik-Merkumians is currently offline Martin Melik-MerkumiansFriend
Messages: 45
Registered: March 2016
Member
In this case, it is probably the easiest way to add print messages in the MQTTHandler.

In order to check if the client successfully connected to the broker, check the return value of the MQTTClient_connection function

Taken from the Paho client example
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
    {
        printf("Failed to connect, return code %d\n", rc);
        exit(-1);       
    }


HTH,
Martin

PS: If the connect was not successful this will also be observable via the STATUS output not showing the string OK

[Updated on: Fri, 11 March 2016 14:22]

Report message to a moderator

Re: MQTT [message #1726349 is a reply to message #1726336] Fri, 11 March 2016 17:20 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Martin,

Thanks for the tips. I have already added some debug messages into
the MQTT layer and I've been able to check that, on the FORTE side:
- the subscriber FB is created OK and does register with the proper topic name
- the MQTT layer does get some events for the subscribed topic.

However, I still don't get any MQTT value on the MGR side.
I've noticed, when I've generated the communication FB, that the
auto generated SUBSCRIBER_1 and PUBLISHER_1 are configured with the
multicast ID 225.0.0.1:61550.
My tests environment is the following:
- 4DIAC GUI and FBRT are running on a Windows 7 PC
- the FORTE instance is running on Debian but within a VirtualBox VM on the
same Windows 7 PC.

On the PC side, running "netsh interface ip show joins" does not show such
a multicast address nor UDP port that I would have expected to see.
Am I correct ?

So, I'm not sure that the IP setup is correct on the PC side.
I will try to investigate this issue.
Thanks for your help.
Regards.

/joseph
Re: MQTT [message #1726359 is a reply to message #1726349] Fri, 11 March 2016 19:25 Go to previous messageGo to next message
Martin Melik-Merkumians is currently offline Martin Melik-MerkumiansFriend
Messages: 45
Registered: March 2016
Member
Please provide more details about your system configuration and used tools.

In which tool the Subscriber and Publisher get autogenerated multicast IPs?

What's your "MGR" side? From your post, I would assume you are trying to connect FBDK/FBRT via MQTT, which is not possible, as FBDK does not support the MQTT protocol.
Re: MQTT [message #1726370 is a reply to message #1726359] Fri, 11 March 2016 21:41 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi :artin,

I'm using the latest 4DIAC release for Windows.
The multicast address got generated when I did the following:
Right Click on the application -> Generate -> Generate Communications FB.

This automatically generated a PUBLISHER_1 and a SUBSCRIBER_1 FB.
My understanding is that this pair does handle the output string from
the MQTT Subscriber FB.

Regards,

/joseph
Re: MQTT [message #1726430 is a reply to message #1726370] Sun, 13 March 2016 13:35 Go to previous messageGo to next message
Martin Melik-Merkumians is currently offline Martin Melik-MerkumiansFriend
Messages: 45
Registered: March 2016
Member
Hi Joseph,

I did not mean your development environment system, but the IEC 61499 application you want to develop, as you wrote:

Quote:
My tests environment is the following:
- 4DIAC GUI and FBRT are running on a Windows 7 PC


So I assume you want to connect a FORTE device to an FBRT device via MQTT, right?
Re: MQTT [message #1726568 is a reply to message #1726430] Mon, 14 March 2016 17:21 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Hi Joseph,

the genrate communication FB feature currently only understands the clasic IEC 61499 UDP Publish/subscribe communication. If you would like to have MQTT communication you need to adjust the values for the ID parameter of the generated publish subscribe FBs according to the values described in the documentation.

Cheers,
Alois
Re: MQTT [message #1726592 is a reply to message #1726568] Mon, 14 March 2016 22:02 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Alois,

What I had in mind was the following:

MQTT Broker ->MQTT Subscriber_1 -> UDP Publisher_1 ==> <Ethernet Network> <== FBRT UDP SubScriber_1 -> [Display value]

I believe that I have some issue with the regular UDP Publish/Subscriber mechanism since the MQTT publisher does attempt to send the received data via the UDP Publisher but I get a "connection reset/closed by peer" error.

I will try to get rid of VirtualBox for my tests environment.
Thanks for your help.
/joseph
Re: MQTT [message #1726654 is a reply to message #1726592] Tue, 15 March 2016 11:15 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Hi would it be ok for you to post your project here? or at least screenshots of your fb networks?

If you have issues on the UDP Pub/Sub it may be a problem with your network setup (i.e., firewalls, UDP multicast routing, loop back device).
/Alois
Re: MQTT [message #1726699 is a reply to message #1726654] Tue, 15 March 2016 20:33 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Alois,

I've uploaded a simplified version of my project files.
This a version with auto-generated Publisher_1/Subscriber_1 which
make use of multicast addresses.
Thanks for your help,
Regards,

/joseph
  • Attachment: SysConf.xml
    (Size: 62.92KB, Downloaded 91 times)
  • Attachment: AltixApp.xml
    (Size: 17.61KB, Downloaded 79 times)
Re: MQTT [message #1726723 is a reply to message #1726699] Tue, 15 March 2016 21:37 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Hi,

would you mind zipping me the whol project directory. Makes it easier for me to import it into my 4DIAC workspace.

Alois
Re: MQTT [message #1726736 is a reply to message #1726723] Tue, 15 March 2016 22:13 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Alois,

I've uploaded the full zip file of this tests project.
Thanks for your help,
Regards,

/joseph
  • Attachment: AltixSys.7z
    (Size: 65.71KB, Downloaded 85 times)
Re: MQTT [message #1726830 is a reply to message #1726736] Wed, 16 March 2016 17:43 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Hi Joseph,

thanks this made it much easier. When you watch the outputs of your subscribe blcok which is subscribing to your mqtt topic what outputs do you get? You are using the fbdk layer as top layer configuration for your mqtt subscriber. With that our subscriber assumes that the payload of your mqtt message is encoding according to the definitions in the IEC 61499 Compliance Profile for Feasibility demonstrations. I don't think this is correct as this normally would only work if your the other end of your mqtt communication would also use this encoding. I guess here you better use for first tests the raw layer as suggested by Monika.

Alois
Re: MQTT [message #1726886 is a reply to message #1726830] Thu, 17 March 2016 09:40 Go to previous messageGo to next message
joseph reveane is currently offline joseph reveaneFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Alois,

Thanks a lot for your help and your time.
I will try to switch to the raw layer then.
Regards.

/Joseph
Re: MQTT [message #1748011 is a reply to message #1721820] Thu, 17 November 2016 16:53 Go to previous messageGo to next message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

I am also having issues with MQTT Subscribe.

My SUBSCRIBE_1 block has:
- ID set to use a raw layer ("raw[].mqtt[%broker_uri%, 4diac-benjamin-sub, 4diac/stop]")]
- QI = TRUE

but the STATUS is always "TERMINATED".
If I try to switch to fbdk, the STATUS is "INVALID_ID"

In both cases, MQTT messages can't be received.
FWIW, I have in the same app a working PUBLISH_1 FB, that uses the very same broker URI.


Re: MQTT [message #1748167 is a reply to message #1748011] Sun, 20 November 2016 00:21 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Our mqtt implementation currently has some limitations. first of all all publishers and subscribers have to connect to the same broker. Secondly they need to use the same client id (the 2nd parameter in the list).

Furthermore I just found and fixed an issue in the code this could also affect you. It is available here [1]. Just pull the latest cset for the 1.8.x branch.

[1] http://git.eclipse.org/c/4diac/org.eclipse.4diac.forte.git/commit/?h=1.8.x&id=17f30cf591a55d16eef6304a837248100beb1e95
Re: MQTT [message #1748635 is a reply to message #1721820] Fri, 25 November 2016 13:50 Go to previous messageGo to next message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

I'll give the changeset a try, thanks Alois!

Re: MQTT [message #1750575 is a reply to message #1748635] Thu, 22 December 2016 21:40 Go to previous messageGo to next message
Ahmet Tuna is currently offline Ahmet TunaFriend
Messages: 1
Registered: December 2016
Junior Member
I have the same problem. Do you have any solution ?
Re: MQTT [message #1750576 is a reply to message #1750575] Thu, 22 December 2016 22:13 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 617
Registered: January 2014
Senior Member
Which FORTE version are you using. We fixed an issue in MQTT code for version 1.8.3 which we released today. Could you please give it a try?
Previous Topic:Howto use Adapters
Next Topic:Why "INF" value in composite fb?
Goto Forum:
  


Current Time: Mon Aug 20 06:57:41 GMT 2018

Powered by FUDForum. Page generated in 0.02911 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top