oceanconnect

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

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

Go to latest
Published: Dec 17, 2017 License: MIT Imports: 16 Imported by: 0

README

OceanConnect

Build Status Go Report Card GoDoc codecov

OceanConnect is the platform developed by Huawei for the use with NB-IOT devices.

NB-IOT is a LPWAN technology for bi-directional data traffic between devices and centralized cloud platforms. OceanConnect is the gateway for these devices.

This library uses the API of OceanConnect to retrieve data and register devices.

NOTE: The API is currently unstable

Installation

To get started please get the Golang toolchains from the Golang website. When you have a working go toolchain you can do:

go get github.com/dualinventive/go-oceanconnect

And you are ready to go!

Included tools

Some simple tools for use with ocean-connect are included and located in the cmd folder of the root of the project.

Register devices (regdevices)

Commandline tool to register devices at OceanConnect. See the readme in the designated folder.

Contributing

Please read the Contribution Guidelines. Furthermore: Fork -> Patch -> Push -> Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client struct that contains pointer to http client

func NewClient

func NewClient(c Config) (*Client, error)

NewClient creates new client with certification

func (*Client) GetDevice

func (c *Client) GetDevice(deviceID string) (*Device, error)

func (*Client) GetDevices

func (c *Client) GetDevices(dev GetDevicesStruct) ([]Device, error)

GetDevices returns struct with devices

func (*Client) Login

func (c *Client) Login() error

Login with the client to oceanconnect

func (*Client) RegisterDevice

func (c *Client) RegisterDevice(imei string, timeoutV ...uint) (*RegistrationReply, error)

RegisterDevice registers a device with a corresponding IMEI number

func (*Client) SetDeviceInfo

func (c *Client) SetDeviceInfo(deviceID, name string) error

func (*Client) Subscribe

func (c *Client) Subscribe(url string) (*Server, error)

Subscribe to notifications

type Config

type Config struct {
	CertFile    string `yaml:"cert_file"` // CertFile is the path to the PEM client certificate
	CertKeyFile string `yaml:"key_file"`  // CertKeyFile is the path to the PEM client certificate public key
	URL         string `yaml:"url"`       // URL where the Oceanconnect API is present
	AppID       string `yaml:"app_id"`    // AppID is the application Identifier
	Secret      string `yaml:"secret"`

	ManufacturerName string `yaml:"manufacturer_name"`
	ManufacturerID   string `yaml:"manufacturer_id"`
	EndUserID        string `yaml:"end_user_id"`
	Location         string `yaml:"location"`
	DeviceType       string `yaml:"device_type"`
	Model            string `yaml:"model"`
}

Config struct for client configuration

type Device

type Device struct {
	DeviceID         string     `json:"deviceId"`
	GatewayID        string     `json:"gatewayId"`
	NodeType         string     `json:"nodeType"`
	CreateTime       OcTime     `json:"creationTime"`
	LastModifiedTime OcTime     `json:"lastModifiedTime"`
	DeviceInfo       DeviceInfo `json:"deviceInfo"`
	Services         []Service  `json:"services"`
	// contains filtered or unexported fields
}

Device struct with device data

func (*Device) Command

func (d *Device) Command(data []byte, timeoutSec int64) error

func (*Device) GetHistoricalData

func (d *Device) GetHistoricalData() ([]DeviceData, error)

GetHistoricalData returns data from specific device

type DeviceData

type DeviceData struct {
	DeviceID  string
	GatewayID string
	Appid     string
	ServiceIS string
	Data      []byte `json:"data"`
	Timestamp OcTime
}

DeviceData struct with response data

func (*DeviceData) UnmarshalJSON

func (u *DeviceData) UnmarshalJSON(data []byte) error

type DeviceDataChanged

type DeviceDataChanged struct {
	DeviceID  string
	GatewayID string
	RequestID string
	Service   Service `json:"service"`
}

DeviceDataChanged struct with device data

type DeviceInfo

