Skip to content

Commit

Permalink
fix: Add delay before reading serial
Browse files Browse the repository at this point in the history
  • Loading branch information
tonygilkerson committed Jan 7, 2024
1 parent 544f7c6 commit 7859a36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SERIAL_PORT=./virtual-tty go run cmd/serial/main.go
The serial-gateway has a `/pub` endpoint that can be used for testing. A `POST` to `/pub` will result in the http body being written to the serial port on the host. As a result the LORA gateway will broadcast the contents for any LORA device to receive.

```sh
ssh -D 9995 weeble
kubectl ctx weeble
kubectl -n iot port-forward svc/serial-gateway 8080:8080
curl -X POST "http://localhost:8080/pub" -d "a-message"
```
4 changes: 4 additions & 0 deletions cmd/serial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -160,6 +161,9 @@ func serialServer(port *serial.Port) {
var n int
var msg string

log.Println("Pause for buffer ZZZzzz...")
time.Sleep(time.Millisecond * 50)

n, err = port.Read(buf)
if err != nil {
log.Panicf("Error trying to read serial port %v\n", err)
Expand Down

0 comments on commit 7859a36

Please sign in to comment.