aliyuniot

package module
v0.0.0-...-32d9e5c Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 10 Imported by: 0

README

aliyun iot device sdk for golang

write this for personal use after consulted aliyun-iot-device-sdk

可以用于开发私人网关,架设在路由器中运行,支持更新和发布属性。

Sample

    dev := iot.NewDevice(cnf)
    if err := dev.Connect(); err != nil {
        logger.Log("error on connecting:", err.Error())
        return
    }
    logger.Log("msg", "connected.")
    if err := dev.SubscribePropertyMessage(onReceiveMessage); err != nil {
        logger.Log("error on subscribe property message:", err.Error())
        return
    }
    logger.Log("msg", "subscrib property message.")

更多的用例参考sample文件夹, 有需求可以提Issues

Todo

  • 和云端建立连接
  • 通过云端验证
  • 上报物模型属性
  • 监听物模型属性
  • [] 上报物模型事件
  • 上报自定义topic
  • 订阅自定义topic

Documentation

Index

Constants

View Source
const (
	DefaultRegionID = "cn-shanghai"
	BrokerURL       = "%s%s.iot-as-mqtt.%s.aliyuncs.com:%d"
)
View Source
const (
	DefaultProtocol = ProtocolWS
	ProtocolWS      = "ws://"
	ProtocolTCP     = "tcp://"
	ProtocolTLS     = "tls://"
	ProtocolWSS     = "wss://"
)
View Source
const (
	ServiceTopic           = "/sys/%s/%s/thing/service/%s"
	PropertyPostTopic      = "/sys/%s/%s/thing/event/property/post"
	PropertyPostReplyTopic = "/sys/%s/%s/thing/event/property/post_reply"
	EventPostTopic         = "/sys/%s/%s/thing/event/%s/post"
	EventPostReplyTopic    = "/sys/%s/%s/thing/event/%s/post_reply"
)
View Source
const (
	DefaultSignAlgorithm = HMACSHA1
	HMACSHA1             = "sha1"
	HMACSHA256           = "sha256"
)

Variables

View Source
var (
	PostProperty             = "thing.event.property.post"
	PostEvent                = "thing.event.%s.post"
	ThingServiceMethodPrefix = "thing.service."
)

Functions

This section is empty.

Types

type Device

type Device interface {
	Connect() error
	// SendProperty send property message to aliyun
	// params maybe struct or map[string]interface{}
	SendProperty(params interface{}) error
	SubscribePropertyMessage(callback mqtt.MessageHandler) error
	Publish(topic string, qos byte, retained bool, message string) error
	Subscribe(topic string, qos byte, callback mqtt.MessageHandler) error
}

func NewDevice

func NewDevice(conf DeviceConfig) Device

NewDevice create new aliyun iot device from device config

type DeviceConfig

type DeviceConfig struct {
	RegionID      string
	SignAlgorithm string
	ProductKey    string
	DeviceName    string
	DeviceSecret  string
	BrokerURL     string
	ClientID      string
	TLS           bool
	Websocket     bool
}

type Logger

type Logger interface {
	Log(keyvals ...interface{}) error
}

Logger is the fundamental interface for all log operations. Log creates a log event from keyvals, a variadic sequence of alternating keys and values. Implementations must be safe for concurrent use by multiple goroutines. In particular, any implementation of Logger that appends to keyvals or modifies or retains any of its elements must make a copy first. from github.com/go-kit/kit/log

var (
	Error    Logger = &NOOPLogger{}
	Critical Logger = &NOOPLogger{}
	Warning  Logger = &NOOPLogger{}
	Debug    Logger = &NOOPLogger{}
)

Internal levels of library output that are initialised to not print anything but can be overridden by programmer

type NOOPLogger

type NOOPLogger struct{}

NOOPLogger implements the logger that does not perform any operation by default. This allows us to efficiently discard the unwanted messages.

func (*NOOPLogger) Log

func (l *NOOPLogger) Log(keyvals ...interface{}) error

Log do nothing

type Params

type Params map[string]interface{}

type PropertyMsg

type PropertyMsg struct {
	ID      int         `json:"id"`
	Version string      `json:"version"`
	Params  interface{} `json:"params"`
	Method  string      `json:"method"`
}

Directories

Path Synopsis
sample

Jump to

Keyboard shortcuts

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