EMS.ThingPoint ThingConnect IoT Sample
Contents
This sample is a server-client ThingPoint Overview application demo.
This sample demonstrates how to use a ThingPoint application to extend the RAD Server Engine (EMS Server), how to connect to and receive data from a ThingConnect device and how this data is consumed by a EMS Client application.
Requirements
In order to run this demo, you have to meet the following requirements:
- You have InterBase installed on the machine or are connected to an EMS remote server. Make sure that the RAD Server Engine (EMS Server) is running before you run the sample.
- You have the Generic Heart Rate Monitor IoT component installed and you have an actual heart rate monitor device.
- Your target OS is one of the following:
- Windows 8 or newer.
- OS X.
- Note: This is required because of BLE support.
Location
You can find the ThingPoint sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to either:
Object Pascal\Multi-Device Samples\EMS\ThingPoint ThingConnect IoT Demo
CPP\Multi-Device Samples\EMS\ThingPoint ThingConnect IoT Demo
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
The demo application creates a ThingPoint application that receives data from a ThingConnect device, caches the data, and responds to remote requests for data from the RAD Server Engine (EMS Server).
The EMS Resource project is loaded to the RAD Server Engine (EMS Server). The new ResourceName is Measurements
.
Once you run the package, the resource is registered on the RAD Server Engine (EMS Server) and can be accessed by a client application using REST.
There are two client applications in the sample. The client applications need a TEMSProvider to connect to the EMS Server and to retrieve the JSON data.
- The client project requests data to the EMS Resource from the RAD Server Engine (EMS Server) and the data from the particular EMS EdgeModule.
- The mobile client application requests data from the particular EMS EdgeModule.
How to Use the Sample
Running the Sample Projects
The EMS Custom Package Project
When you run the CustomResourcePackage project, the EMS Development Server starts automatically. If the configuration file is missing, a wizard launches.
- Navigate to the location given above and open:
- Delphi:
CustomResource\
CustomResourcePackage.dpk
- Delphi:
- Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
- The EMS Development Server opens. If it is the first time you are using EMS on the machine, you need to run the configuration wizard in order to create the EMS server configuration file.
- When the Confirm dialog opens, click Yes.
- Leave all the parameters by default and go through the different windows by clicking Next.
- Click Finish to close the wizard.
- An Information window appears. Click OK.
- The server starts automatically and registers the custom resource in CustomResourcePackage.bpl.
{"RegResource":{"Resource":"Measurements","Endpoints":["Get"],"Thread":4376}} {"Loaded":{"Filename":"C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl\CustomResourcePackage.bpl","Thread":4376}}
The ThingPoint Application Project
The ThingPoint application receives data from a heart rate monitor and simulates blood pressure measurement.
- On the Project Manager, right-click on ProjectGroup1.
- Click Add Existing Project...
- Navigate to the location given above and open:
- Delphi:
Thing Point\
ThingPointProject.dproj - C++:
Thing Point\
ThingPointProjectCpp.cbproj
- Delphi:
- Run without debugging. Choose Run > Run Without Debugging.
- Test the connection to the RAD Server Engine (EMS Server). In the Connection to EMS Server options, click the Test button with the default parameters (if your server is running at localhost:8080).
- Enter the configuration parameters of the EdgeModule:
- Enter a name for the EdgeModule:
MeasurementsThingPoint
- Enter the IP address where it runs:
localhost
- Enter the connection port:
8081
- Enter a name for the EdgeModule:
- Activate the EdgeModule. To do so, click the Activate Edge Module option.
- Test if the ThingPoint is properly registered in the EMS Server.
- Click the Test button.
- If the connection is OK, a dialog box shows the EdgeModule version and name.
{"Request":{"Resource":"Edgemodules","Endpoint":"GetResourceEndpoint","Method":"GET","User":"(blank)","Time":"10/1/2015 9:45:09 AM","Thread":4444}}
- Connect to the heart rate monitor device:
- Enter the name of your device into the Edit box (next to the Connect button). You can get the name from the
Windows Bluetooth Devices Manager
. - Click on Connect button to connect with the device.
- Note: You need to pair with the device before connecting.
- Click on Start button to start receiving heart rate measurement.
[10:26:170] {"bpm":69} [10:25:668] {"bpm":69} [10:25:167] {"bpm":68} [10:24:668] {"bpm":70}
- Enter the name of your device into the Edit box (next to the Connect button). You can get the name from the
- Generate the simulated blood pressure measurement data for the demo. To do so:
- Select the Blood Pressure tab.
- Click the Notify button every time you want to send a new measurement.
[10:10:886] {"systolic":115,"diastolic":77} [10:08:695] {"systolic":118,"diastolic":77}
Running the Client Applications
The client applications expect the EMS Development server to be running at localhost:8080. If you are running the server at a different address, modify the properties of the TEMSProvider component.
- On the Project Manager, right-click on ProjectGroup1.
- Click Add Existing Project....
- Navigate to the location given above and open:
- ClientProject:
- Delphi:
\Client\DesktopClient\
ClientProject.dproj.
- Delphi:
- MobileClientProject:
- Delphi:
\Client\MobileClient\
MobileClientProject.dproj.
- Delphi:
- ClientProject:
- Press F9 or choose Run > Run.
- Select the Edge Request tab to retrieve all the EdgeModule names that are registered in the EMS Server. This populates the combo-box.
- Select an EMS EdgeModule from the combo-box.
- Click the Execute button to retrieve the most recent data from the selected EdgeModule.
- Select the Custom Resource Request tab.
- Click the Execute button to retrieve the most recent data from all ThingPoints.
- Note: This request fails if the CustomResourcePackage.bpl is not registered in the EMSDevServer.
- Check Auto Refresh to continuously execute requests to the EMS Server.
Uses
- REST.Backend.EMSProvider.TEMSProvider
- EMSHosting.EdgeService.TEMSEdgeService