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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Websocket connection between Thingworx and a websocket-server.

mrenner
2-Explorer

Websocket connection between Thingworx and a websocket-server.

Hello community,

I want to open a websocket connection between Thingworx and a websocket-server for subscribing data.

I have seen that such services for http protocol exist in Thingworx:

var result = Resources["ContentLoaderFunctions"].LoadJSON(params);

So my question is:

Is there any possibility to do almost the same via websocket communication?

Thanks a lot for help,

Max

12 REPLIES 12
ttielebein
14-Alexandrite
(To:mrenner)

Why aren't you just using the EMS or one of the SDKs, which handle the websocket communication for you?

Thanks for comment.

Yes I could handle the websocket communication using one of the SDKs.

But I thought there will be an out of the box solution for websockets in thingworx.

Do you know if there is any way to do this out of the box?

ttielebein
14-Alexandrite
(To:mrenner)

The EMS is out of the box. It only needs to be configured. Here, check out the Developer's Guide and let me know if you have further questions on this.

Thanks again.

So your suggestion is to write a websocket client in LUA Script to receive the data from the websocket server and then pushing the data from EMS to Thingworx?

Is there no way to receive the data from the websocket server in thingworx directly without using EMS or one of the SDKs?

I tried to write a service for a websocket client in Java Script like this:

var socket = new WebSocket(urlToWebsocketServer);

But I get the error:

ReferenceError: "WebSocket" is not defined.

Because WebSocket is not defined in the Java Script Thingworx API?

Aanjan
12-Amethyst
(To:mrenner)

Maximilian, if you deploy the EMS on the end server, it will create a websocket connection to ThingWorx. The LuaScriptResource we provide pretty much makes REST calls via the EMS (websocket) connection.

With that being said, what sort of data are you trying to send/ subscribe to? The example template that's included has couple sample properties and services to test with.

mrenner
2-Explorer
(To:Aanjan)

Thanks for reply Aanjan.

I know how Thingworx Connectivity is working. Sorry if I express myself unclear.

I have possibility to deploy the EMS on the end server I just want to subscribe data of an existing websocket server.

My use case is:

I want to subscribe all data of a rotary table with drill tools etc. via websocket communication. For Example the speed of the rotary table.

The rotary table is more or less a black box for me. I only have the websocket server address and the communication protocoll on which I can communicate.

So I just want to send a JSON-Message to the Websocket Server like:

{"type":"readALL"}~

And receiving all the data the rotary table with all its components is producing.

This data I want to display in a Thingworx Mashup.

Because the websocket protocoll is widespread and the EMS for example is creating a websocket connection to Thingworx too
I thought there will be a possibility to subscribe the data of a websocket directly out of thingworx?

Aanjan
12-Amethyst
(To:mrenner)

If you have a possibility of accessing the server through REST calls, you can just do it directly then; using GetJSON to retrieve or PutJSON to send (part of the ContentLoaderFunctions Resource). If there is no API to hit/ access, we might need to look into leveraging lua.

mrenner
2-Explorer
(To:Aanjan)

Thanks again for your help Aanjan.

I have not a possibility of accessing the server through REST calls because its a websocket communication via websocket protocoll.

When you say "If there is no API to hit/ access, we might need to look into leveraging lua." do you mean to use the EMS and write a websocket client in LUA Script?

supandey
19-Tanzanite
(To:mrenner)

Hi Maximilian, expanding on Aanjan's response yes it would involve lua for collecting and representing your remote device to the EMS - finally on to the Thingworx platform. If you have more of such devices may be it'll help running EMS and lua in Gateway scenario where you can connect multiple of those remote devices running lua scripts pointing to one EMS which in turns connect to thingworx platform.

There's already a community blog on running EMS and lua script in Gateway mode you might want to give it a try if you haven't already- Using the Edge MicroServer and LSR in a Gateway Scenario

Hope this helps.

pjoly
12-Amethyst
(To:supandey)

Hello

I have exactly the same "issue" :

I have to connect Thingworx to a websocket server to get data from several gateways, getting data from several devices.

I receive data in JSON format from the device ("the thing")  and send data by sending a JSON message on the same websocket.

As websocket are used internally in Thingworx I thought that there was a procedure to create a new one to connect with cloud services (which are offered more and more websockets)

So I would be interested by the solution .

Did you put a microedge server in place between the server and Thingworx ?

Is it "easy" to configure for such services ?

Thanks for information.

Regards

mrenner
2-Explorer
(To:pjoly)

Hello

I have to disappoint you, unfortunately I have not yet begun with the implementation.

I will report if I have implemented it with the microedge server in place between the server and Thingworx.


Regards

pjoly
12-Amethyst
(To:mrenner)

Ok thanks for the update.

I was wondering if it should not be easier to develop an extension (java ) to achieve this task and to be able to have a websocket link inside Thingworx.

As I have not yet developp any extension I am not sure , but the explannations for the Thingworx  Eclipse plugin  seem very detailed.

Regards

Pascal

Announcements


Top Tags