Documentation
¶
Index ¶
- Constants
- Variables
- func NstartClear(addr string)
- func NstartEntryCount() int
- func ObserveRegister(token string, path string, callback ObserveCallback, arg interface{})
- func ObserveTokens(callback func(string))
- func RspCodeToError(code COAPCode) error
- func SetLogFunc(lf LogFunc)
- func SetLogLevel(level string)
- func SetSniffPacketsCallback(callback SniffPacketsCallback)
- type BlockMetadata
- type COAPCode
- type COAPType
- type Config
- type DtlsListener
- type LogFunc
- type MediaType
- type Message
- func (m *Message) Accept() MediaType
- func (m *Message) ContentFormat() MediaType
- func (m *Message) GetBlock1() *BlockMetadata
- func (m *Message) GetBlock2() *BlockMetadata
- func (m *Message) IsConfirmable() bool
- func (m *Message) IsRequest() bool
- func (m *Message) LocationPath() []string
- func (m *Message) LocationPathString() string
- func (m *Message) MakeReply(code COAPCode, payload []byte) *Message
- func (m *Message) Option(o OptionID) interface{}
- func (m *Message) Options(o OptionID) []interface{}
- func (m *Message) OptionsMap() map[string]interface{}
- func (m *Message) PacketSize() int
- func (m *Message) ParseQuery() map[string]string
- func (m *Message) Path() []string
- func (m *Message) PathString() string
- func (m *Message) QueryString() string
- func (m *Message) RemoveOption(opID OptionID)
- func (m *Message) RequiresBlockwise() bool
- func (m *Message) WithAccept(mt MediaType) *Message
- func (m *Message) WithBlock1(bm *BlockMetadata) *Message
- func (m *Message) WithBlock2(bm *BlockMetadata) *Message
- func (m *Message) WithCode(code COAPCode) *Message
- func (m *Message) WithContentFormat(mt MediaType) *Message
- func (m *Message) WithLocationPath(s []string) *Message
- func (m *Message) WithLocationPathString(path string) *Message
- func (m *Message) WithOption(opID OptionID, val interface{}, replace bool) *Message
- func (m *Message) WithPath(s []string) *Message
- func (m *Message) WithPathString(s string) *Message
- func (m *Message) WithPayload(payload []byte) *Message
- func (m *Message) WithQuery(q map[string]string) *Message
- func (m *Message) WithSize1(sz int) *Message
- func (m *Message) WithSize2(sz int) *Message
- func (m *Message) WithToken(token []byte) *Message
- func (m *Message) WithType(ty COAPType) *Message
- type Metadata
- type Observation
- type ObserveCallback
- type ObserveNotFoundCallback
- type OptionID
- type ProxyFunction
- type RouteCallback
- type SendOptions
- func (so *SendOptions) NoRetry() *SendOptions
- func (so *SendOptions) WithBlockSize(bs int) *SendOptions
- func (so *SendOptions) WithMaxMessageSize(ms int) *SendOptions
- func (so *SendOptions) WithNStart(ns int) *SendOptions
- func (so *SendOptions) WithRetry(count int, timeout time.Duration, randomFactor float64) *SendOptions
- type Server
- func (s *Server) AddRoute(path string, callback RouteCallback)
- func (s *Server) BlockCacheSize() (int64, int64)
- func (s *Server) Close()
- func (s *Server) GetConfig() *Config
- func (s *Server) GetNextMsgId() uint16
- func (s *Server) GetPorts() (int, int)
- func (s *Server) GetRef() any
- func (s *Server) LastActivity() time.Time
- func (s *Server) NewOptions() *SendOptions
- func (s *Server) Observe(addr string, code COAPCode, path string, payload []byte, encoding MediaType, ...) (string, error)
- func (s *Server) ObserveCancel(addr string, path string, token string, options *SendOptions) error
- func (s *Server) ProxySend(prefix string, rawReq []byte, from string) ([]byte, error)
- func (s *Server) Send(addr string, msg *Message, options *SendOptions) (*Message, error)
- type SniffPacketsCallback
- type UdpListener
Constants ¶
View Source
const ( LogLevelError string = "error" LogLevelWarn string = "warn" LogLevelInfo string = "info" LogLevelDebug string = "debug" )
View Source
const ( SniffWrite = "write" SniffRead = "read" )
Variables ¶
View Source
var ( ErrTimeout = errors.New("coap: timeout") ErrBadRequest = errors.New("coap: bad request") ErrNotFound = errors.New("coap: not found") ErrMethodNotAllowed = errors.New("coap: method not allowed") ErrEncodingNotAcceptable = errors.New("coap: encoding not acceptable") ErrInternalServerError = errors.New("coap: internal server error") ErrInvalidTokenLen = errors.New("coap: invalid token length") ErrOptionTooLong = errors.New("coap: option is too long") ErrOptionGapTooLarge = errors.New("coap: option gap too large") )
Functions ¶
func NstartClear ¶ added in v1.6.8
func NstartClear(addr string)
func NstartEntryCount ¶ added in v1.6.15
func NstartEntryCount() int
func ObserveRegister ¶
func ObserveRegister(token string, path string, callback ObserveCallback, arg interface{})
func ObserveTokens ¶
func ObserveTokens(callback func(string))
func RspCodeToError ¶
func SetLogFunc ¶
func SetLogFunc(lf LogFunc)
func SetLogLevel ¶
func SetLogLevel(level string)
func SetSniffPacketsCallback ¶ added in v1.6.6
func SetSniffPacketsCallback(callback SniffPacketsCallback)
Types ¶
type BlockMetadata ¶ added in v1.1.0
func (*BlockMetadata) Encode ¶ added in v1.1.0
func (bm *BlockMetadata) Encode() []byte
type COAPCode ¶
type COAPCode uint8
COAPCode is the type used for both request and response codes.
const ( CodeEmpty COAPCode = 0 CodeGet COAPCode = 1 CodePost COAPCode = 2 CodePut COAPCode = 3 CodeDelete COAPCode = 4 CodeFetch COAPCode = 5 CodePatch COAPCode = 6 CodeIPatch COAPCode = 7 )
Request Codes
const ( RspCodeCreated COAPCode = 65 RspCodeDeleted COAPCode = 66 RspCodeValid COAPCode = 67 RspCodeChanged COAPCode = 68 RspCodeContent COAPCode = 69 RspCodeContinue COAPCode = 95 RspCodeBadRequest COAPCode = 128 RspCodeBadOption COAPCode = 130 RspCodeForbidden COAPCode = 131 RspCodeNotFound COAPCode = 132 RspCodeMethodNotAllowed COAPCode = 133 RspCodeNotAcceptable COAPCode = 134 RspCodeRequestEntityIncomplete COAPCode = 136 RspCodePreconditionFailed COAPCode = 140 RspCodeRequestEntityTooLarge COAPCode = 141 RspCodeUnsupportedMediaType COAPCode = 143 RspCodeInternalServerError COAPCode = 160 RspCodeNotImplemented COAPCode = 161 RspCodeBadGateway COAPCode = 162 RspCodeGatewayTimeout COAPCode = 164 RspCodeProxyingNotSupported COAPCode = 165 )
Response Codes
func ToCOAPCode ¶ added in v1.4.0
func (COAPCode) NumberString ¶ added in v1.4.0
type COAPType ¶
type COAPType uint8
COAPType represents the message type.
const ( // Confirmable messages require acknowledgements. TypeConfirmable COAPType = 0 // NonConfirmable messages do not require acknowledgements. TypeNonConfirmable COAPType = 1 // Acknowledgement is a message indicating a response to confirmable message. TypeAcknowledgement COAPType = 2 // Reset indicates a permanent negative acknowledgement. TypeReset COAPType = 3 )
type Config ¶
type Config struct {
DeduplicateExpiration time.Duration
DeduplicateInterval time.Duration
ObserveNotFoundCallback ObserveNotFoundCallback
BlockDefaultSize int
BlockInactivityTimeout time.Duration
MaxMessageDefaultSize int
NStart int
Name string
Ref any
ProxyCallbacks map[string]ProxyFunction
}
func (*Config) AddProxyReceiver ¶ added in v1.7.1
func (c *Config) AddProxyReceiver(prefix string, f ProxyFunction)
type DtlsListener ¶ added in v1.3.0
type DtlsListener struct {
// contains filtered or unexported fields
}
func (*DtlsListener) Close ¶ added in v1.4.0
func (l *DtlsListener) Close()
func (*DtlsListener) ClosePeer ¶ added in v1.4.8
func (l *DtlsListener) ClosePeer(addr string)
type MediaType ¶
type MediaType int
MediaType specifies the content type of a message.
const ( None MediaType = -1 TextPlain MediaType = 0 // text/plain;charset=utf-8 AppLinkFormat MediaType = 40 // application/link-format AppXML MediaType = 41 // application/xml AppOctets MediaType = 42 // application/octet-stream AppExi MediaType = 47 // application/exi AppJSON MediaType = 50 // application/json AppCBOR MediaType = 60 // application/cbor AppSenmlCBOR MediaType = 112 // application/senml_cbor AppLwm2mTLV MediaType = 11542 //application/vnd.oma.lwm2m+tlv AppLwm2mJSON MediaType = 11543 //application/vnd.oma.lwm2m+json )
Content types.
type Message ¶
type Message struct {
Type COAPType
Code COAPCode
MessageID uint16
Token []byte
Payload []byte
PathVars map[string]string
Meta Metadata
// contains filtered or unexported fields
}
Message is a CoAP message.
func NewMessage ¶
func NewMessage() *Message
func (*Message) ContentFormat ¶
func (*Message) GetBlock1 ¶ added in v1.3.11
func (m *Message) GetBlock1() *BlockMetadata
func (*Message) GetBlock2 ¶ added in v1.3.11
func (m *Message) GetBlock2() *BlockMetadata
func (*Message) IsConfirmable ¶
IsConfirmable returns true if this message is confirmable.
func (*Message) LocationPath ¶
Path gets the Path set on this message if any.
func (*Message) LocationPathString ¶
PathString gets a path as a / separated string.
func (*Message) OptionsMap ¶ added in v1.4.0
func (*Message) PacketSize ¶
func (*Message) ParseQuery ¶
func (*Message) PathString ¶
PathString gets a path as a / separated string.
func (*Message) QueryString ¶ added in v1.1.0
func (*Message) RemoveOption ¶
RemoveOption removes all references to an option
func (*Message) RequiresBlockwise ¶ added in v1.1.0
func (*Message) WithAccept ¶
func (*Message) WithBlock1 ¶ added in v1.1.0
func (m *Message) WithBlock1(bm *BlockMetadata) *Message
func (*Message) WithBlock2 ¶ added in v1.1.0
func (m *Message) WithBlock2(bm *BlockMetadata) *Message
func (*Message) WithContentFormat ¶
func (*Message) WithLocationPath ¶
func (*Message) WithLocationPathString ¶
func (*Message) WithOption ¶
AddOption adds an option.
func (*Message) WithPathString ¶
WithPathString sets a path by a / separated string.
func (*Message) WithPayload ¶
type Observation ¶
type Observation struct {
// contains filtered or unexported fields
}
type ObserveCallback ¶
type ObserveNotFoundCallback ¶
type OptionID ¶
type OptionID uint8
OptionID identifies an option in a message.
const ( OptIfMatch OptionID = 1 OptURIHost OptionID = 3 OptETag OptionID = 4 OptIfNoneMatch OptionID = 5 OptObserve OptionID = 6 OptURIPort OptionID = 7 OptLocationPath OptionID = 8 OptURIPath OptionID = 11 OptContentFormat OptionID = 12 OptMaxAge OptionID = 14 OptURIQuery OptionID = 15 OptAccept OptionID = 17 OptLocationQuery OptionID = 20 OptBlock2 OptionID = 23 OptBlock1 OptionID = 27 OptSize2 OptionID = 28 OptProxyURI OptionID = 35 OptProxyScheme OptionID = 39 OptSize1 OptionID = 60 )
Option IDs.
type ProxyFunction ¶ added in v1.7.0
type RouteCallback ¶
type SendOptions ¶
type SendOptions struct {
MaxRetransmit int `json:"MaxRetransmit"`
ActTimeout time.Duration `json:"ActTimeout"`
RandomFactor float64 `json:"RandomFactor"`
BlockSize int `json:"BlockSize"`
MaxMessageSize int `json:"MaxMessageSize"`
NStart int `json:"NStart"`
}
func (*SendOptions) NoRetry ¶
func (so *SendOptions) NoRetry() *SendOptions
func (*SendOptions) WithBlockSize ¶ added in v1.2.7
func (so *SendOptions) WithBlockSize(bs int) *SendOptions
func (*SendOptions) WithMaxMessageSize ¶ added in v1.8.4
func (so *SendOptions) WithMaxMessageSize(ms int) *SendOptions
func (*SendOptions) WithNStart ¶ added in v1.2.7
func (so *SendOptions) WithNStart(ns int) *SendOptions
func (*SendOptions) WithRetry ¶
func (so *SendOptions) WithRetry(count int, timeout time.Duration, randomFactor float64) *SendOptions
type Server ¶ added in v1.3.0
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddRoute ¶ added in v1.3.0
func (s *Server) AddRoute(path string, callback RouteCallback)
func (*Server) BlockCacheSize ¶ added in v1.3.0
func (*Server) GetNextMsgId ¶ added in v1.6.0
func (*Server) LastActivity ¶ added in v1.4.5
func (*Server) NewOptions ¶ added in v1.3.0
func (s *Server) NewOptions() *SendOptions
func (*Server) Observe ¶ added in v1.3.0
func (s *Server) Observe(addr string, code COAPCode, path string, payload []byte, encoding MediaType, callback ObserveCallback, arg interface{}, options *SendOptions) (string, error)
func (*Server) ObserveCancel ¶ added in v1.3.0
type SniffPacketsCallback ¶ added in v1.6.6
type UdpListener ¶ added in v1.3.0
type UdpListener struct {
// contains filtered or unexported fields
}
func (*UdpListener) Close ¶ added in v1.4.0
func (l *UdpListener) Close()
Click to show internal directories.
Click to hide internal directories.
