goplatform

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 10 Imported by: 0

README

GoPlatform

An SDK for Apio Platform in Golang.

Install
go get github.com/ApioIoT/goplatform
Get Projects
platform := goplatform.New(URI, API_KEY)

projects, err := platform.GetProjects()
if err != nil {
  log.Fatal(err)
}
Get Project
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}
Get Nodes
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

nodes, err := project.GetNodes()
if err != nil {
  log.Fatal(err)
}
Get Node
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

node, err := project.GetNode(NODE_ID)
if err != nil {
  log.Fatal(err)
}
Get Devices
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

devices, err := project.GetDevices()
if err != nil {
  log.Fatal(err)
}
Get Device
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

device, err := project.GetDevice(DEVICE_ID)
if err != nil {
  log.Fatal(err)
}
Get DeviceTypes
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

devices, err := project.GetDeviceTypes()
if err != nil {
  log.Fatal(err)
}
Get DeviceType
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

deviceType, err := project.GetDeviceType(DEVICE_TYPE_ID)
if err != nil {
  log.Fatal(err)
}
Create Event
platform := goplatform.New(URI, API_KEY)

project, err := platform.GetProject(PROJECT_ID)
if err != nil {
  log.Fatal(err)
}

event := goplatform.Event{
  Description: "Evento di prova",
  Type:        "Notification",
  Source:      "test/event",
}

