iot.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. }
  13. //Defination of an IoT device
  14. type Device struct {
  15. Name string //Name of the device
  16. Model string //Model number of the device
  17. Version string //Device firmware
  18. Manufacturer string //<amifacturer of device
  19. DeviceUUID string //Device UUID
  20. IPAddr string //IP address of the device
  21. RequireAuth bool //Require authentication or public accessable.
  22. RequireConnect bool //Require pre-connection before use
  23. Status map[string]interface{} //Status of the device, support multi channels
  24. ControlEndpoints []*Endpoint //Endpoints avabile for this device
  25. SourceHandler *ProtocolHandler //The source handler that this device is scanned / discovered by
  26. }
  27. type ProtocolHandler interface {
  28. Scan() ([]*Device, error) //Scan the nearby devices
  29. List() ([]*Device, error) //Return the previous scanned list
  30. Connect(device *Device) error //Connect to the device
  31. Status(device *Device) (map[string]string, error) //Get status of the IoT device //Connect to a given device
  32. Execute(device *Device, endpoint *Endpoint, payload interface{}) (interface{}, error) //Execute an endpoint for a device
  33. Disconnect(device *Device) error //Disconnect from a device connection
  34. }