goplatform

package module
v2.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 14 Imported by: 0

README

Golang version License CI

GoPlatform

An SDK for Apio Platform in Golang.

Install
go get github.com/ApioIoT/goplatform/v2
Get Projects
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

projects, err := platform.GetProjects(context.TODO())
if err != nil {
  panic(err)
}
Get Project
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}
Get Nodes
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

nodes, err := project.GetNodes(context.TODO())
if err != nil {
  panic(err)
}
Get Node
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

node, err := project.GetNode(context.TODO(), "my-node-id")
if err != nil {
  panic(err)
}
Get Devices
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

devices, err := project.GetDevices(context.TODO())
if err != nil {
  panic(err)
}
Get Device
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

device, err := project.GetDevice(context.TODO(), "my-device-id")
if err != nil {
  panic(err)
}
Get DeviceTypes
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

devices, err := project.GetDeviceTypes(context.TODO())
if err != nil {
  panic(err)
}
Get DeviceType
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

deviceType, err := project.GetDeviceType(context.TODO(), "my-device-type-id")
if err != nil {
  panic(err)
}
Create Event
platform := goplatform.New(goplatform.Config{
  Uri:    "platform-uri",
  ApiKey: "my-api-key",
})

project, err := platform.GetProject(context.TODO(), "my-project-id")
if err != nil {
  panic(err)
}

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

if err := project.CreateEvent(context.TODO(), event); err != nil {
  panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Uuid           string                `json:"uuid"`
	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"`
	Status         CommandStatus         `json:"status"`
	DownlinkRetry  *DownlinkRetryOption  `json:"downlinkRetry,omitempty"`
	ExecutionRetry *ExecutionRetryOption `json:"executionRetry,omitempty"`
	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 CommandAck

type CommandAck struct {
	Uuid   string         `json:"uuid"`
	Status CommandStatus  `json:"status"`
	Extras map[string]any `json:"-"`
}

func (CommandAck) MarshalJSON

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

func (*CommandAck) UnmarshalJSON

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

type CommandParameter

type CommandParameter map[string]any

type CommandParameters

type CommandParameters []CommandParameter

func (CommandParameters) MarshalJSON

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

func (*CommandParameters) UnmarshalJSON

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

type CommandRequest

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"`
	DownlinkRetry  *CommandRequestRetryOption `json:"downlinkRetry,omitempty"`
	ExecutionRetry *CommandRequestRetryOption `json:"executionRetry,omitempty"`
}

func (CommandRequest) MakeCommand

func (c CommandRequest) MakeCommand(status ...CommandStatus) Command

type CommandRequestRetryOption

type CommandRequestRetryOption struct {
	MaxRetries *int `json:"maxRetries,omitempty"`
}

type CommandStatus

type CommandStatus string
const (
	CMD_STATUS_PENDING   CommandStatus = "pending"
	CMD_STATUS_RECEIVED  CommandStatus = "received"
	CMD_STATUS_COMPLETED CommandStatus = "completed"
	CMD_STATUS_FAILED    CommandStatus = "failed"
)

type Config

type Config struct {
	Uri        string
	ApiKey     string
	SkipVerify bool
}

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

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

type DeviceTypeModbusProtocol

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

type DeviceTypeModbusRegister

type DeviceTypeModbusRegister struct {
	Register            uint16 `json:"register"`
	Read                bool   `json:"read"`
	ModbusFunctionRead  int    `json:"modbusFunctionRead"`
	Write               bool   `json:"write"`
	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 DownlinkRetryOption

type DownlinkRetryOption struct {
	MaxRetries  *int       `json:"maxRetries,omitempty"`
	RetryCount  *int       `json:"retryCount,omitempty"`
	NextRetryAt *time.Time `json:"nextRetryAt,omitempty"`
}

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 ExecutionRetryOption

type ExecutionRetryOption struct {
	MaxRetries *int `json:"maxRetries,omitempty"`
	RetryCount *int `json:"retryCount,omitempty"`
}

type LocationPointSchema

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

type Measure

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

type Node

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"`
	Retry        *struct {
		Enabled          bool    `json:"enabled"`
		MaxRetries       int     `json:"maxRetries"`
		BackoffBase      float64 `json:"backoffBase"`
		BackoffFactor    float64 `json:"backoffFactor"`
		BackoffTimeLimit int     `json:"backoffTimeLimit"`
	} `json:"retry,omitempty"`
	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

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(config Config) Platform

func (Platform) GetProject

func (p Platform) GetProject(ctx context.Context, uuid string) (Project, error)

func (Platform) GetProjects

func (p Platform) GetProjects(ctx context.Context) ([]Project, error)

type Project

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

func (Project) CreateEvent

func (p Project) CreateEvent(ctx context.Context, event Event) error

func (Project) GetDevice

func (p Project) GetDevice(ctx context.Context, uuid string) (Device, error)

func (Project) GetDeviceType

func (p Project) GetDeviceType(ctx context.Context, uuid string) (DeviceType, error)

func (Project) GetDeviceTypes

func (p Project) GetDeviceTypes(ctx context.Context) ([]DeviceType, error)

func (Project) GetDevices

func (p Project) GetDevices(ctx context.Context) ([]Device, error)

func (Project) GetNode

func (p Project) GetNode(ctx context.Context, uuid string) (Node, error)

func (Project) GetNodes

func (p Project) GetNodes(ctx context.Context) ([]Node, error)

func (Project) GetRule

func (p Project) GetRule(ctx context.Context, uuid string) (Rule, error)

func (Project) GetRules

func (p Project) GetRules(ctx context.Context) ([]Rule, error)

func (Project) SendCommand

func (p Project) SendCommand(ctx context.Context, command Command) error

type Rule

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

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

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

type RuleTrigger

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