cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

ThingWorx Kepware Server IoTGateway Rest-Client to ThingWorx Kepware Server IoTGateway Rest-Server

AS_10596593
4-Participant

ThingWorx Kepware Server IoTGateway Rest-Client to ThingWorx Kepware Server IoTGateway Rest-Server

Good day!

 

I have a use case where I must take some OPC-UA tags and send them to a REST server which is then connected to another OPC-UA server using ThingWorx Kepware Server on both sides. Here is what my configuration looks like:

- ThingWorx Kepware Server on Remote PC configured as a REST server. This REST server is bound to one FLOAT type tag on a test OPC-UA server. I can read it and write to it just fine using powershell and my web-browser.

- ThingWorx Kepware Server on Local PC configured as a REST client. The REST client points to the REST server configured earlier and reads one FLOAT type tag from the source OPC-UA server (production data). The idea is to publish this OPC tag to the REST server earlier (which should then automatically update a tag on the test OPC-UA server it is bound to).

 

I tried to do this using the Standard Template in the REST client's message body but I keep getting ERROR 500. I can use the Advanced Template like this and it works but the value is obviously static,

 

[{id: Tag on My REST Server,v: 22}]

 

I want the value to be written dynamically (fed from the source or prod OPC-UA server). When I do something like this, I get ERROR 400.

 

[{id: Tag on My REST Server,v: |TAGVALUE|}]

 

Is what I am trying to do even possible? I want to make two OPC-UA servers talk to each other but with a REST-API acting like a middle-man. If this is not possible, I would also be completely open to exploring other protocols once the data makes it to the REST Server. I would just like to dynamically write to a ThingWorx Kepware Server based REST server from a ThingWorx Kepware Server based REST client if that makes sense. Thanks for your guidance and support in advance.

 

A visualization of what I am trying to achieve.

 

Setup OPC.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Alright, here is how you do it:

- Make sure the server tag names (IoT items) on your REST server and REST client are exactly the same. I only had 10 tags to write so I ended up using the tags associated with Data Type Examples as a buffer and then using Advanced Tags to link them to my two OPC servers. I would be open to exploring other options here for sure so feel free to suggest a better method. Perhaps, a new channel using the Simulator driver or any other means to have the same user-defined OPC tags on either side?

- Set Enable Write Endpoint to Yes on your REST server.

- Next, make sure your REST client uses the following URL: https://<ip address>:<port>/iotgateway/write

- Set Max Events per Publish to 1.

- Use the advanced template and ensure that the message body looks like this. You can leave the header empty.

 

[
{
|#each VALUES| 
    "id": "|TAGNAME|",
    "v": |VALUE|
|/each|
}
]

 

AS_10596593_1-1701198730612.png

AS_10596593_2-1701198956347.png

 

How did I figure it out:

So I almost gave up because I had written a python script to achieve the same thing and it seemed to be working like a charm. However, the problem with these custom scripts in industrial settings is the question regarding who maintains them, makes sure they keep running etc. Anyway, I had to run a wireshark trace to figure out exactly what my client was writing to the REST server and work my way backwards. PTC should definitely look into improving their documentation in this regard.

 

Best Regards,

Arbab Kolachi (my pen-name)

View solution in original post

2 REPLIES 2

So I managed to figure this out. I will make a more detailed post soon outlying exactly how this use-case can be realized.

Alright, here is how you do it:

- Make sure the server tag names (IoT items) on your REST server and REST client are exactly the same. I only had 10 tags to write so I ended up using the tags associated with Data Type Examples as a buffer and then using Advanced Tags to link them to my two OPC servers. I would be open to exploring other options here for sure so feel free to suggest a better method. Perhaps, a new channel using the Simulator driver or any other means to have the same user-defined OPC tags on either side?

- Set Enable Write Endpoint to Yes on your REST server.

- Next, make sure your REST client uses the following URL: https://<ip address>:<port>/iotgateway/write

- Set Max Events per Publish to 1.

- Use the advanced template and ensure that the message body looks like this. You can leave the header empty.

 

[
{
|#each VALUES| 
    "id": "|TAGNAME|",
    "v": |VALUE|
|/each|
}
]

 

AS_10596593_1-1701198730612.png

AS_10596593_2-1701198956347.png

 

How did I figure it out:

So I almost gave up because I had written a python script to achieve the same thing and it seemed to be working like a charm. However, the problem with these custom scripts in industrial settings is the question regarding who maintains them, makes sure they keep running etc. Anyway, I had to run a wireshark trace to figure out exactly what my client was writing to the REST server and work my way backwards. PTC should definitely look into improving their documentation in this regard.

 

Best Regards,

Arbab Kolachi (my pen-name)

Top Tags