type DeviceInfo struct {
	NodeID            string
	Name              string
	Description       string
	ManufacturerID    string
	ManufacturerName  string
	Mac               string
	Location          string
	DeviceType        string
	Model             string
	Swversion         string
	FwVersion         string
	HwVersion         string
	ProtocolType      string
	BridgeID          string
	Status            string
	StatusDetail      string
	Mute              string
	SupportedSecurity string
	IsSecurity        string
	SignalStrength    string
	SigVersion        string
	SerialNumber      string
}

DeviceInfo struct with device info data

type GetDevicesStruct

type GetDevicesStruct struct {
	GatewayID string
	NodeType  string
	PageNo    int
	PageSize  int
	Status    string
	StartTime string
	EndTime   string
	Sort      string
}

GetDevicesStruct struct for function GetDevices

type Notification

type Notification string
const (
	// NotificationDeviceAdded is used to notify initial device logins.
	// When a device registers with the OceanConnect (the device creates messages on
	// the OceanConnect and obtains the password), the OceanConnect sends a
	// notification to the application or a new device is added to the gateway, the
	// OceanConnect invokes this interface to send a notification to the application.
	NotificationDeviceAdded Notification = "deviceAdded"
	// NotificationDeviceInfoChanged is used after receiving device information changes
	// (changes of static information such as the device name and manufacturer ID).
	NotificationDeviceInfoChanged Notification = "deviceInfoChanged"
	// NotificationDeviceDataChanged is used after receiving device data changes
	// (dynamic changes such as changes of service attribute values).
	NotificationDeviceDataChanged Notification = "deviceDataChanged"
	// NotificationDeviceDeleted is used when learning that a
	// non-directly-connected device is deleted
	NotificationDeviceDeleted Notification = "deviceDeleted"
	// NotificationMessageConfirm is used after receiving an acknowledgment
	// message from the gateway, for example, the OceanConnect sends a command
	// to the gateway and the gateway acknowledges the message.
	NotificationMessageConfirm Notification = "messageConfirm"
	// NotificationCommandResponse is used after receiving a response command
	// from a device (gateway or common device), for example, the OceanConnect sends a
	// command to the device and the device returns a response command after running the
	// command, such as video call, video recording, and screenshot
	NotificationCommandResponse Notification = "commandRsp"
	// NotificationDeviceEvent after receiving an event (for example, insufficient
	// UDS storage space) from a device
	NotificationDeviceEvent Notification = "deviceEvent"
	// NotificationServiceInfoChanged is sent when learning device service information
	// changes, the OceanConnect invokes this interface to send a notification to the
	// application.
	NotificationServiceInfoChanged Notification = "serviceInfoChanged"
	// NotificationRuleEvent is used when generates the corresponding rule event
	// notification to NA when the rule is triggered
	NotificationRuleEvent Notification = "ruleEvent"
)

type NotificationFunc

type NotificationFunc func(interface{}) error

type OcTime

type OcTime struct {
	time.Time
}

OcTime is used for unmarshalling the times communicated via the API to time.Time

func (*OcTime) UnmarshalJSON

func (ct *OcTime) UnmarshalJSON(b []byte) error

UnmarshalJSON reads the times to time.Time

type RegistrationReply

type RegistrationReply struct {
	VerifyCode string `json:"verifyCode"`
	DeviceID   string `json:"deviceId"`
	Timeout    uint   `json:"timeout"`
	Psk        string `json:"psk"`
}

RegistrationReply for RegisterDevice

type Server

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

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(uri string) error

func (*Server) RegisterCallback

func (s *Server) RegisterCallback(not Notification, cb NotificationFunc)

type Service

type Service struct {
	ServiceID   string
	ServiceType string
	Data        []byte `json:"data"`
	EventTime   OcTime
	ServiceInfo string `json:",omitEmpty"`
}

Service struct which holds service information data

func (*Service) UnmarshalJSON

func (u *Service) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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