gateway

package module
v0.0.0-...-1e4dab5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

README

gateway-go-sdk

Go Doc Go Report

Golang SDK for DevIoT gateway service

Documentation

Index

Constants

View Source
const (
	// PropertyTypeInt represents number type of a property
	PropertyTypeInt = 0
	// PropertyTypeString represents string type of a property
	PropertyTypeString = 1
	// PropertyTypeBool represents boolean type of a property
	PropertyTypeBool = 2
	// PropertyTypeColor represents color type of a property
	PropertyTypeColor = 3
)
View Source
const GatewayModeHttpPull = 0

GatewayModeHttpPull connect to DevIoT using pull based HTTP protocol

View Source
const GatewayModeHttpPush = 1

GatewayModeHttpPush connect to DevIoT using push based HTTP protocol

View Source
const GatewayModeMqtt = 2

GatewayModeMqtt connect to DevIoT using MQTT protocol

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name       string     `json:"name,omitempty"`
	Parameters []Property `json:"parameters,omitempty"`
}

Action represents a action model in DevIoT

func (*Action) AddParameter

func (a *Action) AddParameter(p Property) *Action

AddParameter add a parameter to action model

type Connector

type Connector interface {
	Start() error
	Stop() error
	Publish(data map[string]interface{}) error
}

Connector represents a connector

type Gateway

type Gateway struct {
	Name    string             `json:"name"`
	Kind    string             `json:"kind,omitempty"`
	Host    string             `json:"host,omitempty"`
	Port    int                `json:"port,omitempty"`
	Data    string             `json:"data,omitempty"`
	Action  string             `json:"action,omitempty"`
	Account string             `json:"owner,omitempty"`
	Mode    int                `json:"mode"`
	Things  map[string]wrapper `json:"sensors,omitempty"`
	Logger  *log.Logger
	// contains filtered or unexported fields
}

Gateway represents gateway service

func NewGateway

func NewGateway(name string, deviotServer string, connectorServer string, account string, opts map[string]interface{}) (*Gateway, error)

NewGateway create a gateway service

func (*Gateway) CallAction

func (g *Gateway) CallAction(data map[string]interface{})

CallAction call an action on thing

func (*Gateway) Deregister

func (g *Gateway) Deregister(id string)

Deregister a thing from gateway service

func (*Gateway) IsRegistered

func (g *Gateway) IsRegistered() bool

IsRegistered check if gateway service has been registered to DevIoT

func (*Gateway) Register

func (g *Gateway) Register(id string, name string, instance Instance)

Register a thing to gateway service

func (*Gateway) SendData

func (g *Gateway) SendData(data map[string]interface{}) error

SendData send data to DevIoT server

func (*Gateway) Start

func (g *Gateway) Start() error

Start gateway service and register it to DevIoT server

func (*Gateway) Stop

func (g *Gateway) Stop() error

Stop gateway service

type Instance

type Instance interface {
	Init(thing *Thing)
}

Instance represents a thing instance can be registered to DevIoT

type MqttConnector

type MqttConnector struct {
	DataTopic   string
	ActionTopic string
	// contains filtered or unexported fields
}

MqttConnector represents mqtt based connector

func NewMqttConnector

func NewMqttConnector(gateway *Gateway, connectorServer string) (*MqttConnector, error)

NewMqttConnector create a mqtt based connector

func (*MqttConnector) Publish

func (c *MqttConnector) Publish(data map[string]interface{}) error

Publish to DevioT server

func (*MqttConnector) Start

func (c *MqttConnector) Start() error

Start mqtt connector

func (*MqttConnector) Stop

func (c *MqttConnector) Stop() error

Stop mqtt connector

type Property

type Property struct {
	Name        string        `json:"name"`
	Type        int           `json:"type"`
	Value       interface{}   `json:"value,omitempty"`
	Range       []interface{} `json:"range,omitempty"`
	Unit        string        `json:"unit,omitempty"`
	Description string        `json:"description,omitempty"`
}

Property represents a property model in DevIoT

type Thing

type Thing struct {
	Id         string     `json:"id"`
	Name       string     `json:"name"`
	Kind       string     `json:"kind,omitempty"`
	Actions    []Action   `json:"actions,omitempty"`
	Properties []Property `json:"properties,omitempty"`
}

Thing represents a thing model in DevIoT

func (*Thing) AddAction

func (t *Thing) AddAction(a Action) *Thing

AddAction add an action to thing model

func (*Thing) AddProperty

func (t *Thing) AddProperty(p Property) *Thing

AddProperty add a property to thing model

func (*Thing) FindAction

func (t *Thing) FindAction(name string) (*Action, bool)

FindAction find action definition by name

Jump to

Keyboard shortcuts

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