ProsecCoAP 🥂
 
Loading...
Searching...
No Matches
Coap::Observer Class Reference

A remote CoAP observer. More...

#include <Observers.h>

Public Member Functions

 Observer ()
 Default constructor that creates an inactive observer.
 
 Observer (IPAddress ip, uint16_t port, const uint8_t *token, uint8_t tokenLength)
 Constructor that creates an active observer with the given parameters.
 
bool isActive () const
 Check if the observer is currently active.
 
bool isStale () const
 Check if the observer is stale.
 
void activate ()
 Set the observer as active.
 
void deactivate ()
 Set the observer as deactivated.
 
IPAddress getIp () const
 Get the IP address of the observer.
 
uint16_t getPort () const
 Get the port of the observer.
 
const uint8_t * getToken () const
 Get the token pointer used by the observer.
 
uint8_t getTokenLength () const
 Get the token length used by the observer.
 
uint32_t getNextSequentialNumber ()
 The sequential number for notifications, as per specifications.
 

Detailed Description

A remote CoAP observer.

It tracks a remote observer registered to a specific resource for notifications.

Constructor & Destructor Documentation

◆ Observer() [1/2]

Coap::Observer::Observer ( )
inline

Default constructor that creates an inactive observer.

◆ Observer() [2/2]

Coap::Observer::Observer ( IPAddress ip,
uint16_t port,
const uint8_t * token,
uint8_t tokenLength )
inline

Constructor that creates an active observer with the given parameters.

Parameters
ipThe IP address of the observer.
portThe port of the observer.
tokenThe token used by the observer.
tokenLengthThe length of the token in bytes.

Member Function Documentation

◆ activate()

void Coap::Observer::activate ( )

Set the observer as active.

Setting an observer as active also updates its internal last seen value. Inactive observers are ignored by the registry and their slot can be reused to store new observers.

◆ deactivate()

void Coap::Observer::deactivate ( )

Set the observer as deactivated.

Inactive observers are ignored by the registry and their slot can be reused to store new observers.

◆ getIp()

IPAddress Coap::Observer::getIp ( ) const
inline

Get the IP address of the observer.

Returns
The IP address.

◆ getNextSequentialNumber()

uint32_t Coap::Observer::getNextSequentialNumber ( )

The sequential number for notifications, as per specifications.

As per https://datatracker.ietf.org/doc/html/rfc7641#section-4.4, the sequence number MAY start at any value and MUST NOT increase so fast that it increases by more than 2^23 within less than 256 seconds.

As per implementation notes, using the local clock (e.g. millis()) is a simple way to meet this requirement.

Note
Only the least significant 24 bits are used.

◆ getPort()

uint16_t Coap::Observer::getPort ( ) const
inline

Get the port of the observer.

Returns
The port number.

◆ getToken()

const uint8_t * Coap::Observer::getToken ( ) const
inline

Get the token pointer used by the observer.

Returns
Pointer to the token.

◆ getTokenLength()

uint8_t Coap::Observer::getTokenLength ( ) const
inline

Get the token length used by the observer.

Returns
The token length in bytes.

◆ isActive()

bool Coap::Observer::isActive ( ) const
inline

Check if the observer is currently active.

Returns
True if the observer is active, false otherwise.

Inactive observers are ignored by the registry and their slot can be reused to store new observers.

◆ isStale()

bool Coap::Observer::isStale ( ) const

Check if the observer is stale.

Returns
True if the observer is stale, false otherwise.

An observer is considered stale if it is active AND has not been seen for 24 hours or more.

See also
https://datatracker.ietf.org/doc/html/rfc7641#section-4.5

The documentation for this class was generated from the following files: