EMS.ThingPoint IoT Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample is a server-client ThingPoint Overview application demo.

This sample demonstrates how to use a ThingPoint application to extend the EMS Server and how these data is consumed by a EMS Client application.

It requires InterBase to be installed on the machine or to connect to the EMS remote server. Make sure that the EMS Server is running before you run the sample.

Location

You can find the ThingPoint sample project at:

Description

The demo application creates a ThingPoint application that simulates data generated from a ThingConnect device, caches its data, and responds to remote requests for data from the EMS Server.

The EMS Resource project is loaded to the EMS Server. The new ResourceName is Measurements. Once you run the package, the resource is registered on the 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.

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.

  1. Navigate to the location given above and open:
    • Delphi: CustomResource\CustomResourcePackage.dpk
  2. Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
  3. 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.
    1. When the Confirm dialog opens, click Yes.
    2. Leave all the parameters by default and go through the different windows by clicking Next.
    3. Click Finish to close the wizard.
    4. An Information window appears. Click OK.
  4. 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 simulates two different types of measurements: heart rate measurements and blood pressure.

  1. On the Project Manager, right-click on ProjectGroup1.
  2. Click Add Existing Project....
  3. Navigate to the location given above and open:
    • Delphi: Thing Point\ThingPointProject.dproj
    • C++: Thing Point\ThingPointProjectCpp.cbproj
  4. Run without debbuging. Choose Run > Run Without Debugging.
  5. Test the connection to the 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).
  6. 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
  7. Activate the EdgeModule. To do so, click the Activate Edge Module option.
  8. 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}}
    
  9. Generate the simulated heart rate measurement data for the demo. To do so:
    • Select the Heart Rate tab.
    • Click the Start button.
     [10:26:170] {"bpm":69}
     [10:25:668] {"bpm":69}
     [10:25:167] {"bpm":68}
     [10:24:668] {"bpm":70}
    
  10. 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.

  1. On the Project Manager, right-click on ProjectGroup1.
  2. Click Add Existing Project....
  3. Navigate to the location given above and open:
    • ClientProject:
      • Delphi: \Client\DesktopClient\ClientProject.dproj.
    • MobileClientProject:
      • Delphi: \Client\MobileClient\MobileClientProject.dproj.
  4. Press F9 or choose Run > Run.
  5. Select the Edge Request tab to retrieve all the EdgeModule names that are registered in the EMS Server. This populates the combo-box.
  6. Select an EMS EdgeModule from the combo-box.
  7. Click the Execute button to retrieve the most recent data from the selected EdgeModule.
  8. Select the Custom Resource Request tab.
  9. 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.
  10. Check Auto Refresh to continuously execute requests to the EMS Server.

Uses

See Also