client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAbnormalEvent

func NewAbnormalEvent(args ...string) Event

func NewBootstrappedEvent

func NewBootstrappedEvent(args ...string) Event

func NewDeviceChangedEvent

func NewDeviceChangedEvent(args ...string) Event

func NewInfoObservedEvent

func NewInfoObservedEvent(args ...string) Event

func NewInfoReportedEvent

func NewInfoReportedEvent(args ...string) Event

func NewRegUpdatedEvent

func NewRegUpdatedEvent(args ...string) Event

func NewRegisteredEvent

func NewRegisteredEvent(args ...string) Event

func NewUnregisteredEvent

func NewUnregisteredEvent(args ...string) Event

Types

type AbnormalEvent

type AbnormalEvent struct {
	*BaseEvent
}

type BootstrapOption added in v0.2.0

type BootstrapOption = func(b *Bootstrapper)

func WithBootstrapInfo added in v0.2.0

func WithServerInfo added in v0.2.0

func WithServerInfo(s *ServerInfo) BootstrapOption

type BootstrappedEvent

type BootstrappedEvent struct {
	*BaseEvent
}

type Bootstrapper

type Bootstrapper struct {
	*meta.StateMachine[state]
	// contains filtered or unexported fields
}

Bootstrapper implements the "Client Initiated Bootstrap" mode defined in Bootstrap interface.

func NewBootstrapper

func NewBootstrapper(client *LwM2MClient, opts ...BootstrapOption) *Bootstrapper

func (*Bootstrapper) BootstrapServerBootstrapInfo

func (r *Bootstrapper) BootstrapServerBootstrapInfo() *core.BootstrapServerBootstrapInfo

func (*Bootstrapper) Bootstrapped

func (r *Bootstrapper) Bootstrapped() bool

func (*Bootstrapper) OnDelete

func (r *Bootstrapper) OnDelete() error

func (*Bootstrapper) OnDiscover

func (r *Bootstrapper) OnDiscover() (*core.ResourceField, error)

func (*Bootstrapper) OnFinish

func (r *Bootstrapper) OnFinish() error

func (*Bootstrapper) OnRead

func (r *Bootstrapper) OnRead() (*core.ResourceField, error)

func (*Bootstrapper) OnWrite

func (r *Bootstrapper) OnWrite() error

func (*Bootstrapper) PackRequest

func (r *Bootstrapper) PackRequest() error

PackRequest implements BootstrapPackRequest operation

method: GET
format: SenML CBOR, SenML JSON, or LwM2M CBOR
path: /bspack?ep={Endpoint Client Name}
code may be responded:
 2.05 Content The response includes the Bootstrap-Pack.
 4.00 Bad Request Undetermined error occurred
 4.01 Unauthorized Access Right Permission Denied
 4.04 Not Found URI of "Bootstrap-Pack-Request" operation is not found
 4.05 Method Not Allowed The LwM2M Client is not allowed for "Bootstrap-Pack-Request" operation
 4.06 Not Acceptable The specified Content-Format is not supported
 5.01 Not Implemented The operation is not implemented.

func (*Bootstrapper) Request

func (r *Bootstrapper) Request() error

Request implements BootstrapRequest operation

method: POST
path: /bs?ep={Endpoint Client Name}&pct={Preferred Content Format}
code may be responded:
 2.04 Changed Bootstrap-Request is completed successfully
 4.00 Bad Request Unknown Endpoint Client Name
	   Endpoint Client Name does not match with CN field of X.509 Certificates
 4.15 Unsupported content format The specified format is not supported

func (*Bootstrapper) SetBootstrapServerBootstrapInfo

func (r *Bootstrapper) SetBootstrapServerBootstrapInfo(info *core.BootstrapServerBootstrapInfo)

SetBootstrapServerBootstrapInfo set the pre-provisioned bootstrap server account as depicted: In order for the LwM2M Client and the LwM2M Bootstrap-Server to establish a connection on the Bootstrap Interface, either in Client Initiated Bootstrap mode or in Server Initiated Bootstrap mode, the LwM2M Client MUST have an LwM2M Bootstrap-Server Account pre-provisioned.

func (*Bootstrapper) Start

func (r *Bootstrapper) Start() bool

func (*Bootstrapper) Stop

func (r *Bootstrapper) Stop()

func (*Bootstrapper) Timeout

func (r *Bootstrapper) Timeout() bool

type Client

