Global Command Scripts
Global scripted commands allow execution directly in a HumanOS(R) instance, without a device. In this tutorial we will use the built in REST API Server to execute the command.
Step 1: Prepare the IoT Gateway
-
Select the
Plugins
node in the project view and click [+] button. -
Add the REST API Server to the project.
Step 2: Add the object schema
-
Select the
Datamodel
->Objects
node in the project view and click [+] button. -
Add a blank schema.
-
Open the configuration of the schema - double click on the
Blank_Schema.json
node.Add following content to the file:
{
"Id": "B960149D-CB38-4319-BEC9-CA0FC2E3A4FD",
"Name": "GlobalCommandsGroup1",
"Commands": [
{
"Id": "3991FB86-620A-4400-B117-30AA83686473",
"Name": "ExecuteCommand1",
"Type": "CSharpScriptCommandNode",
"Arguments": [
{
"Name": "Arg1",
"Type": "Input",
"DataType": "System.String"
}
],
"Properties": [
{
"Name": "ScriptFileName",
"Value": "Command1.cs"
}
]
}
]
}This tells the system that there is a scripted command and how it is callable and which arguments it has. Now we have add the script.
Step 3: Add the script
-
Click on
Scripts
->Commands
and add the payload script namedCommand1.cs
.Add following content on any line before the
return
Keyword:Logger.writeInfo($"Hello from global command, received '{dicInputArguments["Arg1"]}' as input data.");
Step 4: Deploy and Test
-
Deploy and run HumanOS IoT Gateway
-
Start a REST capable Client like Postman. Enter the URL and the body data:
The Id is visible in the json data at Add the object schema.
Execute URL:
POST localhost:8081/nodes/command?id=3991FB86-620A-4400-B117-30AA83686473
<HumanOS.Stream>
<Command>
<Argument name="Arg1" datatype="System.String">hello</Argument>
</Command>
</HumanOS.Stream> -
Check the response
It should contain a
Good
statuscode.<HumanOS.Stream>
<Command>
<ReturnCode>Good</ReturnCode>
<Exception></Exception>
</Command>
</HumanOS.Stream> -
Check the action output
Switch to the HumanOS IoT Gateway Console Application Window. There should be a log entry displaying your text, in our case its
ExecuteCommand1: Hello from global command, received 'hello' as input data.
.