iot.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. "net/http"
  4. "imuslab.com/arozos/mod/iot"
  5. "imuslab.com/arozos/mod/iot/hdsv2"
  6. module "imuslab.com/arozos/mod/modules"
  7. prout "imuslab.com/arozos/mod/prouter"
  8. )
  9. /*
  10. IoT Hub
  11. Author: tobychui
  12. This script handle the IoT service start up and mangement
  13. IoT Manager: Manage who can have access to certain IoT devices
  14. IoT Panel: The panel for controlling the devices
  15. */
  16. var iotManager *iot.Manager
  17. func IoTHubInit() {
  18. if *allow_iot && *allow_mdns && MDNS != nil {
  19. //Create a new ioT Manager
  20. iotManager = iot.NewIoTManager()
  21. //Register IoT Hub Module
  22. moduleHandler.RegisterModule(module.ModuleInfo{
  23. Name: "IoT Hub",
  24. Group: "System Tools",
  25. IconPath: "SystemAO/iot/hub/img/small_icon.png",
  26. Version: "1.0",
  27. StartDir: "SystemAO/iot/hub/index.html",
  28. SupportFW: true,
  29. InitFWSize: []int{465, 730},
  30. LaunchFWDir: "SystemAO/iot/hub/index.html",
  31. SupportEmb: false,
  32. })
  33. //Register IoT Setting Interfaces
  34. registerSetting(settingModule{
  35. Name: "IoT Hub",
  36. Desc: "Manage IoT Devices Scanners",
  37. IconPath: "SystemAO/iot/img/small_icon.png",
  38. Group: "Device",
  39. StartDir: "SystemAO/iot/info.html",
  40. })
  41. //Register IoT Devices Endpoints
  42. router := prout.NewModuleRouter(prout.RouterOption{
  43. ModuleName: "IoT Panel",
  44. AdminOnly: false,
  45. UserHandler: userHandler,
  46. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  47. sendErrorResponse(w, "Permission Denied")
  48. },
  49. })
  50. adminRouter := prout.NewModuleRouter(prout.RouterOption{
  51. ModuleName: "System Setting",
  52. AdminOnly: true,
  53. UserHandler: userHandler,
  54. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  55. sendErrorResponse(w, "Permission Denied")
  56. },
  57. })
  58. //IoT Panel control APIs
  59. router.HandleFunc("/system/iot/scan", iotManager.HandleScanning)
  60. router.HandleFunc("/system/iot/list", iotManager.HandleListing)
  61. //IoT Hub Info APIs
  62. adminRouter.HandleFunc("/system/iot/listScanner", iotManager.HandleScannerList)
  63. //Start of the IoT Management Handlers
  64. //Home Dynamic v2
  65. hdsv2Handler := hdsv2.NewProtocolHandler(MDNS)
  66. iotManager.RegisterHandler(hdsv2Handler)
  67. //Add more here if needed
  68. }
  69. }