Official | HULFT IoT EdgeStreaming Reverse Reference First Edition: July 1, 2021
Transfer collected file data using HTTP
This section describes the processing that reads the data within a file collected from an external source and transfers it using HTTP.
This process outputs results such as the following:
- Example
-
The content of a CSV file is read and transferred using HTTP.
Description of the processing
A CSV file stored in the IoT gateway is read whenever a line is added and the read data is transferred to an external system using HTTP.
Key features
- Monitoring of File Update
-
This component can be used to set the properties of the monitoring file updates operation.
It can be set from File > CSV > Monitoring of File Update of the tool palette.
- Send operation
-
This component can be used to set the properties of the Send operation.
It can be set from Generic protocol > HTTP > Send of the tool palette.
Operation procedure
This section explains the procedure using an example scenario created based on the assumption that the following CSV file is read.
A script that reads a CSV file stored in the IoT gateway whenever a line is added and transfers the data to an external system using HTTP is created.
The CSV file is assumed to be output by a CSV file-outputting device (such as a PLC with an FTP client function).
-
CSV data:
Temperature, Humidity
22.5, 31.8 23.0, 32.0 23.1, 31.9 23.2, 31.1 23.1, 31.4 |
1. Place an operation that reads the data of lines added to a CSV file.
-
Drag and drop File > CSV > Monitoring of File Update from the tool palette onto the script canvas.
The New Monitoring of File Update operation dialog box is displayed.
-
Configure the settings to read the values from the CSV file.
Name
Enter any value (single-byte alphanumeric characters, underscores).
[Required settings] tab
File name
Specify the file name of the CSV file.
Skip already written lines when runtime starts up
There is no need to select this check box.
For this example, it is assumed that the CSV file is generated upon script execution.
Column List
Add all the columns in the CSV file to Column Name.
For Column Name, enter any value that represents the column.
= Remarks =-
Column Name is only used for display on the screen.
-
To retrieve Column Name from the first line of the CSV file, click Read column names from first line of file, and select the file.
[Advanced settings] tab
Delimiter
Select Comma.
Encode of file reading
Select UTF-8.
-
-
Click Finish.
The monitoring file updates operation icon is placed on the script canvas.
2. Place an operation that externally transfers data using HTTP.
-
Drag and drop Generic protocol > HTTP > Send from the tool palette onto the script canvas.
The New Send operation dialog box is displayed.
-
Configure the settings of the REST API of the external system.
Name
Enter any value (single-byte alphanumeric characters, underscores).
Input data
Select the "icon name of the Monitoring operation" that you placed earlier.
URL
Set the "URL" for REST API.
Method
Set the HTTP method (POST or PUT) for REST API.
Header
Set the request header that is necessary to send a request to REST API.
-
Click Finish.
The Send operation icon is placed on the script canvas.
The Monitoring operation icon and the Send operation icon are connected by a stream flow (an orange dashed line).
3. Configure a Mapper.
-
Right-click the stream flow that connects the Monitoring operation to the Send operation and select Add mapping from the menu.
Mapper is placed in between the Monitoring operation and the Send operation.
-
Double-click the mapping_1 icon to open the Mapper editor.
-
In Output destination, set the input schema of the Send operation.
When the JSON format set for the request body is designated as a REST API specification, you can save that format as a JSON file and use it to generate input schemas.
= Remarks =You can also configure the schema settings manually, but when the JSON format is complicated, letting the schema be read from a JSON file makes operations simpler.
For details on how to manually configure the schema settings, refer to First Step Guide.
Right-click the name of the Send operation icon and select Load schema from the menu.
The Load schema dialog box appears.
Select Read from JSON file.
Specify the JSON file in File path and click Finish.
A tree similar to the following is generated according to the content of the specified JSON file.
4. Drag and drop the following items from the input source onto the output destination:
-
column_0 of Input source to temperature of Output destination
-
column_1 of Input source to humidity of Output destination
5. Save the script.
For information about how to save a script, refer to First Step Guide.
Official | HULFT IoT EdgeStreaming Reverse Reference First Edition: July 1, 2021