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

Problem connecting C SDK to Thingworx composer

agupta-61
1-Newbie

Problem connecting C SDK to Thingworx composer

Hi,

I am trying the SteamSensor example available in the C SDK folder. But on finally running the exe file I get the following error:

developer portal.png

I am using the 30 day trial online composer whose address is : https://pp-180103xxxxxx.devportal.ptc.io/Thingworx/Composer/index.html

In the main.c file I set:

#define TW_HOST "pp-180103xxxxxx.devportal.ptc.io"

#define TW_APP_KEY "18ecb3d9-xxxx-yyyy-zzzz-ab6b29dc21a8"

What could be the problem? Any help is appreciated

17 REPLIES 17
supandey
19-Tanzanite
(To:agupta-61)

Hi Amit, are you attempting to create secured websocket connection with WSS or insecured with WS?

Hi Sushant,

How do I check that?

I am not using #define NO_TLS in the main.c file. So port no should be 443. Has it got something to do with that?

I am sorry. I am new to this field and was just following the steps mentioned in the tutorial. (https://developer.thingworx.com/resources/guides/thingworx-c-sdk-setup-guide/connection-test-setup)

supandey
19-Tanzanite
(To:agupta-61)

The error in the command prompt is highlighting issues with creating SSL connection, it seems to be using the 443 which inherently points to the secured websocket. I've not tried this online guide, will check if there's anything that can be configured there, but could you check if there's any possibility that the pc from which you are executing this piece of code is not blocking e.g. firewall or some anti virus this SSL connection to ThingWorx server.

I turned off the Windows Firewall on my system. It didn't work but the error log changed slightly.

The error now reads: "Error initialising socket connection" instead of "Error initialising SSL connection".

developer portal.png

supandey
19-Tanzanite
(To:agupta-61)

Hmm.. interesting. So if I use the link that you have shared in your above response and if you check the Troubleshooting section the error you are receiving (which has error code of 201) seems to require users to check the websocket configuration. Some questions about your setup

1. What sort of machine are you working with, from screenshot looks like Win7, is that right?

2. How are you connected to the network? via LAN or WiFi?

Yes it's a Windows 7 machine. I am currently using WiFi for connecting to the network.

.

supandey
19-Tanzanite
(To:agupta-61)

Somehow I feel this kind of relates to the network adaptor, (I could be wrong though but it's worth checking) . Could you give this a try How to fix failed Windows sockets initialization? - Microsoft Community it basically points to use the Window's NetShell utility for resetting the see this:  TCP/IP How to reset TCP/IP by using the NetShell utility

So I tried the above mentioned steps and it doesn't work. Instead it again started giving the previous error: "Error initialising SSL connection" as mentioned in the original post.

I also tried another Windows 7 system with a LAN connection but it still gives the same error.

Is there anything more which I can try to make it work?

supandey
19-Tanzanite
(To:agupta-61)

Sorry i somehow missed to reply, so what i wanted to reply yesterday to you is to ask you if you had tried without the secured websocket connection just to see if it works that way. i.e. by using 8080/80

No 80/8080 doesn't work. Just checked it. Error: "Error initialising SSL connection"

For using port 80 I used #define NO_TLS statement at the top of main.c code. For using 8080 I changed 80 to 8080 in if/else statement under main() function.


By the way just for clarification: The port no depends on http/https. Right? In this case the thingworx developer portal has HTTPS in the weblink

adikumar
5-Regular Member
(To:agupta-61)

Hi Amit,

Can you please check whether your Application Key is not expired from the Application Key which you are using? Are you building the C SDK examples using CMake? After building the C SDK examples, just go to the main.c file for SteamSensor example.

Check the line which is in bold into your code of the main.c file for SteamSensor example and change it to 80 or 8080.

#if defined NO_TLS

#define TW_PORT 8080

#else

#define TW_PORT 443    //change it to 80 or 8080

#endif

Hope so it will work.

Thanks,

Aditya

Hi Aditya,

Yes I am building the C SDK example with CMake. My application key had expired. Thanks for pointing that out. But even after correcting it and modifying the main.c by replacing 443 with 80 or 8080 it doesn't work and gives the same error.

adikumar
5-Regular Member
(To:adikumar)

Can you please try it with TLS port as below:

#define TW_TLS_INCLUDE "twNoTls.h"

#define NO_TLS

#if defined NO_TLS

#define TW_PORT 443

#else

#define TW_PORT 443

#endif

It still doesn't work. However if you have used #define NO_TLS shouldn't the port no. be 80/8080 instead of 443?

In any case I tried both the port no. for the above mentioned code snippet and it still gives the same error. In both cases it tries to initialise TLS connection even though #define NO_TLS is used.

supandey
19-Tanzanite
(To:agupta-61)

Amit you are right to understand with HTTPS you'll 443 as the standard port (this could change of course) and 80/8080 would normally be for the HTTP. These settings are configured in the server.xml file. In this case it's challenging for you because you don't have access to that file due to the hosted instance, I wanted to find out sometime to basically set it up exactly the same and do this test. I will check with the team about the correct ports for your hosted trial instance.

The other option for you could be to download the trial instance and install locally and then set this up. That way you'll have more control over the what ports to use as you will be able to configure them yourself in the server.xml file.

Same issue, tried different ports with or without SSL.

With SSL I get:

Error intializing SSL connection

Without SSL I get:

Error trying to connect

I'm using the .NET SDK: SteamSensor example

Would be nice to have a guide for hosted trial platforms.

Announcements