-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (37 loc) · 821 Bytes
/
main.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"net/http"
"time"
)
func main() {
url := flag.String("url", "null", "endpoint url")
flag.Parse()
fmt.Println("Start3... %s", *url)
r := NewRadio("/dev/spidev0.0")
for {
var buf *bytes.Buffer
select {
case rcvPayload := <-r.RcvChan:
fmt.Printf("Buf: %d \n", rcvPayload)
b, _ := json.Marshal(rcvPayload)
fmt.Printf("JSON: %s \n", b)
buf = bytes.NewBuffer(b)
case <-time.After(1 * time.Second):
buf = bytes.NewBufferString("{}")
}
resp, err := http.Post(*url, "application/json", buf)
if err == nil {
respBuf := new(bytes.Buffer)
respBuf.ReadFrom(resp.Body)
sndPayload := new(SndMsg)
json.Unmarshal(respBuf.Bytes(), sndPayload)
if sndPayload.Repeat > 0 {
r.SndChan <- sndPayload
}
}
}
}