-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
38 lines (31 loc) · 759 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
package main
import (
"fmt"
"os"
"time"
magichome "github.com/apoclyps/magic-home/pkg"
)
// Discover a list of available devices on the local network.
func main() {
fmt.Print("Discovering ")
go func() {
for {
fmt.Print(".")
time.Sleep(100 * time.Millisecond)
}
}()
devices, err := magichome.Discover(magichome.DiscoverOptions{
BroadcastAddr: magichome.DEFAULT_BROADCAST_ADDR,
Timeout: 1,
})
if err != nil {
fmt.Println("Error: ", err)
os.Exit(1)
}
fmt.Print("\n\nDiscovered the following devices:\n\n")
fmt.Println("IP \t| ID \t| Model")
fmt.Println("-----------------------------------")
for _, device := range *devices {
fmt.Printf("%s\t| %s\t| %s\n", device.IP, device.ID, device.Model)
}
}