Skip to main content
1-Visitor
October 3, 2021
Question

Using the C SDK to Deliver Data to ThingWorx from a Raspberry PI

  • October 3, 2021
  • 2 replies
  • 1978 views

Hi @AkshayKumar I am facing this error 

 

pi@raspberrypi:~/Documents/c-sdk-2.2.12.1052-development/cmake/examples/SteamSensor $ ls
CMakeFiles           libcrypto.so.1.1  Makefile
cmake_install.cmake  libssl.so.1.1     SteamSensor
pi@raspberrypi:~/Documents/c-sdk-2.2.12.1052-development/cmake/examples/SteamSensor $ ./SteamSensor
[FORCE] 2021-10-02 21:01:00,335: Starting up...
[WARN ] 2021-10-02 21:01:00,336: SDK Version: 2.2.12
[WARN ] 2021-10-02 21:01:00,336: TLS Library: OpenSSL
[WARN ] 2021-10-02 21:01:00,336: TLS Library Version: 1.1.1j
[DEBUG] 2021-10-02 21:01:00,336: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io/Thingworx:443/Thingworx/WS
[DEBUG] 2021-10-02 21:01:00,336: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-02 21:01:00,339: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-02 21:01:00,339: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-02 21:01:00,339: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-02 21:01:00,339: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-02 21:01:05,339: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io/Thingworx:443/Thingworx/WS
[DEBUG] 2021-10-02 21:01:05,340: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-02 21:01:05,340: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-02 21:01:05,340: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-02 21:01:05,340: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-02 21:01:05,340: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-02 21:01:10,341: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io/Thingworx:443/Thingworx/WS
[DEBUG] 2021-10-02 21:01:10,341: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-02 21:01:10,341: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-02 21:01:10,341: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-02 21:01:10,341: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-02 21:01:10,341: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-02 21:01:15,341: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io/Thingworx:443/Thingworx/WS
[DEBUG] 2021-10-02 21:01:15,341: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-02 21:01:15,341: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-02 21:01:15,342: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-02 21:01:15,342: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-02 21:01:15,342: twApi_Initialize: Could not connect after 3 attempts
[ERROR] 2021-10-02 21:01:15,342: Error initializing the API

 

Any thoughts/ suggestions.

 

Related:  post

2 replies

16-Pearl
October 4, 2021

Hello @Hanandan 

 

Can you validate the platform URL - there is an extra "/Thingworx" before the port :

https://PP-2110022216B3.portal.ptc.io/Thingworx:443/Thingworx/WS

Hanandan1-VisitorAuthor
1-Visitor
October 4, 2021

Hi @smainente  Good Catch! I did try removing the extra  "/Thingworx" but still getting the same error 

 

my build is successful too(see below):

