Skip to content

Commit 6625702

Browse files
committed
moved glazing configuration to docs and added script to get modbus logs
1 parent e99205d commit 6625702

2 files changed

Lines changed: 115 additions & 5 deletions

File tree

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
1+
# Glazing Configuration
22

33
Room 1 is the room on the right when entering the facility.
44
Room 2 is the room on the left when entering the facility.
55

6-
# Glazing Configuration
7-
86
## Glazing Configuration in Room 1
97

108
skylight:
119

12-
SK 1.1
10+
SK 1.1
1311

1412
3x3 panels:
1513

@@ -27,4 +25,4 @@ SK 1.2
2725

2826
| DR 2.3 | DR 2.6 | DR 2.9 |
2927
| DR 2.2 | DR 2.5 | DR 2.8 |
30-
| DR 2.1 | DR 2.4 | DR 2.7 |
28+
| DR 2.1 | DR 2.4 | DR 2.7 |

scripts/sensors/Get-ModbusLogs.ps1

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<#
2+
.SYNOPSIS
3+
Downloads all files from /var/log/modbus on an FTP data logger to a local folder.
4+
5+
.DESCRIPTION
6+
Uses curl.exe (built into Windows 11) rather than ftp.exe or Invoke-WebRequest,
7+
because curl handles FTP LIST/RETR more predictably and gives clear exit codes
8+
per file. Requires plain anonymous-free FTP auth (user:pass), as confirmed
9+
working in your ftp.exe test.
10+
11+
.PARAMETER FtpHost
12+
IP or hostname of the data logger. Defaults to 192.168.40.50
13+
14+
.PARAMETER Username
15+
FTP username. Deafults to admin.
16+
17+
.PARAMETER Password
18+
FTP password. Defaults to admin. If omitted, you will be prompted (not echoed to screen).
19+
20+
.PARAMETER RemotePath
21+
Remote directory to mirror. Defaults to /var/log/modbus.
22+
23+
.PARAMETER LocalPath
24+
Local destination directory. Created if it does not exist.
25+
26+
.EXAMPLE
27+
.\Get-ModbusLogs.ps1 -Username svc_ftp -LocalPath C:\Logs\modbus
28+
29+
.NOTES
30+
- Explicitly calls curl.exe (not the PowerShell 5.1 alias for Invoke-WebRequest).
31+
- Skips directory entries when parsing the LIST output (lines starting with 'd').
32+
- Existing local files with the same name are overwritten.
33+
#>
34+
35+
[CmdletBinding()]
36+
param(
37+
[string]$FtpHost = "192.168.40.50",
38+
[string]$Username = "admin",
39+
[securestring]$Password = (ConvertTo-SecureString "admin" -AsPlainText -Force),
40+
[string]$RemotePath = "/var/log/modbus",
41+
[string]$LocalPath = ".\modbus_logs"
42+
)
43+
44+
$ErrorActionPreference = "Stop"
45+
46+
# Confirm curl.exe (the real one) is present, not just the IWR alias.
47+
$curl = Get-Command curl.exe -ErrorAction SilentlyContinue
48+
if (-not $curl) {
49+
throw "curl.exe not found. It ships with Windows 11 by default (System32\curl.exe) — check PATH."
50+
}
51+
52+
if (-not $Password) {
53+
$Password = Read-Host -Prompt "FTP password for $Username" -AsSecureString
54+
}
55+
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
56+
$plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
57+
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
58+
59+
$userArg = "${Username}:${plainPassword}"
60+
$remoteDirUrl = "ftp://$FtpHost$RemotePath/"
61+
62+
if (-not (Test-Path -LiteralPath $LocalPath)) {
63+
New-Item -ItemType Directory -Path $LocalPath -Force | Out-Null
64+
}
65+
66+
Write-Host "Listing $remoteDirUrl ..."
67+
$listingRaw = & $curl.Source -s --user $userArg $remoteDirUrl
68+
if ($LASTEXITCODE -ne 0) {
69+
throw "curl LIST failed against $remoteDirUrl (exit code $LASTEXITCODE). Check path/credentials."
70+
}
71+
72+
if (-not $listingRaw) {
73+
Write-Warning "Directory listing came back empty. Nothing to download."
74+
return
75+
}
76+
77+
# Parse standard Unix-style LIST output. Skip directory entries (leading 'd')
78+
# and anything that doesn't look like a regular file line.
79+
$files = @()
80+
foreach ($line in $listingRaw -split "`r?`n") {
81+
if ([string]::IsNullOrWhiteSpace($line)) { continue }
82+
if ($line.StartsWith("d")) { continue } # subdirectory, not a file
83+
if ($line.StartsWith("l")) { continue } # symlink, skip unless you want it followed
84+
$name = ($line -split '\s+', 9)[-1]
85+
if ($name) { $files += $name }
86+
}
87+
88+
if ($files.Count -eq 0) {
89+
Write-Warning "No regular files parsed out of the listing. Raw output below for inspection:"
90+
Write-Host $listingRaw
91+
return
92+
}
93+
94+
Write-Host "Found $($files.Count) file(s). Downloading to $LocalPath ..."
95+
96+
$failed = @()
97+
foreach ($name in $files) {
98+
$remoteUrl = "$remoteDirUrl$name"
99+
$localFile = Join-Path $LocalPath $name
100+
Write-Host " -> $name"
101+
& $curl.Source -s --user $userArg -o "$localFile" "$remoteUrl"
102+
if ($LASTEXITCODE -ne 0) {
103+
Write-Warning " FAILED (curl exit $LASTEXITCODE): $name"
104+
$failed += $name
105+
}
106+
}
107+
108+
if ($failed.Count -gt 0) {
109+
Write-Warning "$($failed.Count) of $($files.Count) file(s) failed: $($failed -join ', ')"
110+
} else {
111+
Write-Host "All $($files.Count) file(s) downloaded successfully to $LocalPath"
112+
}

0 commit comments

Comments
 (0)