iot.go 1.7 KB

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