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

ERROR Connecting WS EMS on Raspberry Pi

SOLVED
Highlighted
Visitor

ERROR Connecting WS EMS on Raspberry Pi

Hi, I have problems when executing wsems, any help will be appreciated.

my config.json file is below

{
"ws_servers": [{ "host": "192.168.1.241", "port": 443 }], "http_server": { "host": "127.0.0.1", "port": 8080,
"ssl": false,
"authenticate": false }, "appKey": "96d6b33a-33c7-41c9-bda2-53416afa9876", "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 } }

 

this is the error i received

[FORCE] 2019-01-10 13:35:19,976 ./wsems: Initializing EMS ....
[FORCE] 2019-01-10 13:35:19,976 main: Using config file /home/pi/microserver/etc/config.json
[INFO ] 2019-01-10 13:35:19,976 ./wsems: Creating the WsEms proxy.
[INFO ] 2019-01-10 13:35:19,977 ./wsems: Starting HTTP Server.
[INFO ] 2019-01-10 13:35:19,977 Main: Using custom certificate and private key for HTTP Server
[WARN ] 2019-01-10 13:35:19,977 Main: Encryption is disabled on HTTP Server.
[WARN ] 2019-01-10 13:35:19,977 Main: Authentication is disabled on the HTTP Server.
[FORCE] 2019-01-10 13:35:19,977 httpServer: starting http server port=8080
[INFO ] 2019-01-10 13:35:19,977 ./wsems: Initializing the ThingWorx REST interface.
[INFO ] 2019-01-10 13:35:19,978 wsEmsProxy::initialize: FIPS is disabled.
[DEBUG] 2019-01-10 13:35:19,978 httpServer: http server bound to port=8080.
[INFO ] 2019-01-10 13:35:19,978 wsEmsProxy::initialize: Encryption is enabled on Web Socket connection.
[WARN ] 2019-01-10 13:35:19,979 SDK: SDK Version: 2.0.4
[WARN ] 2019-01-10 13:35:19,980 SDK: TLS Library: OpenSSL
[WARN ] 2019-01-10 13:35:19,980 SDK: TLS Library Version: 1.0.2l
[WARN ] 2019-01-10 13:35:19,980 SDK: FIPS Capable
[DEBUG] 2019-01-10 13:35:19,980 SDK: twWs_Create: Initializing Websocket Client for 192.168.1.241:443//Thingworx/WS
[DEBUG] 2019-01-10 13:35:19,980 SDK: twTlsClient_Create: Initializing TLS Client
[DEBUG] 2019-01-10 13:35:19,995 SDK: twApi_Initialize: Websocket Established after 0 tries
[DEBUG] 2019-01-10 13:35:19,995 SDK: subscribedPropsMgr_Initialize: Initializing subscribed properties manager
[INFO ] 2019-01-10 13:35:19,995 WsProxy::initialize: EMS Version 5.4.0.114
[INFO ] 2019-01-10 13:35:19,995 WsProxy::initialize: twApi singleton initialized
[WARN ] 2019-01-10 13:35:19,995 WsProxy::initialize: Certificate validation is disabled.
[WARN ] 2019-01-10 13:35:19,995 WsProxy::initialize: Self signed certificates are enabled.
[DEBUG] 2019-01-10 13:35:19,995 jsonConfigurator::getJsonEntity: Key validation_criteria not found
[DEBUG] 2019-01-10 13:35:19,996 jsonConfigurator::getJsonEntity: Parent file not found
[DEBUG] 2019-01-10 13:35:19,997 SDK: twTunnelManager_Create: Tunnel Manager singleton already exists
[ERROR] 2019-01-10 13:35:19,997 SDK: twMap_Add: parse function returned null.
[DEBUG] 2019-01-10 13:35:19,997 WsEmsProxy::bindThing: Host specified as 'localhost'. Testing IPV6/IPV4 connectivity
[WARN ] 2019-01-10 13:35:20,0 WsEmsProxy::bindThing: Exception connecting to localhost:8001. Err: Connection refused [localhost:8001]
[WARN ] 2019-01-10 13:35:20,1 WsEmsProxy::bindThing: Changing host from 'localhost' to '127.0.0.1'
[DEBUG] 2019-01-10 13:35:20,1 SDK: added PiThing to boundList
[DEBUG] 2019-01-10 13:35:20,1 SDK: twApi_BindThings: not currently connected, only binding things to api
[DEBUG] 2019-01-10 13:35:20,1 SDK: twMessage_Delete: Deleting BIND Message: 1
[DEBUG] 2019-01-10 13:35:20,1 jsonConfigurator::getJsonEntity: Parent file not found
[INFO ] 2019-01-10 13:35:20,1 wsEmsProxy::initialize: Initialization complete!
[INFO ] 2019-01-10 13:35:20,3 ./wsems: Starting the connection.

192.168.1.241:443-->[DEBUG] 2019-01-10 13:35:20,6 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2019-01-10 13:35:20,6 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2019-01-10 13:35:20,50 SDK: twTlsClient_Connect: TLS connection established
[ERROR] 2019-01-10 13:35:20,57 SDK: twWs_Connect: Error initializing web socket. Response code: 404
[DEBUG] 2019-01-10 13:35:25,57 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2019-01-10 13:35:25,58 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2019-01-10 13:35:25,143 SDK: twTlsClient_Connect: TLS connection established
[ERROR] 2019-01-10 13:35:25,157 SDK: twWs_Connect: Error initializing web socket. Response code: 404
[DEBUG] 2019-01-10 13:35:30,158 SDK: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2019-01-10 13:35:30,158 SDK: twTlsClient_Connect: Connecting to server
[DEBUG] 2019-01-10 13:35:30,242 SDK: twTlsClient_Connect: TLS connection established
[ERROR] 2019-01-10 13:35:30,256 SDK: twWs_Connect: Error initializing web socket. Response code: 404

1 ACCEPTED SOLUTION

Accepted Solutions

Re: ERROR Connecting WS EMS on Raspberry Pi

All the files are available here:

https://developer.thingworx.com/en/resources/guides/thingworx-raspberry-pi-quickstart

 

And are also duplicated below.

 

The config.lua file references the PiTemplate.lua file which contains hardware specific code that will only work on a Raspberry Pi. To get this to work on other hardware, you would need to modify the queryHardware() function to work with whatever device you are using

 

config.json

{ 
	"ws_servers":	[{
				"host":	"pp-19022819274p.portal.ptc.io",
				"port":	443
		}],
	"appKey":	"8918cf96-xxxx-xxxx-801f-ac6cdb450279",
	"http_server" : {
		"host": "127.0.0.1",
		"port": 8080,
		"use_default_certificate" : true,
		"ssl" : false,
		"authenticate" : false
		},
	"logger":{
		"level":"INFO"
	},


	"certificates":{
		"validate": false
	}
}

 

 

config.lua

scripts.log_level = "INFO"
scripts.script_resource_ssl = false
scripts.script_resource_authenticate = false
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate",
scanRate = 1000,
taskRate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 8080

 

PiTemplate.lua

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" }
)

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

 