type Client interface {
	// OnEvent adds an event listener for the specified
	// event, and overwrites the old if already exists.
	OnEvent(et core.EventType, h core.EventHandler)

	Send(data []byte) ([]byte, error)
	Notify(somebody string, something []byte) error
}

Client defines api for application layer to use.

Procedures, initiated by the client side applications will be exposed, including:

Send of Information Reporting

Procedures, initiated by the server but not terminated within the LwM2M protocol layer, will be exposed to client side applications by methods defined here too:

Create/Read/Write/Execute of DeviceManagement & Service Enablement
Observe of Information Reporting

Event listeners are also supported to acquire client states including bootstrapping results, registration results etc.

type DeviceChangedEvent

type DeviceChangedEvent struct {
	*BaseEvent
}

type DeviceController

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

func NewDeviceController

func NewDeviceController(c *LwM2MClient) *DeviceController

func (*DeviceController) OnCreate

func (d *DeviceController) OnCreate(specifyOId core.ObjectID, newValue []byte) error

func (*DeviceController) OnDelete

func (d *DeviceController) OnDelete(oid core.ObjectID, instId core.InstanceID, resId core.ResourceID, resInstId core.InstanceID) error

func (*DeviceController) OnDiscover

func (d *DeviceController) OnDiscover(oid core.ObjectID, instId core.InstanceID, resId core.ResourceID, depth int) error

func (*DeviceController) OnExecute

func (d *DeviceController) OnExecute(oid core.ObjectID, instId core.InstanceID, resId core.ResourceID, args string) error

func (*DeviceController) OnPack added in v0.2.0

func (d *DeviceController) OnPack(newValue []byte) error

OnPack The LwM2M client MUST delete the existing Objects and their Instances in the client with the Objects and their Instances given in the "Bootstrap-Pack" if the Object IDs are the same. Object IDs available in the LwM2M Client which are not provided in the "Bootstrap-Pack" MUST NOT be deleted. The two exceptions are the LwM2M Bootstrap-Server Account, potentially including an associated Instance of an OSCORE Object ID:21, and the single Instance of the mandatory Device Object (ID:3), which are not affected by any Delete operation. Thus, when checking the configuration consistency, the LwM2M Client MUST ensure that the LwM2M Bootstrap-Server Account is still present.

func (*DeviceController) OnRead

func (d *DeviceController) OnRead(oid core.ObjectID, instId core.InstanceID, resId core.ResourceID, resInstId core.InstanceID) ([]byte, error)

func (*DeviceController) OnWrite

func (d *DeviceController) OnWrite(
	oid core.ObjectID,
	instId core.InstanceID,
	resId core.ResourceID,
	resInstId core.InstanceID,
	newValue []byte) ([]byte, error)

type InfoObservedEvent

type InfoObservedEvent struct {
	*BaseEvent
}

type InfoReportedEvent

type InfoReportedEvent struct {
	*BaseEvent
}

type LwM2MClient

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

LwM2MClient implements client side functionalities and exposes API to applications using callbacks.

func New

func New(name string, store ObjectInstanceStore, opts ...Option) *LwM2MClient

New returns a LwM2M client with the mandatory name and other options, or nil when any failure occurred.

func (*LwM2MClient) EnableInstance

func (c *LwM2MClient) EnableInstance(oid ObjectID, ids ...InstanceID)

func (*LwM2MClient) EnableInstances

func (c *LwM2MClient) EnableInstances(m InstanceIdsMap)

func (*LwM2MClient) Notify

func (c *LwM2MClient) Notify(somebody string, something []byte) error

func (*LwM2MClient) OnEvent

func (c *LwM2MClient) OnEvent(et EventType, h EventHandler)

func (*LwM2MClient) Send

func (c *LwM2MClient) Send(data []byte) ([]byte, error)

func (*LwM2MClient) Servicing

func (c *LwM2MClient) Servicing() bool

func (*LwM2MClient) SetOperator

func (c *LwM2MClient) SetOperator(oid ObjectID, operator Operator)

func (*LwM2MClient) SetOperators

func (c *LwM2MClient) SetOperators(operators OperatorMap)

func (*LwM2MClient) Start

func (c *LwM2MClient) Start() bool

Start runs the client's state-driven loop.

func (*LwM2MClient) Stop

func (c *LwM2MClient) Stop()

type MessagerClient

type MessagerClient struct {
	coap.Client
	// contains filtered or unexported fields
}

func NewMessager