pi@raspberrypi:~/Documents/c-sdk-2.2.12.1052-development/cmake/examples/SteamSensor $ make
Scanning dependencies of target thirdParty
[ 0%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/cJSON/cJSON.c.o
[ 0%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/ciphers/des.c.o
[ 0%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/hashes/md4.c.o
[ 5%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/hashes/md5.c.o
[ 5%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/hashes/sha1.c.o
[ 5%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/misc/error_to_string.c.o
[ 5%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/misc/base64/base64_decode.c.o
[ 11%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/misc/base64/base64_encode.c.o
[ 11%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/tomcrypt/src/misc/crypt/crypt_argchk.c.o
[ 11%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/wildcard/wildcard.c.o
[ 11%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/adler32.c.o
[ 17%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/crc32.c.o
[ 17%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/deflate.c.o
[ 17%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/gzclose.c.o
[ 17%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/gzlib.c.o
[ 23%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/gzread.c.o
[ 23%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/inffast.c.o
[ 23%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/inflate.c.o
[ 29%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/inftrees.c.o
[ 29%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/trees.c.o
[ 29%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/zutil.c.o
[ 29%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/contrib/minizip/ioapi.c.o
[ 35%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/contrib/minizip/unzip.c.o
[ 35%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/contrib/minizip/zip.c.o
[ 35%] Building C object src/thirdParty/CMakeFiles/thirdParty.dir/zlib/contrib/untgz/untgz.c.o
[ 35%] Built target thirdParty
Scanning dependencies of target twCSdk
[ 35%] Building C object src/CMakeFiles/twCSdk.dir/api/twApi.c.o
[ 41%] Building C object src/CMakeFiles/twCSdk.dir/api/twPasswds.c.o
[ 41%] Building C object src/CMakeFiles/twCSdk.dir/api/twProperties.c.o
[ 41%] Building C object src/CMakeFiles/twCSdk.dir/api/twServices.c.o
[ 41%] Building C object src/CMakeFiles/twCSdk.dir/fileTransfer/twFileManager.c.o
[ 47%] Building C object src/CMakeFiles/twCSdk.dir/fileTransfer/twFileTransferCallbacks.c.o
[ 47%] Building C object src/CMakeFiles/twCSdk.dir/messaging/twBaseTypes.c.o
[ 47%] Building C object src/CMakeFiles/twCSdk.dir/messaging/twInfoTable.c.o
[ 47%] Building C object src/CMakeFiles/twCSdk.dir/messaging/twMessages.c.o
[ 52%] Building C object src/CMakeFiles/twCSdk.dir/messaging/twMessaging.c.o
[ 52%] Building C object src/CMakeFiles/twCSdk.dir/forkedThirdParty/libcfu/src/cfuhash.c.o
[ 52%] Building C object src/CMakeFiles/twCSdk.dir/forkedThirdParty/ntlm/ntlm.c.o
[ 52%] Building C object src/CMakeFiles/twCSdk.dir/primitiveUtils/twPrimitiveUtils.c.o
[ 58%] Building C object src/CMakeFiles/twCSdk.dir/shapes/twShapes.c.o
[ 58%] Building C object src/CMakeFiles/twCSdk.dir/standardProps/twStandardProps.c.o
[ 58%] Building C object src/CMakeFiles/twCSdk.dir/stubs/twApiStubs.c.o
[ 58%] Building C object src/CMakeFiles/twCSdk.dir/subscribedProps/twSubscribedProps.c.o
[ 64%] Building C object src/CMakeFiles/twCSdk.dir/threadUtils/twThreadUtils.c.o
[ 64%] Building C object src/CMakeFiles/twCSdk.dir/tls/twConnectionInfo.c.o
[ 64%] Building C object src/CMakeFiles/twCSdk.dir/tls/twSig.c.o
[ 70%] Building C object src/CMakeFiles/twCSdk.dir/tls/twTls.c.o
[ 70%] Building C object src/CMakeFiles/twCSdk.dir/tls/twOpenSSL.c.o
[ 70%] Building C object src/CMakeFiles/twCSdk.dir/tunneling/twTunnelManager.c.o
[ 70%] Building C object src/CMakeFiles/twCSdk.dir/utils/crypto_wrapper.c.o
[ 76%] Building C object src/CMakeFiles/twCSdk.dir/utils/list.c.o
[ 76%] Building C object src/CMakeFiles/twCSdk.dir/utils/stringUtils.c.o
[ 76%] Building C object src/CMakeFiles/twCSdk.dir/utils/twDict.c.o
[ 76%] Building C object src/CMakeFiles/twCSdk.dir/utils/twHttpProxy.c.o
[ 82%] Building C object src/CMakeFiles/twCSdk.dir/utils/twLogger.c.o
[ 82%] Building C object src/CMakeFiles/twCSdk.dir/utils/twMap.c.o
[ 82%] Building C object src/CMakeFiles/twCSdk.dir/utils/twNtlm.c.o
[ 82%] Building C object src/CMakeFiles/twCSdk.dir/utils/twOfflineMsgStore.c.o
[ 88%] Building C object src/CMakeFiles/twCSdk.dir/utils/twPath.c.o
[ 88%] Building C object src/CMakeFiles/twCSdk.dir/utils/twTasker.c.o
[ 88%] Building C object src/CMakeFiles/twCSdk.dir/utils/twZipTar.c.o
[ 88%] Building C object src/CMakeFiles/twCSdk.dir/websocket/twWebsocket.c.o
[ 94%] Building C object src/CMakeFiles/twCSdk.dir/porting/twPThreads.c.o
[ 94%] Building C object src/CMakeFiles/twCSdk.dir/porting/twLinux.c.o
[ 94%] Building C object src/CMakeFiles/twCSdk.dir/porting/twApiWrapper.c.o
[ 94%] Linking C shared library libtwCSdk.so
[ 94%] Built target twCSdk
Scanning dependencies of target SteamSensor
[ 94%] Building C object examples/SteamSensor/CMakeFiles/SteamSensor.dir/src/main.c.o
cc1: warning: option ‘-mstructure-size-boundary’ is deprecated
/home/pi/Documents/c-sdk-2.2.12.1052-development/examples/SteamSensor/src/main.c: In function ‘main’:
/home/pi/Documents/c-sdk-2.2.12.1052-development/examples/SteamSensor/src/main.c:179:43: warning: passing argument 1 of ‘twApi_RegisterOnAuthenticatedCallback’ from incompatible pointer type [-Wincompatible-pointer-types]
twApi_RegisterOnAuthenticatedCallback(authEventHandler, TW_NO_USER_DATA);
^~~~~~~~~~~~~~~~
In file included from /home/pi/Documents/c-sdk-2.2.12.1052-development/src/shapes/twShapes.h:19,
from /home/pi/Documents/c-sdk-2.2.12.1052-development/src/api/twExt.h:6,
from /home/pi/Documents/c-sdk-2.2.12.1052-development/examples/SteamSensor/src/main.c:8:
/home/pi/Documents/c-sdk-2.2.12.1052-development/src/api/twApi.h:813:56: note: expected ‘authEvent_cb’ {aka ‘void (*)(char *, char *, void *)’} but argument is of type ‘void (*)(char *, void *)’
int twApi_RegisterOnAuthenticatedCallback(authEvent_cb cb, void * userdata);
~~~~~~~~~~~~~^~
[100%] Building C object examples/SteamSensor/CMakeFiles/SteamSensor.dir/src/SteamThing.c.o
cc1: warning: option ‘-mstructure-size-boundary’ is deprecated
[100%] Linking C executable SteamSensor
Copying openssl to test directory.
[100%] Built target SteamSensor
pi@raspberrypi:~/Documents/c-sdk-2.2.12.1052-development/cmake/examples/SteamSensor $ ls
CMakeFiles cmake_install.cmake libcrypto.so.1.1 libssl.so.1.1 Makefile SteamSensor

 

 

but again same error (see below):

 

pi@raspberrypi:~/Documents/c-sdk-2.2.12.1052-development/cmake/examples/SteamSensor $ ./SteamSensor
[FORCE] 2021-10-04 14:00:04,126: Starting up...
[WARN ] 2021-10-04 14:00:04,127: SDK Version: 2.2.12
[WARN ] 2021-10-04 14:00:04,127: TLS Library: OpenSSL
[WARN ] 2021-10-04 14:00:04,127: TLS Library Version: 1.1.1j
[DEBUG] 2021-10-04 14:00:04,127: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io:443/Thingworx/WS
[DEBUG] 2021-10-04 14:00:04,127: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-04 14:00:04,130: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-04 14:00:04,130: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-04 14:00:04,130: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-04 14:00:04,130: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-04 14:00:09,130: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io:443/Thingworx/WS
[DEBUG] 2021-10-04 14:00:09,130: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-04 14:00:09,131: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-04 14:00:09,131: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-04 14:00:09,131: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-04 14:00:09,131: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-04 14:00:14,131: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io:443/Thingworx/WS
[DEBUG] 2021-10-04 14:00:14,131: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-04 14:00:14,131: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-04 14:00:14,131: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-04 14:00:14,131: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-04 14:00:14,131: twApi_Initialize: Error creating websocket structure, retrying
[DEBUG] 2021-10-04 14:00:19,131: twWs_Create: Initializing Websocket Client for https://PP-2110022216B3.portal.ptc.io:443/Thingworx/WS
[DEBUG] 2021-10-04 14:00:19,132: twTlsClient_Create: Initializing TLS Client
[WARN ] 2021-10-04 14:00:19,132: twSocket_Create: getaddrinfo() failed: [Name or service not known]
[DEBUG] 2021-10-04 14:00:19,132: twSocket_Close: socket is already closed or was never opened
[ERROR] 2021-10-04 14:00:19,132: twWs_Create: Error creating BSD socket to be used for the websocket
[ERROR] 2021-10-04 14:00:19,132: twApi_Initialize: Could not connect after 3 attempts
[ERROR] 2021-10-04 14:00:19,132: Error initializing the API

Community Manager
October 20, 2021

Hi @Hanandan.

 

There could be a number of causes, e.g. wrong port, firewall config, etc.  You're also testing using SSL,  You could start there by turning that off to see if the problem might be related to the certificate or configuration.

 

Regards.

 

--Sharon

Hanandan1-VisitorAuthor
1-Visitor
October 20, 2021

Hi @slangley thanks for the response. Do you know any article or steps needed for the configuration. BecauseI used the document (Getting Started with The ThingWorx C SDK on the Raspberry PIhttps://community.ptc.com › iottechtips › UsingT...) from PTC to start with and it did not cover these information. Also, I will try as per your suggestion.

Community Manager
October 28, 2021

Hi @Hanandan.

 

The document you referenced is very old.  You might be more successful by using this one.

 

We also noticed in the error message that you're using port 443, which is a secured port, but the protocol is unsecured (WS).  Have you tried with WSS?

 

Regards.

 

--Sharon