Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
1. Navigate to the microserver directory.
cd ..
2. Ensure that you have ownership to the executable wsems and executable privileges. To check ownership.
Ls -la -rwxrwxr-x 1 pi pi 769058 Jun 9 17:46 wsems
NOTE: The account that owns the wsems executable should be used to log into the Raspberry Pi.
3. Confirm that you have executable privileges by run the following command:
sudo chmod 775 wsems
4. Run the EMS.
sudo ./wsems
5. Validate that your EMS successfully connected.
[INFO ] 2016-10-11 14:22:54,770 Main: Succesfully connected. Saving .booted config file
If the websocket does not connect successfully, check the following:
Issue Solution
WEBSOCKET CLOSED - Warning seen immediately after Websocket gets connected. | Ensure that the host IP address, port and appKey of the ThingWorx composer instance are accurately set. If in the config.json you have selected the option to validate certification, then make sure the path to the certificate file is correctly set. |
twWs_Connect - Error trying to connect. | Ensure that the host IP address, port running the ThingWorx Composer is accurately set. Check if the certification parameter is set or not. By default the WS EMS validates certificates. To ensure that the validation is performed correctly without errors, ensure that the certificates configuration parameters are set accurately with the correct path to the certificate file. If you do not wish to validate the certificate, you may explicitly set the validate parameter in certificates parameter set to false. |
twTlsClient_Connect - Error intializing TLS connection. Invalid certificate. | Check if the ws_encryption parameter is present in your config.json file. By default, WS EMS enables TLS connection to ThingWorx platform. Ensure that the certificate file mentioned in the config.json is valid and stored in the path specified in the config.json. For debugging purposes, you can set the ssl parameter to none in ws_encryption configuration parameter. |
[WARN ] ... Main - Unable to connect to server. Trying .booted config file. | Ensure that the host is up and running at the IP address and port number mentioned in the config.json file. Ensure that ThingWorx is running on the host address at the correct port number. Ensure that all appropriate networking ports are open and available. |
The Lua Script Resource (LSR) is used to implement Things on the Edge device. Using the Lua Script Resource, you can define for your Raspberry Pi:
NOTE: The steps in this guide install the LSR on the same server (Raspberry Pi) as the EMS but it could also be installed on another server.
cd microserver/etc
sudo nano config.lua
scripts.log_level = "INFO"
Turn off encryption for connection to EMS. This should only be used for testing.
scripts.script_resource_ssl = false scripts.script_resource_authenticate = false
Create the Edge RemoteThing.
scripts.PiThing = { file = "thing.lua", template = "PiTemplate", scanRate = 1000, taskRate = 30000 }
NOTE: This configuration tells the Lua Script Resource to create a Thing called PiThing whose template definition is in PiTemplate.lua file in the path etc/customs/templates/PiTemplate.lua. You will create the template file PiTemplate.lua in the next section.
scanRate | Controls how frequently (milliseconds) properties are evaluated and pushed to the server. In our example, the Pi will check every 1 second if the values have changed. If so, the values will be pushed to the server. |
taskRate | Controls how frequently the tasks specified in the Thing's template should be executed. In our example, the task will run every 30 seconds. |
7. Set the IP and port address of the LSR host server.
scripts.rap_host = "127.0.0.1" scripts.rap_port = 8080
Here is an example of a complete config.lua that can be used to configure the Lua Script Resource.
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
The template file is located in the microserver/etc/custom/templates directory. The template file provides a base configuration for defining Properties, Services, tasks, etc. This section will focus on defining the template file and adding Properties.
cd microserver/etc/custom/templates
sudo nano PiTemplate.lua
NOTE: This is the same template filename used in config.lua in the previous section.
3. Define the template.
module ("templates.PiTemplate", thingworx.template.extend)
Parameter Description
templates.PiTemplate | refers to the name of the template file: PiTemplate.lua |
thingworx.template.extend | identifies the file as a template and provides base Thingworx template implementation |
4. Define the Properties.
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}
NOTE: This code defines the properties cpu_temperature, cpu_freq and cpu_volt with a baseType of NUMBER. Additionally, it sets each default value to null as well as sets the pushType to ALWAYS which means that the property is always pushed to the Thingworx Server from the Raspberry Pi. The pushType can be set to ALWAYS, ON, OFF, NEVER or VALUE.
Here is an example of a complete PiTemplate.lua that can be used to configure the Lua Script Resource.
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}
Click here to view Part 3 of this guide.