iot.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 ProtocolHandler interface {
  35. Scan() ([]*Device, error) //Scan the nearby devices
  36. List() ([]*Device, error) //Return the previous scanned list
  37. Connect(device *Device) error //Connect to the device
  38. Status(device *Device) (map[string]interface{}, error) //Get status of the IoT device //Connect to a given device
  39. Execute(device *Device, endpoint *Endpoint, payload interface{}) (interface{}, error) //Execute an endpoint for a device
  40. Disconnect(device *Device) error //Disconnect from a device connection
  41. }