Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hi,
I'm trying to set up my Raspberry Pi to Thingworx. I'm following the quickstart guide (https://developer.thingworx.com/resources/guides/thingworx-raspberry-pi-quickstart/run-lsr). I've set up the EMS and that works. However, I'm now at the point where I have configured the LSR and am now trying to run it. I have the EMS running in another window and input the code below as instructed:
sudo ./luaScriptResource
The result is below:
[INFO ] 2018-03-29 13:50:57,437 ./luaScriptResource: Using config file: /home/pi/microserver/etc/config.lua [FORCE] 2018-03-29 13:50:57,437 ./luaScriptResource: Starting up .... [INFO ] 2018-03-29 13:50:57,441 luaScriptResource:main: Encryption is disabled on the RAP connection. [INFO ] 2018-03-29 13:50:57,441 luaScriptResource:main: FIPS is disabled. [INFO ] 2018-03-29 13:50:57,444 ./luaScriptResource: New path is /home/pi/microserver/etc/thingworx/clibs:/home/pi/microserver/etc/custom/clibs:/home/pi/microserver/etc/community/clibs:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [WARN ] 2018-03-29 13:50:57,446 ScriptResource::initialize: Encryption is disabled on HTTP Server. [ERROR] 2018-03-29 13:50:57,447 ScriptResource::initialize: Failed to get HTTP Server authenticate configuration. [ERROR] 2018-03-29 13:50:57,447 ./luaScriptResource: Error initiatizing script resource [ERROR] 2018-03-29 13:50:57,447 luaScriptResource:main: Insecure configuration. Shutting down LSR. [WARN ] 2018-03-29 13:50:58,447 luaConfigurator::~luaConfigurator: Closing Lua state
Any advice is greatly appreciated.
Thanks in advance,
Charlotte
Solved! Go to Solution.
Hello cssummers1,
I made some quick changes to the lua file.Try with the below config.lua
scripts.log_level = "DEBUG"
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate",
identifier = "PiThing",
scanrate = 1000,
taskrate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 8000
scripts.rap_ssl = false
scripts.rap_server_authenticate = false
scripts.script_resource_host = "127.0.0.1"
scripts.script_resource_port = 8001
scripts.script_resource_ssl = false
scripts.script_resource_authenticate = false
Changed the scripts.rap_port to 8000 - This should be the port on which EMS is running. Should be the same as the http_server port in config.json.
I have also added the identifier in the binding section.
Let me know if this helps.
Hi,
What version of EMS are you using? And can you share your config.lua file here?
I'm using the latest version of the EMS that's provided by ThingWorx - I got the download here.
This is the current state of my config.lua file:
scripts.log_level = "INFO" scripts.PiThing = { file = "thing.lua", template = "PiTemplate", scanRate = 1000, taskRate = 30000, indentifier = "PiThing" } scripts.rap_host = "127.0.0.1" scripts.rap_host = 8080 scripts.rap_ssl = false scripts.script_resource_host = "localhost" scripts.script_resource_port = 9001 scripts.script_resource_ssl = "false" scripts.script_resource_authenticate = false
Since making the post I made some changes to my config.lua file and this is the new output I get:
[INFO ] 2018-04-04 08:31:01,796 ./luaScriptResource: Using config file: /home/pi/microserver/etc/config.lua
[FORCE] 2018-04-04 08:31:01,796 ./luaScriptResource: Starting up ....
[INFO ] 2018-04-04 08:31:01,802 luaScriptResource:main: Encryption is disabled on the RAP connection.
[INFO ] 2018-04-04 08:31:01,802 luaScriptResource:main: FIPS is disabled.
[INFO ] 2018-04-04 08:31:01,805 ./luaScriptResource: New path is /home/pi/microserver/etc/thingworx/clibs:/home/pi/microserver/etc/custom/clibs:/home/pi/microserver/etc/community/clibs:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[WARN ] 2018-04-04 08:31:01,807 ScriptResource::initialize: Encryption is disabled on HTTP Server.
[WARN ] 2018-04-04 08:31:01,808 ScriptResource::initialize: Authentication is disabled on the HTTP Server.
[FORCE] 2018-04-04 08:31:01,837 httpServer: starting http server port=9001
[INFO ] 2018-04-04 08:31:01,907 thingworx.shape: Creating a new shape.
[INFO ] 2018-04-04 08:31:01,908 PiThing: -- Configuration -------------------------------
[INFO ] 2018-04-04 08:31:01,908 PiThing: scanRate: 1000
[INFO ] 2018-04-04 08:31:01,908 PiThing: scanRateResolution: 500
[INFO ] 2018-04-04 08:31:01,908 PiThing: taskRate: 30000
[INFO ] 2018-04-04 08:31:01,908 PiThing: keepAliveRate: 60000
[INFO ] 2018-04-04 08:31:01,908 PiThing: requestTimeout: 15000
[INFO ] 2018-04-04 08:31:01,908 PiThing: registerRate: 43200000
[INFO ] 2018-04-04 08:31:01,908 PiThing: register: true
[INFO ] 2018-04-04 08:31:01,908 PiThing: getPropertySubscriptionOnReconnect: false
[INFO ] 2018-04-04 08:31:01,908 PiThing: maxConcurrentPropertyUpdates: 100
[INFO ] 2018-04-04 08:31:01,909 PiThing: defaultPushType: VALUE
[INFO ] 2018-04-04 08:31:01,909 PiThing: useShapes: true
[INFO ] 2018-04-04 08:31:01,909 PiThing: identifier: Not Specififed
[INFO ] 2018-04-04 08:31:01,909 PiThing: ------------------------------------------------
[INFO ] 2018-04-04 08:31:01,911 thingworx.template: Adding shape 'shapes.metadata' to template 'thingworx.template'
[INFO ] 2018-04-04 08:31:01,912 thingworx.template: Adding shape 'shapes.propsubscribe' to template 'thingworx.template'
[INFO ] 2018-04-04 08:31:01,912 thingworx.template: Creating new templates.PiTemplate named 'PiThing'
[INFO ] 2018-04-04 08:31:01,912 PiThing: -- Initializing properties ---------------------
[INFO ] 2018-04-04 08:31:01,912 PiThing: Initialized property upToDate [baseType: BOOLEAN, pushType: NEVER, handler: nil, value: true]
[INFO ] 2018-04-04 08:31:01,913 PiThing: Initialized property cpu_volt [baseType: NUMBER, pushType: ALWAYS, handler: nil, value: 0]
[INFO ] 2018-04-04 08:31:01,913 PiThing: Initialized property cpu_temperature [baseType: NUMBER, pushType: ALWAYS, handler: nil, value: 0]
[INFO ] 2018-04-04 08:31:01,913 PiThing: Initialized property cpu_freq [baseType: NUMBER, pushType: ALWAYS, handler: nil, value: 0]
[INFO ] 2018-04-04 08:31:01,913 PiThing: ------------------------------------------------
[INFO ] 2018-04-04 08:31:03,884 PiThing: -- Starting script --------------------------
[INFO ] 2018-04-04 08:31:03,884 PiThing: Registering core callback handler
[INFO ] 2018-04-04 08:31:03,884 PiThing: Starting main loop
[INFO ] 2018-04-04 08:31:03,884 PiThing: Calling lifecycle start listeners.
[INFO ] 2018-04-04 08:31:03,884 shapes.propsubscribe: Initialized
[INFO ] 2018-04-04 08:31:03,889 thingworx.handler: Creating a new handler.
[ERROR] 2018-04-04 08:31:03,907 UnencryptedClientStream::doopen: Error opening socket. Error: 22
[ERROR] 2018-04-04 08:31:03,907 HttpClient::initialize: Exception while opening connection request to 8080. Error: Error opening non-TLS socket [8080:8000]
[ERROR] 2018-04-04 08:31:03,908 luaBindings::httpPost: Error POSTing to HTTP Server at 8080/Thingworx/Things/LocalEms/Services/AddEdgeThing
[INFO ] 2018-04-04 08:31:03,908 PiThing: Error occured while accessing EMS. Checking isConnected.
[ERROR] 2018-04-04 08:31:03,910 UnencryptedClientStream::doopen: Error opening socket. Error: 22
[ERROR] 2018-04-04 08:31:03,910 HttpClient::initialize: Exception while opening connection request to 8080. Error: Error opening non-TLS socket [8080:8000]
[ERROR] 2018-04-04 08:31:03,910 luaBindings::httpGet: Error GETing from HTTP server at 8080/Thingworx/Things/LocalEms/Properties/isConnected
[INFO ] 2018-04-04 08:31:03,910 PiThing: EMS is available: false, online: false
[ERROR] 2018-04-04 08:31:09,452 UnencryptedClientStream::doopen: Error opening socket. Error: 22
[ERROR] 2018-04-04 08:31:09,453 HttpClient::initialize: Exception while opening connection request to 8080. Error: Error opening non-TLS socket [8080:8000]
[ERROR] 2018-04-04 08:31:09,453 luaBindings::httpPost: Error POSTing to HTTP Server at 8080/Thingworx/Things/LocalEms/Services/AddEdgeThing
[INFO ] 2018-04-04 08:31:09,453 PiThing: Error occured while accessing EMS. Checking isConnected.
[ERROR] 2018-04-04 08:31:09,455 UnencryptedClientStream::doopen: Error opening socket. Error: 22
[ERROR] 2018-04-04 08:31:09,455 HttpClient::initialize: Exception while opening connection request to 8080. Error: Error opening non-TLS socket [8080:8000]
[ERROR] 2018-04-04 08:31:09,455 luaBindings::httpGet: Error GETing from HTTP server at 8080/Thingworx/Things/LocalEms/Properties/isConnected
[INFO ] 2018-04-04 08:31:09,455 PiThing: EMS is available: false, online: false
Any further comments, questions or help is greatly appreciated.
Charlotte
Hello Charlotte,
I noticed that you are using scripts.rap_host = 8080 instead of scripts.rap_port = 8080 in the config.lua.
Also as you have defined an identifier for the remote thing in the config.lua have you also added the identifier to the PiThing in the Composer?
Hello,
Thank you! That has been changed from "host" to "port".
I'm trying your suggesting regarding the identifier however, when I select the "browse" button next to the identifier section no suggestions come up for me to choose from. I have tried just typing the name of my Thing in the identifier box but I am still not able to bind my remote properties to my Thing.
Any suggestions?
Hello Charlotte,
Identifiers provide an alternate way to associate a virtual thing with a remote thing in the ThingWorx platform and at the device. If you specify an Identifier at the server then the same identifier must be used in the client application. This is because once the identifier is specified, the server uses the identifier instead of the name to match a virtual thing connection to a remote thing.
You can just add your own identifier at the Thingworx platform and specify the same in config.lua as below.
But before you try this, could you try enabling TLS communication between EMS and LSR (or) using EMS version 5.3.4 first? as there was a bug that recently came in which only effects when using EMS 5.4.0 on a Linux env(reported on Debian and Ubuntu) and configurations that don't use TLS.
Paste you config and log files here if you face any issues.
Hi jdass,
I am evaluating Composer on a 30 day trial and have been having a similar problem on 5.4 so I have re-built with 5.3.4 as you suggested. I now cannot get a working connection to the WS on-line test server using my config.json file that seemed to work with 5.4. I suspect the documentation now does not cover 5.3.4 (it refers to a ws_encryption parameter which is not defined in config.json.complete) so I cannot debug the connection. I have included the trace and my config.json - I would be grateful for any help.
pi@raspberrypi:~/microserver $ sudo ./wsems
[INFO ] 2018-04-10 22:38:20,428 ./wsems: Using config file: /home/pi/microserver/e tc/config.json
[FORCE] 2018-04-10 22:38:20,429 ./wsems: Starting up ....
[FORCE] 2018-04-10 22:38:20,431 ./wsems: Initializing EMS ....
[FORCE] 2018-04-10 22:38:20,431 main: Using config file /home/pi/microserver/etc/c onfig.json
[INFO ] 2018-04-10 22:38:20,431 ./wsems: Creating the WsEms proxy.
[INFO ] 2018-04-10 22:38:20,431 ./wsems: Starting HTTP Server.
[INFO ] 2018-04-10 22:38:20,432 ./wsems: Initializing the ThingWorx REST interface .
[FORCE] 2018-04-10 22:38:20,432 httpServer: starting http server port=8000
[DEBUG] 2018-04-10 22:38:20,432 httpServer: http server bound to port=8000.
[DEBUG] 2018-04-10 22:38:20,434 SDK: twWs_Create: Initializing Websocket Client fo r pp-1804041630us.devportal.ptc.io:443//Thingworx/WS
[DEBUG] 2018-04-10 22:38:20,434 SDK: twTlsClient_Create: Initializing TLS Client
[DEBUG] 2018-04-10 22:38:20,465 SDK: twApi_Initialize: Websocket Established after 0 tries
[DEBUG] 2018-04-10 22:38:20,465 SDK: subscribedPropsMgr_Initialize: Initializing s ubscribed properties manager
[DEBUG] 2018-04-10 22:38:20,465 jsonConfigurator::getJsonEntity: Key cert_chain no t found
[DEBUG] 2018-04-10 22:38:20,465 jsonConfigurator::getJsonEntity: Key validation_cr iteria not found
[DEBUG] 2018-04-10 22:38:20,466 jsonConfigurator::getJsonEntity: Parent file not f ound
[DEBUG] 2018-04-10 22:38:20,467 SDK: twTunnelManager_Create: Tunnel Manager single ton already exists
[DEBUG] 2018-04-10 22:38:20,467 WsEmsProxy::bindThing: Host specified as 'localhos t'. Testing IPV6/IPV4 connectivity
[DEBUG] 2018-04-10 22:38:20,471 SDK: added PiThing to boundList
[DEBUG] 2018-04-10 22:38:20,472 SDK: twApi_BindThings: not currently connected, on ly binding things to api
[DEBUG] 2018-04-10 22:38:20,472 SDK: twMessage_Delete: Deleting BIND Message: 1
[DEBUG] 2018-04-10 22:38:20,471 jsonConfigurator::getJsonEntity: Parent file not f ound
[INFO ] 2018-04-10 22:38:20,471 wsEmsProxy::initialize: Initialization complete!
[ERROR] 2018-04-10 22:38:20,474 SDK: twMap_Add: key already exists, deleting new e ntry
[INFO ] 2018-04-10 22:38:20,477 ./wsems: Starting the connection.
pp-1804041630us.devportal.ptc.io:443-->[DEBUG] 2018-04-10 22:38:20,480 SDK: twTlsC lient_Reconnect: Re-establishing SSL context
[DEBUG] 2018-04-10 22:38:20,508 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-10 22:38:30,542 SDK: twWs_Connect: Error trying to connect
[DEBUG] 2018-04-10 22:38:30,542 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:38:30,568 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2018-04-10 22:38:35,603 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:38:36,653 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-10 22:38:47,213 SDK: twWs_Connect: Error trying to connect
[DEBUG] 2018-04-10 22:38:47,213 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:38:47,239 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2018-04-10 22:38:52,274 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:38:52,334 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-10 22:39:02,411 SDK: twWs_Connect: Error trying to connect
[DEBUG] 2018-04-10 22:39:02,411 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:39:02,531 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2018-04-10 22:39:07,648 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:39:07,771 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-10 22:39:17,886 SDK: twWs_Connect: Error trying to connect
[DEBUG] 2018-04-10 22:39:17,886 SDK: twTlsClient_Reconnect: Re-establishing SSL co ntext
[DEBUG] 2018-04-10 22:39:18,86 SDK: twTlsClient_Connect: Connecting to server
[WARN ] 2018-04-10 22:39:20,483 Main: Unable to connect to server. Trying .booted config file
[WARN ] 2018-04-10 22:39:23,200 WsEmsProxy::execute() : Server connection failed. Error Code: 201
[FORCE] 2018-04-10 22:39:25,510 Main: Shutdown signal received. Restarting ....
[DEBUG] 2018-04-10 22:39:25,512 SDK: twMessage_Send: Not authenticated yet
[ERROR] 2018-04-10 22:39:25,512 SDK: twMessage_Send: Error sending Message with Re questId 2
[ERROR] 2018-04-10 22:39:25,512 SDK: twApi_UnbindThing: Error creating sending Unb ind message
[DEBUG] 2018-04-10 22:39:25,512 SDK: twMessage_Delete: Deleting BIND Message: 2
terminate called without an active exception
{
"ws_servers": [{
"host": "pp-1804041630us.devportal.ptc.io",
"port": 443
}],
"appKey": "c323961f-8169-4add-ae5a-f50dfdba0c61",
"http_server" : {
"host" : "127.0.0.1",
"port" : 8000,
"ssl" : false,
"use_default_certificate" : true,
"authenticate" : false
},
"logger" : {
"level" : "DEBUG"
},
"auto_bind" : [{
"name" : "PiThing",
"gateway" : true
}],
"certificates" : {
"validate" : false,
"allow_self_signed" : true
},
"ws_connection" : {
"encryption" : "none",
"verbose" : true,
"msg_timeout" : 1000
}
}
Hi jdass,
I've installed version 5.3.4 and have recreated my config.json file and have posted the output below.
The PiThing on my raspberry pi successfully connects to my PiThing in Thingworx but when I try to bind remote properties I still get a message saying "Error browsing properties. Be sure the remote device/server is connected and configured properly" rather than displaying the properties.
Running the LSR shows that my properties have been created properly on the Pi and are updating regularly.
[INFO ] 2018-04-11 11:08:05,440 ./wsems: Using config file: /home/pi/microserver/etc/config.j son
[FORCE] 2018-04-11 11:08:05,441 ./wsems: Starting up ....
[FORCE] 2018-04-11 11:08:05,442 ./wsems: Initializing EMS ....
[FORCE] 2018-04-11 11:08:05,442 main: Using config file /home/pi/microserver/etc/config.json
[INFO ] 2018-04-11 11:08:05,442 ./wsems: Creating the WsEms proxy.
[INFO ] 2018-04-11 11:08:05,442 ./wsems: Starting HTTP Server.
[INFO ] 2018-04-11 11:08:05,442 ./wsems: Initializing the ThingWorx REST interface.
[FORCE] 2018-04-11 11:08:05,442 httpServer: starting http server port=8000
[DEBUG] 2018-04-11 11:08:05,443 httpServer: http server bound to port=8000.
[DEBUG] 2018-04-11 11:08:05,445 SDK: twWs_Create: Initializing Websocket Client for localhost :9000//Thingworx/WS
[DEBUG] 2018-04-11 11:08:05,445 SDK: twTlsClient_Create: Initializing TLS Client
[DEBUG] 2018-04-11 11:08:05,447 SDK: twApi_Initialize: Websocket Established after 0 tries
[DEBUG] 2018-04-11 11:08:05,447 SDK: subscribedPropsMgr_Initialize: Initializing subscribed p roperties manager
[DEBUG] 2018-04-11 11:08:05,447 jsonConfigurator::getJsonEntity: Key cert_chain not found
[DEBUG] 2018-04-11 11:08:05,447 jsonConfigurator::getJsonEntity: Key validation_criteria not found
[DEBUG] 2018-04-11 11:08:05,448 jsonConfigurator::getJsonEntity: Parent file not found
[DEBUG] 2018-04-11 11:08:05,449 SDK: twTunnelManager_Create: Tunnel Manager singleton already exists
[DEBUG] 2018-04-11 11:08:05,450 SDK: added PiThing to boundList
[DEBUG] 2018-04-11 11:08:05,450 SDK: twApi_BindThings: not currently connected, only binding things to api
[DEBUG] 2018-04-11 11:08:05,450 SDK: twMessage_Delete: Deleting BIND Message: 1
[DEBUG] 2018-04-11 11:08:05,450 jsonConfigurator::getJsonEntity: Parent file not found
[INFO ] 2018-04-11 11:08:05,450 wsEmsProxy::initialize: Initialization complete!
[INFO ] 2018-04-11 11:08:05,451 ./wsems: Starting the connection.
localhost:9000-->[DEBUG] 2018-04-11 11:08:05,453 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2018-04-11 11:08:05,454 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2018-04-11 11:08:05,490 SDK: ws_on_headers_complete: Websocket connected!
[INFO ] 2018-04-11 11:08:05,490 SDK: twWs_Connect: Websocket connected!
[DEBUG] 2018-04-11 11:08:05,490 SDK: twWs_SendMessage: Sent 60 bytes using 1 frames.
[DEBUG] 2018-04-11 11:08:05,502 SDK: twMessage_Delete: Deleting RESPONSE Message: 2
[DEBUG] 2018-04-11 11:08:05,502 SDK: twMessage_Delete: Deleting AUTH Message: 2
[WARN ] 2018-04-11 11:08:05,502 SDK: twBindBody_Delete: NULL body or stream pointer
[DEBUG] 2018-04-11 11:08:05,502 SDK: twMessage_Delete: Deleting BIND Message: 0
[DEBUG] 2018-04-11 11:08:05,502 SDK: twWs_SendMessage: Sent 26 bytes using 1 frames.
[INFO ] 2018-04-11 11:08:05,502 Main: Succesfully connected. Saving .booted config file
[DEBUG] 2018-04-11 11:08:05,505 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:08:05
[DEBUG] 2018-04-11 11:08:05,570 SDK: twMessage_Delete: Deleting RESPONSE Message: 3
[DEBUG] 2018-04-11 11:08:05,570 SDK: twMessage_Delete: Deleting BIND Message: 3
[INFO ] 2018-04-11 11:08:06,588 SDK: api_requesthandler: No handler found. Returning 404
[DEBUG] 2018-04-11 11:08:06,589 SDK: twMessage_Delete: Deleting RESPONSE Message: 0
[DEBUG] 2018-04-11 11:08:06,590 SDK: twWs_SendMessage: Sent 17 bytes using 1 frames.
[DEBUG] 2018-04-11 11:08:06,590 SDK: twMessage_Delete: Deleting RESPONSE Message: 14
[DEBUG] 2018-04-11 11:08:06,590 SDK: twMessage_Delete: Deleting REQUEST Message: 14
[INFO ] 2018-04-11 11:08:35,282 SDK: api_requesthandler: No handler found. Returning 404
[DEBUG] 2018-04-11 11:08:35,283 SDK: twMessage_Delete: Deleting RESPONSE Message: 0
[DEBUG] 2018-04-11 11:08:35,283 SDK: twWs_SendMessage: Sent 17 bytes using 1 frames.
[DEBUG] 2018-04-11 11:08:35,283 SDK: twMessage_Delete: Deleting RESPONSE Message: 15
[DEBUG] 2018-04-11 11:08:35,283 SDK: twMessage_Delete: Deleting REQUEST Message: 15
[DEBUG] 2018-04-11 11:09:00,549 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:09:00
[DEBUG] 2018-04-11 11:09:55,612 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:09:55
[DEBUG] 2018-04-11 11:10:50,669 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:10:50
[DEBUG] 2018-04-11 11:11:45,731 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:11:45
[DEBUG] 2018-04-11 11:12:40,801 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:12:40
[DEBUG] 2018-04-11 11:13:35,861 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:13:35
[DEBUG] 2018-04-11 11:14:30,931 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:14:30
[DEBUG] 2018-04-11 11:15:26,1 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:15:26
[DEBUG] 2018-04-11 11:16:21,68 SDK: sendCtlFrame: >>>>> Sending Ping. Msg: 10:16:21
Here is a copy of my config.json file
{ "ws_servers": [{ "host": "localhost", "port": 9000 }], "http_server": { "host": "127.0.0.1", "port": 8000, "ssl": false, "authenticate": false }, "appKey": "c9291758-bb3e-45e4-83a8-fb8b8abcff35", "logger": { "level": "TRACE" }, "auto_bind": [ { "name": "PiThing", "host": "127.0.0.1", "port": 8001, "protocol": "http",
"identifier": "PiThing", "gateway": false }], "certificates": { "validate": false, "allow_self_signed": true }, "ws_connection": { "encryption": "none", "verbose": true, "msg_timeout": 1000 } }
If you have any ideas about where to go from here that would be greatly appreciated!
Thanks,
Charlotte
Hi Charlotte,
Can you also share your config.lua please?
Hello,
Here's my config.lua file:
scripts.log_level = "DEBUG" scripts.PiThing = { file = "thing.lua", template = "PiTemplate", scanRate = 1000, taskRate = 30000 } scripts.rap_host = "127.0.0.1" scripts.rap_port = 8001 scripts.rap_ssl = false scripts.rap_validate = false scripts.script_resource_host = "127.0.0.1" scripts.script_resource_port = 8001 scripts.script_resource_ssl = false scripts.script_resource_authenticate = false
Also, here is my microserver/etc/custom/templates/PiTemplate.lua file
module ("templates.PiTemplate", thingworx.template.extend) properties.cpu_temperature = { baseType="NUMBER", pushType="ALWAYS", value=0 } properties.cpu_freq = { baseType="NUMBER", pushType="ALWAYS", value=0 } properties.cpu_volt = { baseType="NUMBER", pushType="ALWAYS", value=0 } serviceDefinitions.GetSystemProperties( output { baseType="BOOLEAN", description="" }, description { "updates properties" } ) -- service input parameters -- me: table that refers to the Thing -- headers: table of HTTP headers -- query: query parameters from the HTTP request -- data: lua table containing the parameters to the service call. services.GetSystemProperties = function(me, headers, query, data) log.trace("[PiTemplate]","########### in GetSystemProperties#############") queryHardware() -- if properties are successfully updated, return HTTP 200 code with a true service return value return 200, true end function queryHardware() -- use the vcgencmd shell command to get raspberry pi system values and assign to variables -- measure_temp returns value in Celsius -- measure_clock arm returns value in Hertz -- measure_volts returns balue in Volts local tempCmd = io.popen("vcgencmd measure_temp") local freqCmd = io.popen("vcgencmd measure_clock arm") local voltCmd = io.popen("vcgencmd measure_volts core") -- set property temperature local s = tempCmd:read("*a") s = string.match(s,"temp=(%d+\.%d+)"); log.debug("[PiTemplate]",string.format("temp %.1f",s)) properties.cpu_temperature.value = s -- set property frequency s = freqCmd:read("*a") log.debug("[PiTemplate]",string.format("raw freq %s",s)) s = string.match(s,"frequency%(45%)=(%d+)"); s = s/1000000 log.debug("[PiTemplate]",string.format("scaled freq %d",s)) properties.cpu_freq.value = s -- set property volts s = voltCmd:read("*a") log.debug("[PiTemplate]",string.format("raw volts %s", s)) s = string.match(s,"volt=(%d+\.%d+)"); log.debug("[PiTemplate]",string.format("scaled volts %.1f", s)) properties.cpu_volt.value = s end tasks.refreshProperties = function(me) log.trace("[PiTemplate]","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In tasks.refreshProperties~~~~~~~~~~~~~ ") queryHardware() end
Thanks
Hello cssummers1,
I made some quick changes to the lua file.Try with the below config.lua
scripts.log_level = "DEBUG"
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate",
identifier = "PiThing",
scanrate = 1000,
taskrate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 8000
scripts.rap_ssl = false
scripts.rap_server_authenticate = false
scripts.script_resource_host = "127.0.0.1"
scripts.script_resource_port = 8001
scripts.script_resource_ssl = false
scripts.script_resource_authenticate = false
Changed the scripts.rap_port to 8000 - This should be the port on which EMS is running. Should be the same as the http_server port in config.json.
I have also added the identifier in the binding section.
Let me know if this helps.
It works - thanks for your help!
Charlotte
Hi Duane,
For TLS configuration the ws_connection encryption must be sent to SSL as below
"ws_connection": {
"encryption": "ssl",
"verbose": true,
"msg_timeout": 1000
}
You can find more information in EMS 5.3.4 Developer's Guide here
And I noticed that you have set gateway parameter to true. Does your PiThing implement the EMSGateway ThingTemplate?
Hi,
Thanks for the document. I have had a quick look at the wsems section and it looks similar to version 5.4. :-(
I have reset the gateway parameter to false and have turned ssl back on. I have been following the 'Connect Raspberry Pi to Thingworx' document instructions so I have not got to the part where the PiThing implements the EMSGateway ThingTemplate as the link to the Development Portal hosted server does not work yet. I have tried changing some of the parameters to see if that helped (hence the two items you noticed) but the connection does not work.
For the avoidance of doubt, I have reverted to the config.json file that is exactly as described in the documentation.
The new error log is shown below together with the config.json file.
Thanks again, your help is greatly appreciated!
pi@raspberrypi:~/microserver $ sudo ./wsems
[INFO ] 2018-04-11 15:24:40,259 ./wsems: Using config file: /home/pi/microserver/etc/config.json
[FORCE] 2018-04-11 15:24:40,259 ./wsems: Starting up ....
[FORCE] 2018-04-11 15:24:40,261 ./wsems: Initializing EMS ....
[FORCE] 2018-04-11 15:24:40,261 main: Using config file /home/pi/microserver/etc/config.json
[INFO ] 2018-04-11 15:24:40,261 ./wsems: Creating the WsEms proxy.
[INFO ] 2018-04-11 15:24:40,261 ./wsems: Starting HTTP Server.
[INFO ] 2018-04-11 15:24:40,262 ./wsems: Initializing the ThingWorx REST interface.
[FORCE] 2018-04-11 15:24:40,262 httpServer: starting http server port=8080
[DEBUG] 2018-04-11 15:24:40,262 httpServer: http server bound to port=8080.
[DEBUG] 2018-04-11 15:24:40,264 SDK: twWs_Create: Initializing Websocket Client for pp-1804041630us.devportal.ptc.io:443//Thingworx/WS
[DEBUG] 2018-04-11 15:24:40,265 SDK: twTlsClient_Create: Initializing TLS Client
[DEBUG] 2018-04-11 15:24:40,556 SDK: twApi_Initialize: Websocket Established after 0 tries
[DEBUG] 2018-04-11 15:24:40,557 SDK: subscribedPropsMgr_Initialize: Initializing subscribed properties manager
[DEBUG] 2018-04-11 15:24:40,557 jsonConfigurator::getJsonEntity: Key cert_chain not found
[DEBUG] 2018-04-11 15:24:40,557 jsonConfigurator::getJsonEntity: Key validation_criteria not found
[DEBUG] 2018-04-11 15:24:40,558 jsonConfigurator::getJsonEntity: Parent file not found
[DEBUG] 2018-04-11 15:24:40,559 SDK: twTunnelManager_Create: Tunnel Manager singleton already exists
[DEBUG] 2018-04-11 15:24:40,559 WsEmsProxy::bindThing: Host specified as 'localhost'. Testing IPV6/IPV4 connectivity
[WARN ] 2018-04-11 15:24:40,562 WsEmsProxy::bindThing: Exception connecting to localhost:8001. Err: Connection refused [localhost:8001]
[WARN ] 2018-04-11 15:24:40,562 WsEmsProxy::bindThing: Changing host from 'localhost' to '127.0.0.1'
[DEBUG] 2018-04-11 15:24:40,563 SDK: added PiThing to boundList
[DEBUG] 2018-04-11 15:24:40,563 SDK: twApi_BindThings: not currently connected, only binding things to api
[DEBUG] 2018-04-11 15:24:40,563 SDK: twMessage_Delete: Deleting BIND Message: 1
[DEBUG] 2018-04-11 15:24:40,563 jsonConfigurator::getJsonEntity: Parent file not found
[INFO ] 2018-04-11 15:24:40,563 wsEmsProxy::initialize: Initialization complete!
[INFO ] 2018-04-11 15:24:40,566 ./wsems: Starting the connection.
pp-1804041630us.devportal.ptc.io:443-->[DEBUG] 2018-04-11 15:24:40,568 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2018-04-11 15:24:40,595 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-11 15:24:40,667 SDK: Error intializing SSL connection
[ERROR] 2018-04-11 15:24:40,667 SDK: twWs_Connect: Error restarting socket. Error 0
[DEBUG] 2018-04-11 15:24:45,667 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2018-04-11 15:24:45,694 SDK: twTlsClient_Connect: Connecting to server
[ERROR] 2018-04-11 15:24:45,766 SDK: Error intializing SSL connection
[ERROR] 2018-04-11 15:24:45,766 SDK: twWs_Connect: Error restarting socket. Error 0
{
"ws_servers": [{
"host": "pp-1804041630us.devportal.ptc.io",
"port": 443
}],
"appKey": "c323961f-8169-4add-ae5a-f50dfdba0c61",
"http_server" : {
"host" : "127.0.0.1",
"port" : 8080
},
"logger" : {
"level" : "DEBUG"
},
"auto_bind" : [{
"name" : "PiThing",
"gateway" : false
}],
"certificates" : {
"validate" : false,
"allow_self_signed" : true
},
"ws_connection" : {
"encryption" : "ssl",
"verbose" : true,
"msg_timeout" : 1000
}
}