The following steps are required to get the Virtual RTU working in debug mode on your local machine.
-
Create Azure resources
-
Deploy Piraeus in AKS
-
Configure VRTU projects
-
Deploy a new device using a PS script
-
Auto-configure the IoT Edge device
-
Run the solution end-2-end in debug mode
You will need to update your local machine with the latest tooling. You will need to install these prereqs as well as the following:
-
Visual Studio 2019 v16.3.10
-
- Note: We need to also install the preview version to leverage dotnet core v3.0.1 with Azure Functions and their dependencies.
-
Clone the source http://github.com/skunklab/piraeus onto your local machine.
-
Following the instructions in the ReadMe.md (here) to create the deployment and configuration file. The deployment should take between 15-20 minutes to complete.
-
The resulting deployment will create a configuration file in the “kubernetes” folder in the form “dd-mm-yyyyThh-mm-ss.json”. We will use this file in the next step.
-
Clone the VRTU source https://github.com/skunklab/virtualrtu
-
Open a new command prompt and navigate to the “Kubernetes” folder on the virtual rtu source.
-
Type “pwsh” to start PowerShell
-
Type “. ./New-VrtuConfigFile.ps1” to load PowerShell command to create a configuration file.
-
Type New-VrtuConfigFile with the following parameters to create the “vrtu-config.json” file.
-Dns | Dns name for the vrtu, e.g., “growlingdog7” |
---|---|
-VirtualRtuId | Lowercase name of the VRTU. Use “testvrtu” for the sample. |
-ClusterName | The AKS cluster name for the vrtu. If omitted “vrtucluster” is used. |
-StorageAcctName | Name of a new Azure Storage Account used by the VRTU. |
-IoTHubName | Name of a new IoT Hub used by the VRTU. |
-InFile | This is the path to the configuration file created in the Step 2. |
-OutFile | The name of the configuration file to be output in the current “Kubernetes” folder. Use “vrtu-config.json” |
-
Type “. ./New-LocalDebugSetup.ps1” to load a PowerShell command to configuration the solution locally.
-
Type “New-LocalDebugSetup” with the following parameters
-File | This will be the configuration file created in Step 3.5, i.e., “vrtu-config.json” |
---|
The command will configure the solution and produce and output file in the “kubernetes” folder in the form “mm-dd-yyyyThh-mm-ss.json” that can be used to deploy a device to the IoT Hub.
-
Open the “Build.sln” in the “src” folder using Visual Studio Preview.
-
Set the “AzureIoT.Deployment.Function” project as the start project.
-
Run the project in Visual Studio in debug mode.
-
Back to the command prompt…type “. ./New-DeviceDeploy.ps1” to load the PowerShell to deploy a new device.
Type “New-DeviceDeploy”. The follow is a parameter list for the command, but you will only need the 1st parameter. Your command should look like New-DeviceDeploy -File “dd-mm-yyyyThh-mm-ss.json”.
-File | This will be the configuration file in the Kubernetes folder created in Step 2.7 in the form “mm-dd-yyyyThh-mm-ss.json” |
---|---|
-Url | Url of the Azure deployment function. You can omit this parameter which uses the default value of "http://localhost:7071/api/DeploymentFunction" |
-Key | “code” parameter used to call an Azure Function with http trigger. You can omit because we are uses the local function. |
-Update | $true or $false (default) indicates whether the command is for a new device and an update to an existing device. You can omit and use the default. |
-
After the PowerShell command executes it will return a device connection string. Stop the Visual Studio debugger. Open the Azure Portal.
-
Find the resource group you created and select the newly created IoT Hub
-
Navigate down the menu in the IoT Hub and select the “IoT Edge” menu item.
-
Select the device, “device1”, you just created.
-
Copy the “primary connection string” and paste it in Notepad. Add “ModuleId=fieldgateway;” to the connection string. It should now look like (below) copy it to the clipboard.
HostName=randombirdhub.azure-devices.net;DeviceId=device1;ModuleId=fieldgateway;SharedAccessKey=WgeWdRz2glOsSqF9h5dY6oeiP8H2EreTtYn85kmlIuo=
-
In Visual Studio right-click the VirtualRtu.Module project and select “properties” from the menu. Navigate to the Environment Variable section and paste the connection string in the value for the variable MODULE_CONNECTIONSTRING key.
-
-
In Visual Studio set the solution to “Multiple Startup Projects”, which is preconfigured and start the solution in debug mode. The module should configure itself and the solution is ready to use. Using the “Echo Client” console application you should be able to send and receive messages.
Learn out applying constraints to Modbus messages to filter interactions between clients and an RTU.