Intro 2: Setting Up IO for REST
Intro 2: Setting Up IO for REST
CDP Studio allows you to connect to hardware/automation I/O or external services using IOServers, to build systems by connecting components and to use mathematical functions, and all this can be done without any coding. How we use the configuration is a key concept that is important to understand. This example shows:
- What is possible to do with the configuration
- How to connect and configure/build a system
- How to connect external information or physical IO to a CDP project using IOServers
- Add pre-made mathematical functions
Recommended: See first Intro 1: Connect Variables to HMI GUI. The project files are found in the Examples
section in Welcome mode.
This example is the second in the series of Intro to CDP Studio.
Step-by-step Guide How the Example Was Made
There is a detailed step-by-step guide showing how the example was made, see Intro 2: Tutorial of Using REST IO.
Project Overview
The project connects to OpenStreetMap to get the coordinates of Oslo, the capital of Norway. It then connects to an internet weather service using the coordinates to collect the weather information. Fahrenheit is calculated from the Celsius temperature using operators. The temperatures are shown in a simple GUI.
The example uses REST as no physical hardware is required and will therefore work for all users. The same principle applies to industrial protocols such as MQTT, MODBUS, CANopen etc. In this example, an ExternalControlBroker (a pre-made IOServer, see also Definitions) has been added to the WeatherDataApp from the Resources section in Configure mode.
The temperature in Celsius is shown on the meter (Meter widget), in Fahrenheit in the bar (bar widget) and “Fahrenheit” is written using the text label widget.
How to Run the Example
To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information.
Project Description
Some concepts are important to understand when developing with CDP Studio. Below is useful information related to this example.
The process to create a CDP system is:
- Select the pre-made or existing resources/function blocks (items that exist in the Resources section in Configure mode)
- Develop any missing resources/function blocks
- Design the GUI
- Create the system by connecting the resources/function blocks together and to the GUI
This example covers steps 1,3 and 4. The development of resources/function blocks/components is covered in the Intro 3 where libraries are introduced.
The development process shown above may differ from other tools. An important concept to understand is that CDP systems are created by connecting available components/function blocks/GUI together and by adding mathematical functions (operators). This is done without any coding. Coding is only done when developing new function blocks or mathematical functions.
When you have the required reusable components created, you may create advanced and comprehensive systems without any (or only a small amount) of coding.
In this example, only existing components and operators are used. The system is built ('configured' in CDP terminology) by routing (connecting) the blocks together and then route these to the GUI.
There are several premade mathematical functions, called operators, available. These range from simple 'add'-functions to Kalman filters and PID regulators.
The temperature fetched from the weather service is in Celsius. The Fahrenheit temperature is calculated by the formula F=C*1.8+32
and implemented using a Mul and an Add operator placed inside the CtoFconverter operator container block. This is done to make the example easier to understand. The Add and Mul operators could have been placed on the top level.
Additional Information On REST Requests And Extracting Information
The GetOsloPosition sends an HTTP request to the OpenStreetMap Nominatim Geocoding Service and the CityInformation contains the complete response in a string (JSON format). The JSONQuery function is used to extract the latitude and longitude.
The weather data is collected from Norwegian Meteorological Institute. The GetPositionWeather fetches the weather forecast at the location specified by the longitude and latitude. To get the forecast, you need to add the latitude and longitude to the HTTP request. This is done by adding Request Channels to the WeatherQuery block (inside GetPositionWeather). In the URL, the first request channel is referred to as "%1%", the second as "%2%" etc.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.