iotagentsdk

package module
v1.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 15 Imported by: 4

README

Tests

iotagentsdk: Go SDK for IoT Agents

The iotagentsdk package is a Go software development kit (SDK) designed to facilitate interactions with IoT Agents in FIWARE-based systems. FIWARE is an open-source initiative aimed at providing a framework for the development of smart solutions in various domains, including smart cities, industrial IoT, and agriculture.

Features:

  • Config Group Management: Allows you to manage configuration groups for devices, including creating, reading, updating, and deleting (CRUD) operations.

  • Device Management: Provides functionalities for managing devices, such as reading device information, checking device existence, listing devices, creating devices, updating device information, and deleting devices.

How to Use:

  1. Import the Package: Import the iotagentsdk package into your Go project:

    import "github.com/fbuedding/fiware-iot-agent-sdk"
    
  2. Initialize the IoTA Client: Create an instance of the IoTA struct, providing the necessary configuration parameters such as host, port, and timeout.

    iotAgent := iotagentsdk.NewIoTA("localhost", 4041, 5000)
    
  3. Interact with IoT Agents: Use the methods provided by the iotagentsdk package to perform operations such as managing configuration groups and devices.

    // Example: Read device information
    deviceID := "my-device"
    deviceInfo, err := iotAgent.ReadDevice(myFiwareService, iotagentsdk.DeciveId(deviceID))
    if err != nil {
        log.Fatal("Error reading device:", err)
    }
    fmt.Println("Device information:", deviceInfo)
    

Compatibility:

  • The iotagentsdk package is compatible with Go versions 1.11 and higher.

Contributing:

Contributions to the iotagentsdk package are welcome! Feel free to submit bug reports, feature requests, or pull requests on GitHub.

License:

This package is licensed under the MIT License. See the LICENSE file for details.

For more information and detailed usage instructions, please refer to the documentation.

Acknowledgments:

This package is developed based on the FIWARE architecture and specifications. I acknowledge the contributions of the FIWARE community and developers.

Documentation

Overview

Package iotagentsdk provides an SDK for communicating with Fiware IoT Agents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(ll string)

SetLogLevel sets the global logging level based on the given value. Possible values are: "trace", "debug", "info", "warning", "error", "fatal", "panic".

Types

type ApiError

type ApiError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
}

ApiError represents an error in an API call.

func (ApiError) Error

func (e ApiError) Error() string

Error returns the error as a formatted string.

type Apikey

type Apikey string

Apikey represents an API key.

type Attribute

type Attribute struct {
	ObjectID   string              `json:"object_id,omitempty" form:"object_id"`
	Name       string              `json:"name" form:"name"`
	Type       string              `json:"type" form:"type"`
	Expression string              `json:"expression,omitempty" form:"expression"`
	SkipValue  string              `json:"skipValue,omitempty" form:"skipValue"`
	EntityName string              `json:"entity_name,omitempty" form:"entity_name"`
	EntityType string              `json:"entity_type,omitempty" form:"entity_type"`
	Metadata   map[string]Metadata `json:"metadata,omitempty" form:"metadata"`
}

Attribute represents an attribute in the data model.

type Command

type Command struct {
	ObjectID    string              `json:"object_id,omitempty" form:"object_id"`
	Name        string              `json:"name" form:"name"`
	Type        string              `json:"type" form:"type"`
	Expression  string              `json:"expression,omitempty" form:"expression"`
	PayloadType string              `json:"payloadType,omitempty" form:"payloadType"`
	ContentType string              `json:"contentType,omitempty" form:"contentType"`
	Metadata    map[string]Metadata `json:"metadata,omitempty" form:"metadata"`
}

Command represents a command in the data model.

type ConfigGroup

