MQTT/Openhab config + get values of DUT InOut to openhab

PLATFORM: LINUX

NODE.JS: V12.22.7
NPM: 6.14.15
1th device: Rpi3: IP 192.168.0.100

  • default rasbian image and installed IoBroaker → adapter connection2BeckhoffPLC

2th device: Rpi4: IP192.168.0.101 with setup with openhabian image

  • openHAB 3.1.0

expl: DUT:= (data unit type)

#blockly
→ set State of Beckhoff adapter in Iobroaker and PLC Run
→ for trial once received Alivebit In from PLC send delayed back to Alivebit Out

#Settings MQTT Client

  • How does I need to configure the MQTT on IoBroaker be able to read or write in Openhab?
    I know it is wrong but don`t know what is right… :sleepy:

#Settings OpenHab System

#Settings OpenHab Thing

#IoBroaker_DUT

I have that : beckhoff.0.plc.IoBroker.IoB# [DUT] variable block that is puplished and as seen in log also transmittet to MQTT broker. in that [DUT] I have bool, word, string and so on that I would like to visualize in Openhab. in pic IoBroaker_DUT you can see a smal view of it to give an idea.

I try to setup the connection between IP *.100 and *.101 over MQTT as shown in print screen the connection is eatablished.

  • How does I need to proceed to be able to visualize for examble the value of an boolean from that DUT?

I am beginning in openhab, so thank for a few more detailes info and keyword as usual. :hugs:

thanks

Either system can be setup in multipal ways.

From plc you are sending Dout

Is it one output per topic or multiple?

I have not enought expirience with openhab at least at that stage to know what is the smartest way to setup or structure the datas to exchange with openhab. On PLC I am flexible, but probably I am going to structure most convinient way to prepare datas in PLC for openhab. Of course some expirienced advice are welcome.

IoBroaker_Dut are at the moment prepared Data for example: (I am technicial and for troubleshoot the Hardware originally Made it ready to be visualised)
beckhoff.0.plc.IoBroker.IoB.IOModul.KL_A1_02#… mirrors an 8 x Digital Input Module on PLC A1 Slot 02 and contains 8x bool with names
#.xBit0
#.xBit1
#.xBit2
#.xBit3
#.xBit4
#.xBit5
#.xBit6
#.xBit7

At the moment I would simply like to understand how would be the setup ( settings on IoBroaker.MQTT and openHAB) to example transfer #TestVal (see bellow pic) containing different types and be able to change value in PLC → 2be updated in Openhab as well the other way.

I don’t have any experience getting beekhoff into MQTT only OPC

I am sure we can figure it out. I use http://mqtt-explorer.com/ which is another client which will show you everything that is sent to the MQTT broker.

Find out what the topic is that the PLC is sending to and what data I suspect that it is not a single bit per topic.

In openHAB create a generic MQTT Thing and then create a channel for each topic. Keep them as TET value (string) so the data will show up in openHAB while testing. You can change them to switch(binary) later.

Your are kind. that was the tool I was missing :slight_smile: Great…

The Datas from PLC I got them already in Iobroeker that is running on IP…100 with the MQQT subscriver/ client. I can also modify data in Iobroaker and send them back into PLC. on Change both ways are synchronised. No worry this works… :slight_smile:

Manually I modified the TestVal/xBool ; byByte ; strString ; wWord in PLC (leftside) and they where Updated automatically over Iobroaker to mosquitto. (see right MQTT Explorer.

If I modified over MQTT Explorer the value and published the it didn`t update. But lets see that later on.

Here I got stuck. Am I right by entering → beckhoff/0/plc/IoBroker/IoB/TestVal/strString in the channel unter configuration MQTT Topic?

I think not

Ok you are nearly there

I assume you have installed the MQTT Binding?

Goto setting click Bindings


Should Look like

If not Click on the blue circle image and add it

Then Go Here to add a new MQTT Broker

Its a Connection to your MQTT Broker you only need one connection for each Broker(server) you use.

Then if you goto things you should see it online

Next would be to create a thing for your device whatever you call it. You can group your things however you like. You can group by location of function whatever you like. You can work that out later.

Now looking at only getting the states into openHAB you need to understand the data and items

I choose to look at an openHAB item switch to intergrate with your BOOL true.

Click the Blue + to add new thing / Generic MQTT Thing

Change Label to “beckhoff PLC”

Click on Bridge and select which broker to use.

Then you should be able to see it in the things


Take no note of the green online it is not indicating anything unless setup.

Click on thing / Select the channels tab / Add a channel

Change the Channel Identifier to “TestVal”
Label “Testing Bool”
Select on/off switch

State topic should be beckhoff/0/plc/IoBroker/IoB/TestVal/xBool
Custom On/Open Value is true
off is false

Create channel and it should show up


Now that you have a channel setup in a thing you can start using it by linking it to an item. - Concept

