Læser og kalder API som det skal. OTA virker Opsætning af wifi via ESP32's eget hotspot virker Mangler at få lavet skrivning, men det bliver v2.
122 lines
2.8 KiB
PowerShell
122 lines
2.8 KiB
PowerShell
param(
|
|
[string]$BaseUrl = "http://192.168.3.2:9090"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Invoke-FilamentGuardPost {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$Name,
|
|
|
|
[Parameter(Mandatory)]
|
|
[string]$Path,
|
|
|
|
[Parameter(Mandatory)]
|
|
[object]$Payload
|
|
)
|
|
|
|
$url = $BaseUrl.TrimEnd("/") + $Path
|
|
$json = $Payload | ConvertTo-Json -Depth 10 -Compress
|
|
|
|
Write-Host ""
|
|
Write-Host "=== $Name ===" -ForegroundColor Cyan
|
|
Write-Host "POST $url"
|
|
Write-Host $json
|
|
|
|
try {
|
|
$response = Invoke-WebRequest `
|
|
-Uri $url `
|
|
-Method Post `
|
|
-ContentType "application/json; charset=utf-8" `
|
|
-Body $json `
|
|
-UseBasicParsing
|
|
|
|
Write-Host "HTTP $([int]$response.StatusCode)" -ForegroundColor Green
|
|
|
|
if ($response.Content) {
|
|
Write-Host $response.Content
|
|
}
|
|
}
|
|
catch {
|
|
$statusCode = 0
|
|
$responseBody = ""
|
|
|
|
if ($_.Exception.Response) {
|
|
$statusCode = [int]$_.Exception.Response.StatusCode
|
|
|
|
try {
|
|
$stream = $_.Exception.Response.GetResponseStream()
|
|
$reader = [System.IO.StreamReader]::new($stream)
|
|
$responseBody = $reader.ReadToEnd()
|
|
$reader.Dispose()
|
|
}
|
|
catch {
|
|
$responseBody = ""
|
|
}
|
|
}
|
|
|
|
Write-Host "HTTP $statusCode" -ForegroundColor Red
|
|
|
|
if ($responseBody) {
|
|
Write-Host $responseBody
|
|
}
|
|
else {
|
|
Write-Host $_.Exception.Message
|
|
}
|
|
}
|
|
}
|
|
|
|
$deviceId = "ESP32-API-TEST"
|
|
$hostname = "filamentguard-api-test"
|
|
$tagUid = "E0:04:01:23:45:67:89:AB"
|
|
|
|
$tagRead = @{
|
|
reader = @{
|
|
id = "00112233445566778899AABBCCDDEEFF"
|
|
}
|
|
device = @{
|
|
deviceId = $deviceId
|
|
hostname = $hostname
|
|
}
|
|
tag = @{
|
|
tagUid = $tagUid
|
|
instanceUuid = "00000000-0000-0000-0000-000000000001"
|
|
materialName = "API test PLA"
|
|
materialType = "PLA"
|
|
brand = "Test"
|
|
colorHex = "#FF0000"
|
|
actualWeightGrams = 1000
|
|
nominalWeightGrams = 1000
|
|
spoolWeightGrams = 200
|
|
consumedWeightGrams = 0
|
|
remainingWeightGrams = 1000
|
|
hasActualWeight = $true
|
|
hasNominalWeight = $true
|
|
hasSpoolWeight = $true
|
|
hasConsumedWeight = $true
|
|
}
|
|
}
|
|
|
|
$logEntry = @{
|
|
deviceId = $deviceId
|
|
hostname = $hostname
|
|
firmwareVersion = "1.0.2"
|
|
level = "Info"
|
|
category = "ApiTest"
|
|
message = "Ekstern API-test"
|
|
data = '{"source":"test-api.ps1"}'
|
|
tagUid = $tagUid
|
|
uptimeMilliseconds = 12345
|
|
}
|
|
|
|
Invoke-FilamentGuardPost `
|
|
-Name "Tagregistrering" `
|
|
-Path "/api/Tag/detected" `
|
|
-Payload $tagRead
|
|
|
|
Invoke-FilamentGuardPost `
|
|
-Name "Logoprettelse" `
|
|
-Path "/api/Log/create" `
|
|
-Payload $logEntry
|