Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Connect a Raspberry Pi to ThingWorx using the Edge Micro Server (EMS).
This project will introduce you to the Edge MicroServer (EMS) and how to connect your ThingWorx server to a Raspberry Pi device.
Following the steps in this guide, you will be able to connect to the ThingWorx platform with your Raspberry Pi. The coding will be simple and the steps will be very straight forward.
We will teach you how to utilize the EMS for your Edge device needs. The EMS comes with the Lua Script Resource, which serves as an optional process manager, enabling you to create Properties, Services, Events, and Subscriptions for a remote device on the ThingWorx platform.
NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete ALL parts of this guide is 30 minutes.
unzip /MED-61060-CD-054_SP9_Microserver-Linux-arm-hwfpu-openssl-5-4-10-1509.zip
After unzipping the distribution, a sub-directory named /microserver will be created inside the parent directory.
Switch into the microserver directory with the command cd microserver The microserver directory includes the following files.
File Name Description
wsems | An executable file that runs the Edge MicroServer |
luaScriptResource | The Lua utility that is used to run Lua scripts, configure remote things, and integrate with the host system |
In this step, you will be using the ThingWorx Composer to generate an Application Key. The Application Key will be used to identify the Edge Agent. The Application Key is tied to a user and has the same entitlements on the server.
Using the Application Key for the default User (Administrator) is not recommended. If administrative access is absolutely necessary, create a User and place the user as a member of the SecurityAdministrators and Administrators User Groups.
Create the User the Application Key will be assigned to.
On the Home screen of Composer click + New.
In the dropdown list, click Applications Key.
Set the User Name Reference to a User you created.
The EMS consists of two distinct components that do slightly different things and communicate with each other. The first is the EMS which creates an AlwaysOn™ connection to the ThingWorx server. It binds things to the platform and automatically provides features like file transfer and tunneling.
The second is the Lua Script Resource (LSR). It is used as a scripting language so that you can add properties, services, and events to the things that you create in the EMS. The LSR communicates with your sensors or devices. The LSR can be installed on the same device as the EMS or on a separate device. For example, one LSR can be a gateway and send data from several different things to a single EMS.
cd microserver/etc
sudo nano config.json
Edit the config.json file
{"host":"<TwX Server IP>", "port":443}
{"host":"127.0.0.1","port":8080, "use_default_certificate": true,"ssl": false, "authenticate": false}
"appKey":"<insert keyId>"
("level":"INFO"}
{"validate":false, "disable_hostname_validation": true}
NOTE: To ensure a secure connection, use valid certificates, encryption and HTTPS (port : 443) protocol for establishing a websocket connection between the EMS and the ThingWorx Platform.
5. Exit and Save.
ctrl x
Replace host and appKey with values from your hosted server.
{ "ws_servers": [{ "host": "pp-2007011431nt.devportal.ptc.io", "port": 443 }], "appkey": "2d4e9440-3e51-452f-a057-b55d45289264", "http_server": { "host": "127.0.0.1", "port": 8080, "use_default_certificate": true, "ssl": false, "authenticate": false }, "logger": { "level": "INFO" }, "certificates": { "validate": false, "disable_hostname_validation": true } }
Click here to view Part 2 of this guide.
It is possible to connect the raspberry with a Thingworx in the cloud. In my application I cannot discover the Thingworx IP because it is in the cloud provided by PTC.
Translated by the Community Moderation using Google Translate
É possivel fazer a conexão do raspberry com um thing worx em cloud. Em minha aplicação não consigo descobrir o IP do ThingWorx pois é em cloud fornecido pela PTC