|
@@ -6,6 +6,7 @@ import (
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
|
|
+ "time"
|
|
|
|
|
|
"imuslab.com/arozos/mod/iot"
|
|
"imuslab.com/arozos/mod/iot"
|
|
)
|
|
)
|
|
@@ -76,6 +77,7 @@ func (h *Handler) Scan() ([]*iot.Device, error) {
|
|
//Create a IP scanner
|
|
//Create a IP scanner
|
|
var wg sync.WaitGroup
|
|
var wg sync.WaitGroup
|
|
for i := 1; i < 256; i++ {
|
|
for i := 1; i < 256; i++ {
|
|
|
|
+ time.Sleep(300 * time.Microsecond)
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
go func(wg *sync.WaitGroup) {
|
|
go func(wg *sync.WaitGroup) {
|
|
defer wg.Done()
|
|
defer wg.Done()
|
|
@@ -104,6 +106,22 @@ func (h *Handler) Scan() ([]*iot.Device, error) {
|
|
deviceState["status"] = strings.TrimSpace(statusText)
|
|
deviceState["status"] = strings.TrimSpace(statusText)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Create the hdsv1 endpoints (aka /on and /off)
|
|
|
|
+ endpoints := []*iot.Endpoint{}
|
|
|
|
+ endpoints = append(endpoints, &iot.Endpoint{
|
|
|
|
+ RelPath: "on",
|
|
|
|
+ Name: "ON",
|
|
|
|
+ Desc: "Turn on the device",
|
|
|
|
+ Type: "none",
|
|
|
|
+ })
|
|
|
|
+ endpoints = append(endpoints, &iot.Endpoint{
|
|
|
|
+ RelPath: "off",
|
|
|
|
+ Name: "OFF",
|
|
|
|
+ Desc: "Turn off the device",
|
|
|
|
+ Type: "none",
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ //Append the device to list
|
|
results = append(results, &iot.Device{
|
|
results = append(results, &iot.Device{
|
|
Name: devName,
|
|
Name: devName,
|
|
Port: 80, //HDS device use port 80 by default
|
|
Port: 80, //HDS device use port 80 by default
|
|
@@ -112,11 +130,12 @@ func (h *Handler) Scan() ([]*iot.Device, error) {
|
|
Manufacturer: "Generic",
|
|
Manufacturer: "Generic",
|
|
DeviceUUID: uuid,
|
|
DeviceUUID: uuid,
|
|
|
|
|
|
- IPAddr: targetIP,
|
|
|
|
- RequireAuth: false,
|
|
|
|
- RequireConnect: false,
|
|
|
|
- Status: deviceState,
|
|
|
|
- Handler: h,
|
|
|
|
|
|
+ IPAddr: targetIP,
|
|
|
|
+ RequireAuth: false,
|
|
|
|
+ RequireConnect: false,
|
|
|
|
+ Status: deviceState,
|
|
|
|
+ Handler: h,
|
|
|
|
+ ControlEndpoints: endpoints,
|
|
})
|
|
})
|
|
|
|
|
|
log.Println("*HDS* Found device ", devName, " at ", targetIP, " with UUID ", uuid)
|
|
log.Println("*HDS* Found device ", devName, " at ", targetIP, " with UUID ", uuid)
|
|
@@ -138,10 +157,20 @@ func (h *Handler) Disconnect(device *iot.Device) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//Get the icon filename of the device, it is always switch for hdsv1
|
|
|
|
+func (h *Handler) Icon(device *iot.Device) string {
|
|
|
|
+ return "switch"
|
|
|
|
+}
|
|
|
|
+
|
|
//Get the status of the device
|
|
//Get the status of the device
|
|
func (h *Handler) Execute(device *iot.Device, endpoint *iot.Endpoint, payload interface{}) (interface{}, error) {
|
|
func (h *Handler) Execute(device *iot.Device, endpoint *iot.Endpoint, payload interface{}) (interface{}, error) {
|
|
- var result interface{}
|
|
|
|
- return result, nil
|
|
|
|
|
|
+ //GET request the target device endpoint
|
|
|
|
+ resp, err := tryGet("http://" + device.IPAddr + ":" + strconv.Itoa(device.Port) + "/" + endpoint.RelPath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return map[string]interface{}{}, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resp, nil
|
|
}
|
|
}
|
|
|
|
|
|
//Get the status of the device
|
|
//Get the status of the device
|