-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiot.go
109 lines (89 loc) · 3.05 KB
/
iot.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"net/http"
"imuslab.com/arozos/mod/iot"
"imuslab.com/arozos/mod/iot/hds"
"imuslab.com/arozos/mod/iot/hdsv2"
"imuslab.com/arozos/mod/iot/sonoff_s2x"
module "imuslab.com/arozos/mod/modules"
prout "imuslab.com/arozos/mod/prouter"
"imuslab.com/arozos/mod/utils"
)
/*
IoT Hub
Author: tobychui
This script handle the IoT service start up and mangement
IoT Manager: Manage who can have access to certain IoT devices
IoT Panel: The panel for controlling the devices
*/
var iotManager *iot.Manager
func IoTHubInit() {
if *allow_iot && *allow_mdns && MDNS != nil {
//Create a new ioT Manager
iotManager = iot.NewIoTManager(sysdb)
//Register IoT Hub Module
moduleHandler.RegisterModule(module.ModuleInfo{
Name: "IoT Hub",
Group: "Internet",
IconPath: "SystemAO/iot/hub/img/small_icon.png",
Version: "1.0",
StartDir: "SystemAO/iot/hub/index.html",
SupportFW: true,
InitFWSize: []int{465, 730},
LaunchFWDir: "SystemAO/iot/hub/index.html",
SupportEmb: false,
})
//Register IoT Setting Interfaces
registerSetting(settingModule{
Name: "IoT Hub",
Desc: "Manage IoT Devices Scanners",
IconPath: "SystemAO/iot/img/small_icon.png",
Group: "Device",
StartDir: "SystemAO/iot/info.html",
})
//Register IoT Devices Endpoints
router := prout.NewModuleRouter(prout.RouterOption{
ModuleName: "IoT Hub",
AdminOnly: false,
UserHandler: userHandler,
DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
utils.SendErrorResponse(w, "Permission Denied")
},
})
adminRouter := prout.NewModuleRouter(prout.RouterOption{
ModuleName: "System Setting",
AdminOnly: true,
UserHandler: userHandler,
DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
utils.SendErrorResponse(w, "Permission Denied")
},
})
//IoT Panel control APIs
router.HandleFunc("/system/iot/scan", iotManager.HandleScanning)
router.HandleFunc("/system/iot/list", iotManager.HandleListing)
router.HandleFunc("/system/iot/status", iotManager.HandleGetDeviceStatus)
router.HandleFunc("/system/iot/execute", iotManager.HandleExecute)
router.HandleFunc("/system/iot/icon", iotManager.HandleIconLoad)
router.HandleFunc("/system/iot/nickname", iotManager.HandleNickName)
//IoT Hub Info APIs
adminRouter.HandleFunc("/system/iot/listScanner", iotManager.HandleScannerList)
//Start of the IoT Management Handlers
//Home Dynamic v1 (Legacy)
hdsHandler := hds.NewProtocolHandler()
iotManager.RegisterHandler(hdsHandler)
//Home Dynamic v2
hdsv2Handler := hdsv2.NewProtocolHandler(MDNS)
iotManager.RegisterHandler(hdsv2Handler)
//Tasmota Sonoff S2X
tasmotaSonoffS2x := sonoff_s2x.NewProtocolHandler(MDNS)
iotManager.RegisterHandler(tasmotaSonoffS2x)
//Add more here if needed
//Start the initial scanning
go func() {
iotManager.ScanDevices()
systemWideLogger.PrintAndLog("IoT", "Initial IoT device scanning completed", nil)
}()
//Finally, inject the gateway into the AGI interface
AGIGateway.Option.IotManager = iotManager
}
}