5 Replies Latest reply on Sep 8, 2016 1:55 PM by aanjan RSS
    bkugler Newbie

    Connectivity issues with WS EMS 5.3 and TW 7.2

    I have pored over all of the documentation and comments and am totally lost at this point.  I have a TLS configured Thingworx 7.2 server running on CentOS 7.2.  I am trying to connect a microserver to Thingworx.  I have tried with several flavors of microserver on several different platforms (including the Thingworx server itself).

     

    Here is the WSEMS config.json:

                                                    

          "ws_servers":  [{                                 

                          "host": "10.128.134.175",           

                          "port": 8443                       

                  }],                                         

          "appKey":      "93636885-bf28-424f-9329-bc9f7bc41593",

          "ws_connection":        {                           

                  "encryption":  "none",                     

                  "verbose":      true                       

          },                                                 

          "certificates": {                                   

                  "validate":    false,                     

                  "allow_self_signed":    true               

          },                                                 

          "logger":      {                                   

                  "level":        "TRACE",                   

                  "publish_level":        "TRACE"             

          },                                                 

          "auto_bind":    [                                   

                  {                                           

                          "name": "MyGateway",               

                          "gateway": true                     

                  }                                           

          ]}

     

    Here are the relevant snippets from the trace log:

     

    [DEBUG] 2016-08-29 20:02:16,699 SDK: twWs_Create: Initializing Websocket Client for 10.128.134.175:8443//Thingworx/WS

    [DEBUG] 2016-08-29 20:02:16,699 SDK: twTlsClient_Create: Initializing TLS Client

    [DEBUG] 2016-08-29 20:27:29,362 SDK: twApi_Initialize: Websocket Established after 0 tries

    [DEBUG] 2016-08-29 20:27:29,362 SDK: subscribedPropsMgr_Initialize: Initializing subscribed properties manager

    ...

    [TRACE] 2016-08-29 20:02:16,705 SDK: twApi_Connect: Delaying 1 milliseconds before connecting

    [DEBUG] 2016-08-29 20:02:16,705 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    [DEBUG] 2016-08-29 20:02:16,705 SDK: twTlsClient_Connect: Connecting to server

    [TRACE] 2016-08-29 20:02:16,725 SDK: twWs_Connect: Connected to 10.128.134.175:8443

    [TRACE] 2016-08-29 20:02:16,725 SDK: twWs_Connect: Sent request:

    GET /Thingworx/WS HTTP/1.1

    User-Agent: ThingWorx C SDK

    Upgrade: websocket

    Connection: Upgrade

    Host: 10.128.134.175

    Sec-WebSocket-Version: 13

    Sec-WebSocket-Key: /g8bnoJyBen64fiUefCMsw==

    Max-Frame-Size: 8192

    appKey: 93636885-bf28-424f-9329-bc9f7bc41593

     

     

     

     

    [ERROR] 2016-08-29 20:02:26,725 SDK: twWs_Connect: Error trying to connect

    [DEBUG] 2016-08-29 20:02:26,726 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    [DEBUG] 2016-08-29 20:02:26,727 SDK: twTlsClient_Connect: Connecting to server

     

    The above bit continues to cycle for multiple attempts and finally fails with:

     

    [WARN ] 2016-08-29 20:13:26,744 Main: Unable to connect to server.  Trying .booted config file

    [WARN ] 2016-08-29 20:13:27,375 WsEmsProxy::execute() : Server connection failed.  Error Code: 201

    [FORCE] 2016-08-29 20:13:31,805 Main: Shutdown signal received. Restarting ....

    [TRACE] 2016-08-29 20:13:31,807 wsEmsProxy::~wsEmsProxy: Destructor called

    [TRACE] 2016-08-29 20:13:31,808 WsProxy::~WsProxy: Deleting Thing binding list

    [TRACE] 2016-08-29 20:13:31,808 SDK: Sending Msg >>>>>>>>>

    Message Details:

    Version: 1

    Method/Code: 0xb (UNBIND)

    RequestID: 1

    EndpointID:0

    SessionID: 0

    Multipart: 0

    Count: 1

    Name: MyGateway

     

     

    [DEBUG] 2016-08-29 20:13:31,808 SDK: twMessage_Send: Not authenticated yet

    [ERROR] 2016-08-29 20:13:31,809 SDK: twMessage_Send: Error sending Message with RequestId 1

    [ERROR] 2016-08-29 20:13:31,809 SDK: twApi_UnbindThing: Error creating sending Unbind message

    [DEBUG] 2016-08-29 20:13:31,809 SDK: twMessage_Delete:  Deleting BIND Message: 1

    [DEBUG] 2016-08-29 20:13:31,849 SDK: Disconnect called.  Code: 1000, Reason: Shutting down

    [WARN ] 2016-08-29 20:13:31,849 SDK: sendCtlFrame: Not connected

    [DEBUG] 2016-08-29 20:13:31,849 SDK: twTlsClient_Close: Disconnecting from server

    [WARN ] 2016-08-29 20:13:31,849 SDK: msgHandlerOnClose: WEBSOCKET CLOSED

    [DEBUG] 2016-08-29 20:13:31,849 SDK: twTunnelManager_StopAllTunnels: Attempting to stop all tunnels

    [INFO ] 2016-08-29 20:13:31,849 SDK: subscribedPropsMgr_Delete: Deleting subscribed propery manager

    [DEBUG] 2016-08-29 20:13:31,849 SDK: Disconnect called.  Code: 1000, Reason: Message handler shut down

    [WARN ] 2016-08-29 20:13:31,849 SDK: sendCtlFrame: Not connected

    [DEBUG] 2016-08-29 20:13:31,849 SDK: twTlsClient_Close: Disconnecting from server

    [DEBUG] 2016-08-29 20:13:31,849 SDK: twTlsClient_Close: Disconnecting from server

     

    I see no log entries on the Tomcat side of the house that shows anything going on.  I have combed through every relevant document and post that I could find with no luck.

     

    I have attempted to turn encryption on ("ssl") at which point, I don't see the connection information like above - and I get a different error set:

     

    [DEBUG] 2016-08-29 20:19:31,345 SDK: twWs_Create: Initializing Websocket Client for 10.128.134.175:8443//Thingworx/WS

    [DEBUG] 2016-08-29 20:19:31,345 SDK: twTlsClient_Create: Initializing TLS Client

    [DEBUG] 2016-08-29 20:19:31,345 SDK: twApi_Initialize: Websocket Established after 0 tries

    ...

    [INFO ] 2016-08-29 20:19:31,351 ./wsems: Starting the connection.

    ...

    [TRACE] 2016-08-29 20:19:31,353 SDK: twApi_Connect: Delaying 0 milliseconds before connecting

    [DEBUG] 2016-08-29 20:19:31,353 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    [DEBUG] 2016-08-29 20:19:31,353 SDK: twTlsClient_Connect: Connecting to server

    [ERROR] 2016-08-29 20:19:31,471 SDK: Error intializing SSL connection

    [ERROR] 2016-08-29 20:19:31,472 SDK: twWs_Connect: Error restarting socket.  Error 0

    [DEBUG] 2016-08-29 20:19:36,472 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    [DEBUG] 2016-08-29 20:19:36,472 SDK: twTlsClient_Connect: Connecting to server

    [ERROR] 2016-08-29 20:19:36,569 SDK: Error intializing SSL connection

    [ERROR] 2016-08-29 20:19:36,569 SDK: twWs_Connect: Error restarting socket.  Error 32

    [DEBUG] 2016-08-29 20:19:41,569 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    [DEBUG] 2016-08-29 20:19:41,569 SDK: twTlsClient_Connect: Connecting to server

    [ERROR] 2016-08-29 20:19:41,656 SDK: Error intializing SSL connection

    [ERROR] 2016-08-29 20:19:41,656 SDK: twWs_Connect: Error restarting socket.  Error 32

    [DEBUG] 2016-08-29 20:19:46,656 SDK: twTlsClient_Reconnect: Re-establishing SSL context

    ...

    [DEBUG] 2016-08-29 20:20:27,497 SDK: twTlsClient_Connect: Connecting to server

    [ERROR] 2016-08-29 20:20:27,626 SDK: Error intializing SSL connection

    [ERROR] 2016-08-29 20:20:27,627 SDK: twWs_Connect: Error restarting socket.  Error 32

    [WARN ] 2016-08-29 20:20:31,362 Main: Unable to connect to server.  Trying .booted config file

    [WARN ] 2016-08-29 20:20:32,627 WsEmsProxy::execute() : Server connection failed.  Error Code: 1001



    Sorry for the long post, just wanted to be sure I covered my bases.  As you can see, it looks like the web socket upgrade is failing, but I have no idea why.  If anyone has any suggestions, I'd greatly appreciate hearing them.

     

    Thanks,

     

    Brett

      • Re: Connectivity issues with WS EMS 5.3 and TW 7.2
        aanjan Heavyweight Champ

        Brett, with encryption set to none, do you have an http port (80 or 8080) where ThingWorx is running? Can you switch it to that and retry?

          • Re: Connectivity issues with WS EMS 5.3 and TW 7.2
            bkugler Newbie

            Aanjan,

             

            Thanks for replying.  I have modified Tomcat's server.xml to have port 80 exposed as follows:

             

                <Connector port="80" protocol="HTTP/1.1"

                          connectionTimeout="20000"

                          redirectPort="8443" />

             

            Executing the WSEMS now gives the following:

             

            [TRACE] 2016-08-29 22:06:14,692 SDK: twWs_Connect: Connected to 10.128.134.175:80

            [TRACE] 2016-08-29 22:06:14,694 SDK: twWs_Connect: Sent request:

            GET /Thingworx/WS HTTP/1.1

            User-Agent: ThingWorx C SDK

            Upgrade: websocket

            Connection: Upgrade

            Host: 10.128.134.175

            Sec-WebSocket-Version: 13

            Sec-WebSocket-Key: BQG4rDbmQ/LhvBbbQl+7Gg==

            Max-Frame-Size: 8192

            appKey: 93636885-bf28-424f-9329-bc9f7bc41593

             

             

             

             

            [TRACE] 2016-08-29 22:06:14,736 SDK: twWs_Connect: Got Response from Server:

             

             

            HTTP/1.1 302 Found

            Server: Apache-Coyote/1.1

            Cache-Control: private

            Expires: Wed, 31 Dec 1969 18:00:00 CST

            Location: https://10.128.134.175:8443/Thingworx/WS

            Content-Length: 0

            Date: Mon, 29 Aug 2016 22:06:14 GMT

             

             

             

             

            [ERROR] 2016-08-29 22:06:14,736 SDK: twWs_Connect: Error initializing web socket.  Response code: 302

             

            I am receiving a response, but it's unclear what to do about it.

             

            302

            TW_ERROR_CALLBACK_NOT_FOUND

            The specified callback was not found. Check the callback parameters passed to the function.

             

            Thanks for the continued support,

             

            Brett

              • Re: Connectivity issues with WS EMS 5.3 and TW 7.2
                bkirchner-2 Explorer

                HI,

                I feel your pain. I went through the documentation and possibly 1/3 of the internet assisted by google.

                Eventually this is how far I got.

                My Tomcat is installed on port 8081.

                 

                This is my config.json file

                 

                {

                    "ws_servers":    [{

                            "host":    "192.168.2.22",

                            "port":    8081

                        }],

                    "appKey":    "732f0c41-db6e-418a-8cca-7530feafa310",

                    "ws_conection":    {

                        "encription":    "none",

                        "verbose":    true

                    },

                    "certificates":    {

                        "validate":    false,

                        "allow_self_assigned":    true

                    },

                    "http_server":    {

                        "host":    "localhost",

                        "port":    8081,

                        "ssl":    false,

                        "authenticate":    false

                    },

                    "logger":    {

                        "level":    "TRACE",

                        "publish_directory":    "c:\\thingworks\\microserver\\logger_dir",

                        "publish_level":    "TRACE",

                        "max_file_storage":    200000,

                        "auto_flush":    true

                    },

                    "auto_bind":    [{

                            "name":    "TrainingWSEMS",

                            "gateway":    false

                        }]

                }

                 

                 

                I have a remotething called TrainingWSEMS based on the EMSGateway template.

                 

                Please note all of the ports changed and i ended using my IP adress as apposed to localhost.

                 

                in the etc directory you then need to have the following

                the config.lua should have the following.

                 

                scripts.log_level = "INFO"

                 

                scripts.TrainingWSEMS = {

                    file = "thing.lua",

                    template = "example",

                }

                 

                scripts.sample = {

                  file = "sample.lua"

                }

                 

                 

                Now if everything is setup and correct it should work........

                In the directory that you have extracted the microserver you need to run both the  wsems.exe and the luascriptresourse.exe in 2 different shells.

                 

                To check that its working / connectiong you need to go to these 2 links

                 

                http://localhost:8081/Thingworx/Things/LocalEms/Properties/isConnected

                if this one is connected you get this.....

                {"rows":[{"isConnected":false}],"datashape":{"fieldDefinitions":{"isConnected":{"name":"isConnected","description":"","baseType":"BOOLEAN","aspects":{}}}}}

                 

                 

                 

                and

                http://localhost:8081/Thingworx/Things/SystemRepository/Properties/name

                 

                this gives nothing,...

                 

                Thats as far as i get.

                If i go into thingworx it hangs......

                So i gave up.

            • Re: Connectivity issues with WS EMS 5.3 and TW 7.2
              bkugler Newbie

              OK,

               

              A follow up to my original post.

               

              I went back and created a Win2008 R2 server and installed TW 7.2 HA on it.  I then setup non-secure communcations (allowed port 8080 on the server, essentially).  Then I tested the WSEMS v. 5.2 and 5.3 and they were both able to connect and retrieve data.  Below are the relevant configs for everything.  Next steps will be to determine how to lock this down - clearly there is an issue with TLS in my production environment.

               

              WSEMS config.json

              {

                  "ws_servers":    [{

                          "host":    "10.128.9.139",

                          "port":    8080

                      }],

                  "appKey":    "d6021b04-cde5-440a-ab14-386130c83b94",

                  "ws_connection":    {

                      "encryption":    "none"

                  }

              }

               

              Tomcat server.xml

              Make sure you have a connector that looks like this:

              <Connector port="8080" protocol="HTTP/1.1"

                             connectionTimeout="20000"

                             redirectPort="8443" />

               

              And as previously mentioned, be sure you have opened port 8080 on the firewall.

               

              If you are running on a Linux system and are not root, you will also want to run wsems with sudo.

               

              I will try to follow up with more information as I work through getting our secure server up and running.