7 REPLIES 7

Re: ERROR Connecting WS EMS on Raspberry Pi

Couple of things to check -

1.) Check the validity of the Application Key - if expiration is a future date

2.) Check is the user associated with the Application key is the default 'Administrator' user

 

 

Re: ERROR Connecting WS EMS on Raspberry Pi

changed the user to Administrator , still did not work though.

Re: ERROR Connecting WS EMS on Raspberry Pi

Hi @dw22.

 

After making the change, are you still getting the same error?

 

Regards.

 

--Sharon

Re: ERROR Connecting WS EMS on Raspberry Pi

The Raspberry Pi guide was updated with instructions for connecting to ThingWorx 8.4, the latest Raspberry Pi Operating System (Raspbian Stretch), and the latest EMS:

 

https://developer.thingworx.com/en/resources/guides/thingworx-raspberry-pi-quickstart

 

Please give this updated guide a try

Re: ERROR Connecting WS EMS on Raspberry Pi

Can you share the config.lua file too?

Re: ERROR Connecting WS EMS on Raspberry Pi

All the files are available here:

https://developer.thingworx.com/en/resources/guides/thingworx-raspberry-pi-quickstart

 

And are also duplicated below.

 

The config.lua file references the PiTemplate.lua file which contains hardware specific code that will only work on a Raspberry Pi. To get this to work on other hardware, you would need to modify the queryHardware() function to work with whatever device you are using

 

config.json

{ 
	"ws_servers":	[{
				"host":	"pp-19022819274p.portal.ptc.io",
				"port":	443
		}],
	"appKey":	"8918cf96-xxxx-xxxx-801f-ac6cdb450279",
	"http_server" : {
		"host": "127.0.0.1",
		"port": 8080,
		"use_default_certificate" : true,
		"ssl" : false,
		"authenticate" : false
		},
	"logger":{
		"level":"INFO"
	},


	"certificates":{
		"validate": false
	}
}

 

 

config.lua

scripts.log_level = "INFO"
scripts.script_resource_ssl = false
scripts.script_resource_authenticate = false
scripts.PiThing = {
file = "thing.lua",
template = "PiTemplate",
scanRate = 1000,
taskRate = 30000
}
scripts.rap_host = "127.0.0.1"
scripts.rap_port = 8080

 

PiTemplate.lua

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" }
)

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

 

Re: ERROR Connecting WS EMS on Raspberry Pi

Hi @dw22.

 

If one of the previous responses answered your question, please mark the appropriate one as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon