forked from EcoMoveQuest/EcoMoveQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial_to_rest.ps1
31 lines (25 loc) · 887 Bytes
/
serial_to_rest.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Serial port settings
$portName = "COM4" # Replace with your serial port name
$baudRate = 9600
$dataBits = 8
$parity = "None"
$stopBits = "One"
# Open serial port
$serialPort = New-Object System.IO.Ports.SerialPort -ArgumentList @($portName, $baudRate, $parity, $dataBits, $stopBits)
$serialPort.Open()
function SendColorToEndpoint($color) {
$body = @{
color = $color
} | ConvertTo-Json
try {
$response = Invoke-WebRequest -Uri "https://comfortable-toad-swimsuit.cyclic.app/arrivals" -Method POST -ContentType "application/json" -Body $body
Write-Host "Sent color: $color - Response: $($response.StatusCode) $($response.StatusDescription)"
}catch {
Write-Host "Error sending color: $color - $($_.Exception.Message)"
}
}
do {
$color = $serialPort.ReadLine().Trim()
SendColorToEndpoint($color)
}
while ($serialPort.IsOpen)