Skip to content

Commit

Permalink
connectivity and visibility samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jomit committed May 1, 2022
1 parent cee2c1f commit c2486ba
Show file tree
Hide file tree
Showing 63 changed files with 6,392 additions and 51 deletions.
3 changes: 3 additions & 0 deletions 1_Connectivity/01_Install_Features.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools
Enable-WindowsOptionalFeature -Online -FeatureName "VirtualMachinePlatform" -NoRestart
Restart-Computer
43 changes: 43 additions & 0 deletions 1_Connectivity/02_Create_VirtualSwitch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ------------------ Configure Networking ---------------------- #
# Create Virtual Switch
New-VMSwitch -Name "Default Switch" -SwitchType Internal

#Get Index
$InterfaceIndex = (Get-NetAdapter -Name "vEthernet (Default Switch)").ifIndex

do {
Start-Sleep -Seconds 10
$IPAddress = (Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $InterfaceIndex).IPAddress
} while($null -eq $IPAddress)

# Configure other IPs
$octets = $IPAddress -split "\."
$octets[3] = 1
$GatewayIP = $octets -join "."
$octets[3] = 0
$NatIP = $octets -join "."
$octets[3] = 100
$StartIP = $octets -join "."
$octets[3] = 200
$EndIP = $octets -join "."
$InternalIPInterfaceAddressPrefix = $NatIP + "/24"

# Set Gateway IP Address
New-NetIPAddress -IPAddress $GatewayIP -PrefixLength 24 -InterfaceIndex $InterfaceIndex

# Create Nat
New-NetNat -Name "Default Switch" -InternalIPInterfaceAddressPrefix $InternalIPInterfaceAddressPrefix

# Install DHCP Server
Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools

# Add
netsh dhcp add securitygroups
Restart-Service dhcpserver

# Add the DHCP Server to the default local security groups and restart the server.
Add-DhcpServerV4Scope -Name "AzureIoTEdgeScope" -StartRange $StartIP -EndRange $EndIP -SubnetMask 255.255.255.0 -State Active

# Assign the NAT and gateway IP addresses you created in the earlier section to the DHCP server, and restart the server to load the configuration.
Set-DhcpServerV4OptionValue -ScopeID $NatIP -Router $GatewayIP
Restart-service dhcpserver
18 changes: 18 additions & 0 deletions 1_Connectivity/03_Install_EFLOW.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
param(
[string]$CONNECTION_STRING
)

# ------------------ EFLOW ---------------------- #
#Run each of the following commands to download IoT Edge for Linux on Windows
$msiPath = $([io.Path]::Combine($env:TEMP, 'AzureIoTEdge.msi'))
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest "https://aka.ms/AzEFLOWMSI-CR-X64" -OutFile $msiPath

#Install IoT Edge for Linux on Windows on your device.
Start-Process -Wait msiexec -ArgumentList "/i","$([io.Path]::Combine($env:TEMP, 'AzureIoTEdge.msi'))","/qn"

#Create Linux virtual machine and installs the IoT Edge runtime for you.
Deploy-Eflow -acceptEula yes -acceptOptionalTelemetry no

# Provision EFLOW
Provision-EflowVm -provisioningType ManualConnectionString -devConnString $CONNECTION_STRING
3 changes: 3 additions & 0 deletions 1_Connectivity/04_Copy_OPCConfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copy pn.json file to EFLOW VM
Invoke-EflowVmCommand "mkdir -p opcconfig"
Copy-EflowVMFile -fromFile "opcconfig.json" -toFile ~\opcconfig\opcconfig.json -pushFile
52 changes: 52 additions & 0 deletions 1_Connectivity/BasicQueries.kql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
opc_raw
| order by SourceTimestamp desc
| take 100

telemetry
| order by SourceTimestamp desc
| take 100

// Plot all Sensors in all Lines
// Last 1 hours with 1 minute grouping
let _startTime = now()-1h;
let _endTime = now();
telemetry
| make-series num=avg(tolong(Value)) default=0 on SourceTimestamp in range(_startTime, _endTime, 1m) by ExpandedNodeId
| render timechart


// Plot all Sensors in Line 1
let _startTime = now()-1hr;
let _endTime = now();
let temptags = telemetry
| distinct ExpandedNodeId
| where ExpandedNodeId contains ("Line1")
| project ExpandedNodeId;
telemetry
| where ExpandedNodeId in (temptags)
| project
SourceTimestamp, Tag = replace_string(ExpandedNodeId,"nsu=KEPServerEX;s=Simulator.Line1.",""),
yaxis = todouble(Value)
| make-series num=avg(yaxis) default=0 on SourceTimestamp in range(_startTime,_endTime, 1m) by Tag
| render timechart



// Plot all Humidity Sensors
// Last 30 minutes with 10 second grouping
let _startTime = now()-30m;
let _endTime = now();
let temptags = telemetry
| distinct ExpandedNodeId
| where ExpandedNodeId contains ("Humidity")
| project ExpandedNodeId;
telemetry
| where ExpandedNodeId in (temptags)
| project SourceTimestamp, ExpandedNodeId, yaxis = todouble(substring(Value,0,2))
| make-series num=avg(yaxis) default=0 on SourceTimestamp in range(_startTime, _endTime, 10s) by ExpandedNodeId
| render timechart


// Management Queries

.show ingestion failures
Loading

0 comments on commit c2486ba

Please sign in to comment.