if err := project.CreateEvent(event); err != nil {
  log.Fatal(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command added in v1.8.8

type Command struct {
	CommandRequest
	Uuid        string     `json:"uuid"`
	Status      string     `json:"status"`
	CreatedAt   *time.Time `json:"createdAt,omitempty"`
	UpdatedAt   *time.Time `json:"updatedAt,omitempty"`
	ReceivedAt  *time.Time `json:"receivedAt,omitempty"`
	CompletedAt *time.Time `json:"completedAt,omitempty"`
	FailedAt    *time.Time `json:"failedAt,omitempty"`
}

type CommandParameters added in v1.8.9

type CommandParameters []map[string]any

func (CommandParameters) MarshalJSON added in v1.8.10

func (c CommandParameters) MarshalJSON() ([]byte, error)

func (*CommandParameters) UnmarshalJSON added in v1.8.9

func (c *CommandParameters) UnmarshalJSON(data []byte) error

type CommandRequest added in v1.8.10

type CommandRequest struct {
	Name       string            `json:"name"`
	ProjectId  string            `json:"projectId"`
	NodeId     *string           `json:"nodeId,omitempty"`
	DeviceId   *string           `json:"deviceId,omitempty"`
	Parameters CommandParameters `json:"parameters"`
	Metadata   map[string]any    `json:"metadata,omitempty"`
}

type Device

type Device struct {
	Uuid                string               `json:"uuid,omitempty"`
	ProjectID           string               `json:"projectId"`
	DeviceTypeID        string               `json:"deviceTypeId,omitempty"`
	NodeID              string               `json:"nodeId,omitempty"`
	Encoder             string               `json:"encoder,omitempty"`
	Decoder             string               `json:"decoder,omitempty"`
	FirmwareVersion     string               `json:"firmwareVersion,omitempty"`
	PlantID             string               `json:"plantId,omitempty"`
	Location            *LocationPointSchema `json:"location,omitempty"`
	SerialNumber        string               `json:"serialNumber,omitempty"`
	Name                string               `json:"name"`
	Description         string               `json:"description,omitempty"`
	DeviceType          *DeviceType          `json:"deviceType,omitempty"`
	Metadata            map[string]any       `json:"metadata"`
	State               any                  `json:"state"`
	StateUpdatedAt      any                  `json:"stateUpdatedAt"`
	LastActivityAt      string               `json:"lastActivityAt"`
	LastCommunicationAt string               `json:"lastCommunicationAt"`
	ConnectivityStatus  string               `json:"connectivityStatus"`
	LastConnectionAt    string               `json:"lastConnectionAt"`
	LastDisconnectionAt string               `json:"lastDisconnectionAt"`
	Tags                []string             `json:"tags"`
	CreatedAt           time.Time            `json:"createdAt,omitempty"`
	UpdatedAt           time.Time            `json:"updatedAt,omitempty"`
	// contains filtered or unexported fields
}

type DeviceType

type DeviceType struct {
	Uuid             string   `json:"uuid,omitempty"`
	ProjectID        string   `json:"projectId"`
	Visibility       string   `json:"visibility,omitempty"`
	Encoder          string   `json:"encoder,omitempty"`
	Decoder          string   `json:"decoder,omitempty"`
	FirmwareID       string   `json:"firmwareId,omitempty"`
	FirmwareVersions []string `json:"firmwareVersions"`
	Model            string   `json:"model,omitempty"`
	Manufacturer     string   `json:"manufacturer,omitempty"`
	Category         string   `json:"category,omitempty"`
	Name             string   `json:"name"`
	Description      string   `json:"description,omitempty"`
	Protocols        *struct {
		Modbus *DeviceTypeModbusProtocol `json:"modbus,omitempty"`
		Knx    *DeviceTypeKnxProtocol    `json:"knx,omitempty"`
	} `json:"protocols,omitempty"`
	Metadata   map[string]any `json:"metadata"`
	Commands   any            `json:"commands"`
	Events     any            `json:"events"`
	Properties any            `json:"properties"`
	CreatedAt  time.Time      `json:"createdAt,omitempty"`
	UpdatedAt  time.Time      `json:"updatedAt,omitempty"`
	// contains filtered or unexported fields
}

type DeviceTypeKnxProtocol added in v1.8.2

type DeviceTypeKnxProtocol struct {
	Properties map[string]struct {
		Address    string `json:"address"`
		SendDPT    string `json:"sendDPT"`
		ReceiveDPT string `json:"receiveDPT"`
	} `json:"properties"`
}

type DeviceTypeModbusProtocol added in v1.8.2

type DeviceTypeModbusProtocol struct {
	Endianness string                     `json:"endianness"`
	Registers  []DeviceTypeModbusRegister `json:"registers"`
}

type DeviceTypeModbusRegister added in v1.8.2

type DeviceTypeModbusRegister struct {
	Register            uint16 `json:"register"`
	ModbusFunctionRead  int    `json:"modbusFunctionRead"`
	ModbusFunctionWrite int    `json:"modbusFunctionWrite,omitempty"`
	Words               byte   `json:"words"`
	BitwiseReading      bool   `json:"bitwiseReading"`
	Properties          []struct {
		Index int    `json:"index"`
		Name  string `json:"name"`
	} `json:"properties"`
	ScaleFactor *float64 `json:"scaleFactor,omitempty"`
	Type        string   `json:"type"`
}

type Event

type Event struct {
	Uuid        string         `json:"uuid,omitempty"`
	ProjectID   string         `json:"projectId"`
	Description string         `json:"description,omitempty"`
	Type        string         `json:"type"`
	EventTime   time.Time      `json:"eventTime,omitempty"`
	Source      string         `json:"source"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	Data        any            `json:"data,omitempty"`
}

type LocationPointSchema

type LocationPointSchema struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type Measure added in v1.8.8

type Measure struct {
	ProjectId string  `json:"projectId"`
	DeviceId  string  `json:"deviceId"`
	Timestamp int64   `json:"timestamp"`
	Name      string  `json:"name"`
	Value     float64 `json:"value"`
}

type Node added in v1.1.0

type Node struct {
	Uuid                string               `json:"uuid,omitempty"`
	ProjectID           string               `json:"projectId"`
	PlantID             string               `json:"plantId,omitempty"`
	Name                string               `json:"name"`
	Model               string               `json:"model,omitempty"`
	NodeTypeID          string               `json:"nodeTypeId,omitempty"`
	SerialNumber        string               `json:"serialNumber,omitempty"`
	Location            *LocationPointSchema `json:"location,omitempty"`
	Protocols           []NodeProtocol       `json:"protocols,omitempty"`
	Metadata            map[string]any       `json:"metadata"`
	ConnectivityStatus  string               `json:"connectivityStatus"`
	LastConnectionAt    string               `json:"lastConnectionAt"`
	LastCommunicationAt string               `json:"lastCommunicationAt"`
	LastDisconnectionAt string               `json:"lastDisconnectionAt"`
	Description         string               `json:"description,omitempty"`
	Tags                []string             `json:"tags"`
	Rules               []string             `json:"rules,omitempty"`
	CreatedAt           time.Time            `json:"createdAt,omitempty"`
	UpdatedAt           time.Time            `json:"updatedAt,omitempty"`
	// contains filtered or unexported fields
}

type NodeProtocol added in v1.6.1

type NodeProtocol struct {
	Uuid          string         `json:"uuid"`
	Name          string         `json:"name"`
	Description   string         `json:"description,omitempty"`
	Metadata      map[string]any `json:"metadata,omitempty"`
	Configuration any            `json:"configuration,omitempty"`
}

type Platform

type Platform struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, uri, apiKey string) Platform

func (Platform) GetProject

func (p Platform) GetProject(uuid string) (Project, error)

func (Platform) GetProjects

func (p Platform) GetProjects() ([]Project, error)

func (*Platform) SetSkipVerify added in v1.10.0

func (p *Platform) SetSkipVerify(value bool)

type Project

type Project struct {
	Uuid          string         `json:"uuid"`
	ProjectId     string         `json:"projectId"`
	Name          string         `json:"name"`
	Metadata      map[string]any `json:"metadata,omitempty"`
	Configuration any            `json:"configuration,omitempty"`
	CreatedAt     time.Time      `json:"createdAt,omitempty"`
	UpdatedAt     time.Time      `json:"updatedAt,omitempty"`
	// contains filtered or unexported fields
}

func (Project) CreateEvent

func (p Project) CreateEvent(event Event) error

func (Project) GetDevice

func (p Project) GetDevice(uuid string) (Device, error)

func (Project) GetDeviceType added in v1.2.0

func (p Project) GetDeviceType(uuid string) (DeviceType, error)

func (Project) GetDeviceTypes added in v1.2.0

func (p Project) GetDeviceTypes() ([]DeviceType, error)

func (Project) GetDevices

func (p Project) GetDevices() ([]Device, error)

func (Project) GetNode added in v1.1.0

func (p Project) GetNode(uuid string) (Node, error)

func (Project) GetNodes added in v1.1.0

func (p Project) GetNodes() ([]Node, error)

func (Project) GetRule added in v1.8.6

func (p Project) GetRule(uuid string) (Rule, error)

func (Project) GetRules added in v1.8.6

func (p Project) GetRules() ([]Rule, error)

type Response

type Response[T any] struct {
	Status bool `json:"status,omitempty"`
	Data   T    `json:"data,omitempty"`
}

type ResponseError

type ResponseError struct {
	Status bool                `json:"status,omitempty"`
	Error  ResponseErrorDetail `json:"error,omitempty"`
}

type ResponseErrorDetail

type ResponseErrorDetail struct {
	Name       string `json:"name,omitempty"`
	StatusCode int    `json:"statusCode,omitempty"`
	Message    string `json:"message,omitempty"`
	Type       string `json:"type,omitempty"`
}

type Rule added in v1.8.6

type Rule struct {
	Uuid            string         `json:"uuid"`
	ProjectId       string         `json:"projectId"`
	Name            string         `json:"name"`
	Description     *string        `json:"description,omitempty"`
	Metadata        map[string]any `json:"metadata,omitempty"`
	Tags            []string       `json:"tags,omitempty"`
	Status          string         `json:"status"`
	AllowConcurrent bool           `json:"allowConcurrent"`
	Mode            string         `json:"mode"`
	Triggers        []RuleTrigger  `json:"triggers"`
	Actions         []RuleAction   `json:"actions"`
	ElseActions     []RuleAction   `json:"elseActions"`
	Condition       *RuleCondition `json:"condition,omitempty"`
	// contains filtered or unexported fields
}

type RuleAction added in v1.8.6

type RuleAction struct {
	Type string `json:"type"`
	// Type wasm
	Label    *string `json:"label,omitempty"`
	Language *string `json:"language,omitempty"`
	Source   *string `json:"source,omitempty"`
	Binary   *string `json:"binary,omitempty"`
	Hash     *string `json:"hash,omitempty"`
	// Type log
	Value *string `json:"value,omitempty"`
	// Type webhook
	Uri     *string `json:"uri,omitempty"`
	Payload *string `json:"payload,omitempty"`
	// Type command
	Command  map[string]any `json:"command,omitempty"`
	DeviceId *string        `json:"deviceId,omitempty"`
	// Type delay
	Time *int64 `json:"time,omitempty"`
}

type RuleCondition added in v1.8.6

type RuleCondition struct {
	Devices   map[string]string `json:"devices"`
	Condition string            `json:"condition"`
	Deadline  *int              `json:"deadline,omitempty"`
}

type RuleTrigger added in v1.8.6

type RuleTrigger struct {
	Type     string  `json:"type"`
	DeviceId *string `json:"deviceId,omitempty"`
	Property *string `json:"property,omitempty"`
	Crontab  *string `json:"crontab,omitempty"`
	Topic    *string `json:"topic,omitempty"`
}

Jump to

Keyboard shortcuts

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