iot.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package iot
  2. /*
  3. ArozOS IoT Handler
  4. This handler provide adaptive functions to different protocol based IoT devices
  5. (aka this is just a wrapper class. See independent IoT module for more information)
  6. */
  7. //Defination of a control endpoint
  8. type Endpoint struct {
  9. RelPath string //Relative path for this endpoint. If the access path is 192.168.0.100:8080/api1, then this value should be /api1
  10. Name string //Name of the this endpoint. E.g. "Toggle Light"
  11. Desc string //Description of function. E.g. "Toggle the ligh on and off"
  12. Type string //Type of endpoint data. Accept {string, integer, float, bool, none}
  13. //Filter for string type inputs
  14. Regex string
  15. //Filter for integer and float type inputs
  16. Min float64
  17. Max float64
  18. Steps float64
  19. }
  20. //Defination of an IoT device
  21. type Device struct {
  22. Name string //Name of the device
  23. Port int //The communication port on the device. -1 for N/A
  24. Model string //Model number of the device
  25. Version string //Device firmware
  26. Manufacturer string //<amifacturer of device
  27. DeviceUUID string //Device UUID
  28. IPAddr string //IP address of the device
  29. RequireAuth bool //Require authentication or public accessable.
  30. RequireConnect bool //Require pre-connection before use
  31. Status map[string]interface{} //Status of the device, support multi channels
  32. ControlEndpoints []*Endpoint //Endpoints avabile for this device
  33. }
  34. type AuthInfo struct {
  35. Username string
  36. Password string
  37. Token string
  38. }
  39. type Stats struct {
  40. Name string //Name of the protocol handler (e.g. Home Dynamic v2)
  41. Desc string //Description of the protcol
  42. Version string //Version of the handler (recommend matching the protocol ver for easier maintaince)
  43. ProtocolVer string //Version of the hardware protocol
  44. Author string //Name of the author
  45. AuthorWebsite string //Author contact website
  46. AuthorEmail string //Author Email
  47. ReleaseDate int64 //Release Date in unix timestamp
  48. }
  49. var (
  50. NoAuth AuthInfo = AuthInfo{} //Empty struct for quick no auth IoT protocols
  51. )
  52. type ProtocolHandler interface {
  53. Start() error //Run Startup check. This IoT Protocl Handler will not load if this return any error (e.g. required wireless hardware not found) **TRY NOT TO USE BLOCKING LOGIC HERE**
  54. Scan() ([]*Device, error) //Scan the nearby devices
  55. List() ([]*Device, error) //Return the previous scanned list
  56. Connect(device *Device, authInfo *AuthInfo) error //Connect to the device
  57. Status(device *Device) (map[string]interface{}, error) //Get status of the IoT device
  58. Execute(device *Device, endpoint *Endpoint, payload interface{}) (interface{}, error) //Execute an endpoint for a device
  59. Disconnect(device *Device) error //Disconnect from a device connection
  60. Stats() Stats //Return the properties and status of the Protocol Handler
  61. }