iot.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "imuslab.com/arozos/mod/iot"
  6. "imuslab.com/arozos/mod/iot/hdsv2"
  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 Setting Interfaces
  22. registerSetting(settingModule{
  23. Name: "IoT Manager",
  24. Desc: "Manage IoT Devices Permission",
  25. IconPath: "SystemAO/iot/img/small_icon.png",
  26. Group: "Device",
  27. StartDir: "SystemAO/iot/manager.html",
  28. })
  29. //Register IoT Devices Endpoints
  30. router := prout.NewModuleRouter(prout.RouterOption{
  31. ModuleName: "IoT Panel",
  32. AdminOnly: false,
  33. UserHandler: userHandler,
  34. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  35. sendErrorResponse(w, "Permission Denied")
  36. },
  37. })
  38. adminRouter := prout.NewModuleRouter(prout.RouterOption{
  39. ModuleName: "System Setting",
  40. AdminOnly: true,
  41. UserHandler: userHandler,
  42. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  43. sendErrorResponse(w, "Permission Denied")
  44. },
  45. })
  46. router.HandleFunc("/system/iot/scan", iotManager.HandleScanning)
  47. log.Println("Work in progress breakpoint: ", router, adminRouter)
  48. //Start of the IoT Management Handlers
  49. //Home Dynamic v2
  50. hdsv2Handler := hdsv2.NewProtocolHandler(MDNS)
  51. iotManager.RegisterHandler(hdsv2Handler)
  52. //Add more here if needed
  53. }
  54. }