type ConfigGroup struct {
	Service                      string            `json:"service,omitempty" form:"service"`
	ServicePath                  string            `json:"subservice,omitempty" form:"subservice"`
	Resource                     Resource          `json:"resource" form:"resource"`
	Apikey                       Apikey            `json:"apikey" form:"apikey"`
	Timestamp                    *bool             `json:"timestamp,omitempty" form:"timestamp"`
	EntityType                   string            `json:"entity_type,omitempty" form:"entity_type"`
	Trust                        string            `json:"trust,omitempty" form:"trust"`
	CbHost                       string            `json:"cbHost,omitempty" form:"cbHost"`
	Lazy                         []LazyAttribute   `json:"lazy,omitempty" form:"lazy"`
	Commands                     []Command         `json:"commands,omitempty" form:"commands"`
	Attributes                   []Attribute       `json:"attributes,omitempty" form:"attributes"`
	StaticAttributes             []StaticAttribute `json:"static_attributes,omitempty" form:"static_attributes"`
	InternalAttributes           []interface{}     `json:"internal_attributes,omitempty" form:"internal_attributes"`
	ExplicitAttrs                string            `json:"explicitAttrs,omitempty" form:"explicitAttrs"`
	EntityNameExp                string            `json:"entityNameExp,omitempty" form:"entityNameExp"`
	NgsiVersion                  string            `json:"ngsiVersion,omitempty" form:"ngsiVersion"`
	DefaultEntityNameConjunction string            `json:"defaultEntityNameConjunction,omitempty" form:"defaultEntityNameConjunction"`
	Autoprovision                bool              `json:"autoprovision,omitempty" form:"autoprovision"`
	PayloadType                  string            `json:"payloadType,omitempty" form:"payloadType"`
	Transport                    string            `json:"transport,omitempty" form:"transport"`
	Endpoint                     string            `json:"endpoint,omitempty" form:"endpoint"`
}

ConfigGroup represents a configuration group. See datamodel [Config Group]: https://iotagent-node-lib.readthedocs.io/en/latest/api.html#service-group-datamodel

func (ConfigGroup) Validate

func (sg ConfigGroup) Validate() error

Function to validate the ConfigGroup

type DeciveId

type DeciveId string

DeciveId represents a device ID.

type Device

type Device struct {
	Id                 DeciveId          `json:"device_id,omitempty" form:"device_id"`
	Service            string            `json:"service,omitempty" form:"service"`
	ServicePath        string            `json:"service_path,omitempty" form:"service_path"`
	EntityName         string            `json:"entity_name,omitempty" form:"entity_name"`
	EntityType         string            `json:"entity_type,omitempty" form:"entity_type"`
	Timezone           string            `json:"timezon,omitempty" form:"timezone"`
	Timestamp          *bool             `json:"timestamp,omitempty" form:"timestamp"`
	Apikey             Apikey            `json:"apikey,omitempty" form:"apikey"`
	Endpoint           string            `json:"endpoint,omitempty" form:"endpoint"`
	Protocol           string            `json:"protocol,omitempty" form:"protocol"`
	Transport          string            `json:"transport,omitempty" form:"transport"`
	Attributes         []Attribute       `json:"attributes,omitempty" form:"attributes"`
	Commands           []Command         `json:"commands,omitempty" form:"commands"`
	Lazy               []LazyAttribute   `json:"lazy,omitempty" form:"lazy"`
	StaticAttributes   []StaticAttribute `json:"static_attributes,omitempty" form:"static_attributes"`
	InternalAttributes []interface{}     `json:"internal_attributes,omitempty" form:"internal_attributes"`
	ExplicitAttrs      any               `json:"explicitAttrs,omitempty" form:"explicitAttrs"`
	NgsiVersion        string            `json:"ngsiVersion,omitempty" form:"ngsiVersion"`
	PayloadType        string            `json:"payloadType,omitempty" form:"payloadType"`
}

Device represents a device. See datamodel Device: https://iotagent-node-lib.readthedocs.io/en/3.3.0/api.html#device-datamodel

func (*Device) MarshalJSON added in v1.1.7

func (d *Device) MarshalJSON() ([]byte, error)

func (Device) Validate

func (d Device) Validate() error

Function to validate a Device

type FiwareService

type FiwareService struct {
	Service     string
	ServicePath string
}

FiwareService represents a Fiware service and its associated service path.

type IoTA

type IoTA struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

IoTA represents an IoT Agent instance.

func NewIoTAgent added in v1.1.0

func NewIoTAgent(host string, port int, timeout_ms int) *IoTA

NewIoTAgent creates a new instance of the IoT Agent.

func (IoTA) Client

func (i IoTA) Client() *http.Client

Client returns the HTTP client used for communication with the IoT Agent. If no client is present, a new one is created.

func (IoTA) ConfigGroupExists

func (i IoTA) ConfigGroupExists(fs FiwareService, r Resource, a Apikey) bool

Method to check if a ConfigGroup exists

func (IoTA) CreateConfigGroup

func (i IoTA) CreateConfigGroup(fs FiwareService, sg ConfigGroup) error

Method to create a ConfigGroup

func (IoTA) CreateConfigGroupWSE

func (i IoTA) CreateConfigGroupWSE(fs FiwareService, sg *ConfigGroup) error

Method to create a ConfigGroup, getting the created ConfigGroup and setting it.

func (IoTA) CreateConfigGroups

func (i IoTA) CreateConfigGroups(fs FiwareService, sgs []ConfigGroup) error