Click on the tesing bool channel / Add link to item / Create new item / Link (Blue Bottom)

Initially you will have a NULL value
You can toggle in MQTT explorer
image

or with your PLC

Now before I continue the two generals problem needs to be addressed.

In your OP screen shot is a setting use different topics for set and get try using that to solve the issue.


Your PLC is Green the Yellow is MQTT Explorer and orange is openHAB

The PLC uses the terminology SET and GET
Explorer reads and displays all topics it see and you publish data to a topic to SET/Command outcome
openHAB uses the terminology STATE and COMMAND

Not there, no. Don’t attach your channel directly to the broker for this job. Get rid of that. Follow @denominator instruction to make one broker Bridge Thing, then a topic Thing representing your PLC, then the channels.

1 Like

hmmm. I followed your instruction and it partially worked .
I can toggle a bool in PLC its sent to Iobroaker, and leaves according Log to Mosquitto and also updates in openhab.
I added also a byte in the same way then your instruction and it worked as well.
I checked also over MQTT Explorer and in that case it only updates in Openhab, but not in Iobroker.
I assume that if I get an input it should log into it but honestly I don`t know.

then I added the setings according that print screen with same behave. One way it works back to IoBroaker (PLC) not)

does it has to do with server or client setiings?

Ok I miss understood your pics don’t include the PLC settings and I didn’t realise that you were using ioBroker. I don’t know what it is.

What are your PLC settings
You need to figure out what to do to get any control over MQTT to your PLC
https://infosys.beckhoff.com/english.php?content=../content/1033/tf6701_tc3_iot_communication_mqtt/3518541195.html&id=

With you PLC what topic do you subscribe to that will allow you to control the bool?

no worry, once back from work this evening I check it out.
Reason why up to know I used IoBroaker is because there is an Adapter that communicats straight on 2 IoBroker over ADS. It is known that this adapter sometimes misses Datas, or the ADS protocol gots failures that blows up the communication in between.
No worry for that → I am ready to work into MQTT straight communication and kick out the IoBroker intermediate setup, if I can get read of that communication instability.
For info here link: Beckhoff Adapter

So current setup is

Beckhoff PLC ==ADS==> Unreliable Adapter ==> iotBroker ==> Mosquitto Broker ==> openHAB

In the adapter readme on github it states

  • When a Value is changed in ioBroker (Important: ACK need to be FALSE!!) then the Value will be automatic transferred to PLC. After that the Adapter set ACK to TRUE.

Where is this ACK bit?
Is it set to FALSE when you try and change it?

Beckhoff PLC ==ADS==> Unreliable Adapter ==> iotBroker ==> Mosquitto Broker ==> openHAB

that is correct. I dont want to blaim the creator of the adapter, because he did a great job. Adapter according to my knowledge isnt the problem and well maintained. it is much more deeper in the ADS world. But this is out of my knowledge.

Where is this ACK bit?
Is it set to FALSE when you try and change it?

I checked in the scripts. but I havent find it either on PLC nor IoBroker level. as well in the adapter couldnt see where it is.

now for the MQTT connection. What do you recommend that I get into it:

MQTT Communication 1

MQTT Communication 2 with Json

I testes both and they work at least up to MQTT Explorer. Into Openhab not tested yet.

I would do com1 and have separate topics for each message as it will integrate into openHAB easier.

thanks. I am struggeling with PLC configuration. At the moment I only get the value converted in String, but that at least works into openhab . I have to get into it on the week end. Let you know as soon as I control PLC and not PLC controls me :wink:

Somehow I haven’t found yet the right Library in beckhoff to send a topicvalues or payloads other then as string. except the jason there I can configure a topic, group, values, min, max, values,units and so on…
I know it is possible but didn`t yet focus on the right Funktion library. perhaps you or somebody gots an note where to focus at. Up to now I have testet sample 1 and 2 upt to MQTT explorer, and as string all works but convertet to string. I just miss a detail where I can choose or handle state for bool., or value of different types as payload

Before I dont get that done I dont want to get further to integrate into openhab. This made take more time then expected.

TF6701 | TwinCAT 3 IoT Communication MQTT

Sample Link Description
1 IotMqttSampleUsingQueue MQTT communication based on a messages queue
2 IotMqttSampleUsingCallback MQTT communication based on a callback method
3 IotMqttSampleTlsPsk MQTT communication via a secure TLS connection and PSK (PreSharedKey)
4 IotMqttSampleTlsCa MQTT communication via a secure TLS connection and CA (certificate authority) certificate
5 IotMqttSampleAwsIoT MQTT communication with AWS IoT
6 IotMqttSampleAzureIotHub MQTT communication with the Microsoft Azure IoT Hub
7 IotMqttSampleIbmWatsonIoT MQTT communication with IBM Watson IoT