func NewMessager(c *LwM2MClient) *MessagerClient

func (*MessagerClient) Close

func (m *MessagerClient) Close() error

func (*MessagerClient) Connected

func (m *MessagerClient) Connected() bool

func (*MessagerClient) Deregister

func (m *MessagerClient) Deregister(info *regInfo) error

func (*MessagerClient) Dial

func (m *MessagerClient) Dial(addr string, opts ...coap.PeerOption) error

func (*MessagerClient) PauseUserPlane

func (m *MessagerClient) PauseUserPlane()

PauseUserPlane stops accepting requests from servers.

func (*MessagerClient) Redial

func (m *MessagerClient) Redial(addr string, opts ...coap.PeerOption) error

func (*MessagerClient) Register

func (m *MessagerClient) Register(info *regInfo) error

func (*MessagerClient) ResumeUserPlane

func (m *MessagerClient) ResumeUserPlane()

ResumeUserPlane resumes accepting requests from servers.

func (*MessagerClient) Start

func (m *MessagerClient) Start()

func (*MessagerClient) Update

func (m *MessagerClient) Update(info *regInfo, params ...string) error

type Observation

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

type Observer

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

Observer manages observations across registrations.

type Option

type Option func(*Options)

func WithLocalAddress

func WithLocalAddress(local string) Option

WithLocalAddress provides local address as a hint. If not provided or the hinted address cannot be set the default address ":0" is used.

func WithObjectClassRegistry

func WithObjectClassRegistry(registry core.ObjectRegistry) Option

func WithServerRecvTimeout

func WithServerRecvTimeout(timeout time.Duration) Option

func WithServerSendTimeout

func WithServerSendTimeout(timeout time.Duration) Option

type Options

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

Options defines client options.

type RegUpdatedEvent

type RegUpdatedEvent struct {
	*BaseEvent
}

type RegisteredEvent

type RegisteredEvent struct {
	*BaseEvent
}

type Registrar

type Registrar struct {
	*meta.StateMachine[state]
	// contains filtered or unexported fields
}

Registrar implements application layer logic for client registration procedure at server side.

func NewRegistrar

func NewRegistrar(client *LwM2MClient) *Registrar

func (*Registrar) Deregister

func (r *Registrar) Deregister() error

Deregister request with parameters like:

 method: DELETE
 uri: /{location}
	 where location has a format of /rd/{id}

func (*Registrar) Register

func (r *Registrar) Register() error

Register encapsulates request payload containing objects and instances and requests according to the following:

method: POST
uri: /rd?ep={Endpoint Client Name}&lt={Lifetime}
        &lwm2m={version}&b={binding}&Q&sms={MSISDN}&pid={ProfileID}
   b/Q/sms/pid are optional.
body: </1/0>,... which is optional.

func (*Registrar) Registered

func (r *Registrar) Registered() bool

func (*Registrar) Start

func (r *Registrar) Start() bool

func (*Registrar) Stop

func (r *Registrar) Stop()

func (*Registrar) Timeout

func (r *Registrar) Timeout() bool

func (*Registrar) Update

func (r *Registrar) Update(params ...string) error

Update requests with parameters like:

method: POST
uri: /{location}?lt={Lifetime}&b={binding}&Q&sms={MSISDN}
	where location has a format of /rd/{id} and b/Q/sms are optional.
body: </1/0>,... which is optional.

type Reporter

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

Reporter implements information reporting functionalities of the lwm2m protocol. Unlike other interface implementations, reporter has no standalone loop embedded.

func NewReporter

func NewReporter(c *LwM2MClient) *Reporter

func (*Reporter) FailureCounter

func (r *Reporter) FailureCounter() int32

func (*Reporter) Notify

func (r *Reporter) Notify(observationId string, value []byte) error

func (*Reporter) OnCancelObservation

func (r *Reporter) OnCancelObservation(observationId string) error

func (*Reporter) OnCancelObservationComposite

func (r *Reporter) OnCancelObservationComposite() error

func (*Reporter) OnObserve

func (r *Reporter) OnObserve(observationId string, attrs core.NotificationAttrs) error

func (*Reporter) OnObserveComposite

func (r *Reporter) OnObserveComposite() error

func (*Reporter) Send

func (r *Reporter) Send(value []byte) ([]byte, error)

type ServerInfo added in v0.2.0

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

type UnregisteredEvent

type UnregisteredEvent struct {
	*BaseEvent
}

Jump to

Keyboard shortcuts

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