Method to create multiple ConfigGroups

func (IoTA) CreateDevice

func (i IoTA) CreateDevice(fs FiwareService, d Device) error

Method to create a device

func (IoTA) CreateDeviceWSE

func (i IoTA) CreateDeviceWSE(fs FiwareService, d *Device) error

Creates a device an updates the given Device

func (IoTA) CreateDevices

func (i IoTA) CreateDevices(fs FiwareService, ds []Device) error

Method to create a device

func (IoTA) DeleteConfigGroup

func (i IoTA) DeleteConfigGroup(fs FiwareService, r Resource, a Apikey) error

Method to delete a ConfigGroup

func (IoTA) DeleteDevice

func (i IoTA) DeleteDevice(fs FiwareService, id DeciveId) error

Method to delete a device

func (IoTA) DeviceExists

func (i IoTA) DeviceExists(fs FiwareService, id DeciveId) bool

Method to check if a device exists

func (IoTA) GetAllServicePathsForService

func (i IoTA) GetAllServicePathsForService(service string) ([]string, error)

GetAllServicePathsForService returns all service paths for the specified service.

func (IoTA) Healthcheck

func (i IoTA) Healthcheck() (*RespHealthcheck, error)

Healthcheck performs a health check of the IoT Agent and returns the result.

func (IoTA) ListConfigGroups

func (i IoTA) ListConfigGroups(fs FiwareService) (*RespReadConfigGroup, error)

Method to list ConfigGroups

func (IoTA) ListDevices

func (i IoTA) ListDevices(fs FiwareService) (*respListDevices, error)

Method to list devices

func (IoTA) ReadConfigGroup

func (i IoTA) ReadConfigGroup(fs FiwareService, r Resource, a Apikey) (*RespReadConfigGroup, error)

Method to read a ConfigGroup

func (IoTA) ReadDevice

func (i IoTA) ReadDevice(fs FiwareService, id DeciveId) (*Device, error)

Method to read a device

func (IoTA) UpdateConfigGroup

func (i IoTA) UpdateConfigGroup(fs FiwareService, r Resource, a Apikey, sg ConfigGroup) error

Method to update a ConfigGroup

func (IoTA) UpdateDevice

func (i IoTA) UpdateDevice(fs FiwareService, d Device) error

Method to update a device

func (IoTA) UpsertConfigGroup

func (i IoTA) UpsertConfigGroup(fs FiwareService, sg ConfigGroup) error

Method to upsert a ConfigGroup

func (IoTA) UpsertDevice

func (i IoTA) UpsertDevice(fs FiwareService, d Device) error

Method to upsert a device

type LazyAttribute

type LazyAttribute struct {
	ObjectID string              `json:"object_id,omitempty" form:"object_id"`
	Name     string              `json:"name" form:"name"`
	Type     string              `json:"type" form:"type"`
	Metadata map[string]Metadata `json:"metadata,omitempty" form:"metadata"`
}

LazyAttribute represents a lazy attribute in the data model.

type Metadata

type Metadata struct {
	Type  string `json:"type" form:"type"`
	Value string `json:"value" form:"value"`
}

Metadata represents metadata for attributes and commands.

type MissingFields

type MissingFields struct {
	Fields  vector.StringVector
	Message string
}

func (*MissingFields) Error

func (e *MissingFields) Error() string

Error handling

type ReqCreateConfigGroup

type ReqCreateConfigGroup struct {
	Services []ConfigGroup `json:"services"`
}

Request struct for creating ConfigGroup

type Resource

type Resource string

Resource represents a resource.

type RespHealthcheck

type RespHealthcheck struct {
	LibVersion string `json:"libVersion"`
	Port       string `json:"port"`
	BaseRoot   string `json:"baseRoot"`
	Version    string `json:"version"`
}

RespHealthcheck represents the response of a health check request.

type RespReadConfigGroup

type RespReadConfigGroup struct {
	Count    int           `json:"count"`
	Services []ConfigGroup `json:"services"`
}

Response struct for reading ConfigGroup

type StaticAttribute

type StaticAttribute struct {
	ObjectID string              `json:"object_id,omitempty" form:"object_id"`
	Name     string              `json:"name" form:"name"`
	Type     string              `json:"type" form:"type"`
	Value    any                 `json:"value" form:"value"`
	Metadata map[string]Metadata `json:"metadata,omitempty" form:"metadata"`
}

StaticAttribute represents a static attribute in the data model.

func (*StaticAttribute) MarshalJSON added in v1.1.8

func (sa *StaticAttribute) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL