iot.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. Handler ProtocolHandler //Its parent protocol handler
  34. }
  35. type AuthInfo struct {
  36. Username string
  37. Password string
  38. Token string
  39. }
  40. type Stats struct {
  41. Name string //Name of the protocol handler (e.g. Home Dynamic v2)
  42. Desc string //Description of the protcol
  43. Version string //Version of the handler (recommend matching the protocol ver for easier maintaince)
  44. ProtocolVer string //Version of the hardware protocol
  45. Author string //Name of the author
  46. AuthorWebsite string //Author contact website
  47. AuthorEmail string //Author Email
  48. ReleaseDate int64 //Release Date in unix timestamp
  49. }
  50. var (
  51. NoAuth AuthInfo = AuthInfo{} //Empty struct for quick no auth IoT protocols
  52. )
  53. type ProtocolHandler interface {
  54. 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**
  55. Scan() ([]*Device, error) //Scan the nearby devices //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. Icon(device *Device) string //Get the icon of the device, see iot/hub/img/devices for a list of icons
  62. }