Skip to content

MeshSocket

class MeshSocket

Variables

Name Description
maxRepeaters @brief Maximum number of repeaters allowed for a socket

Functions

Name Description
MeshSocket @brief Create a new datagram socket that will bind all protcols for incoming data.
MeshSocket @brief Create a new socket that will send and receive data from the target.
~MeshSocket @brief Destructor
getTargetAddress @brief Return the target address of the socket :material-keyboard-return: Return : Target address of the socket
isBroadcastTarget @brief Return true if the target address is the broadcast address :material-keyboard-return: Return : True if the target address is the broadcast address
status @brief Return the status of the socket :material-keyboard-return: Return : Status of the socket
listen @brief Listen for incoming connections :material-keyboard-return: Return : 0 if the socket is listening correctly, otherwise an error code
open @brief Open the socket and allocate the resource to handle its connection.
close @brief Close the socket and release the resources
send @brief Send a single datagram to the target node using the appropriate protocol.
sendDatagram @brief Overloaded of the sendDatagram function to use a vector of repeaters :material-location-enter: data : A buffer containing the data to send :material-location-enter: size : The size of the buffer :material-location-enter: target : The address of the target node :material-location-enter: optional : callback to receive the sent status information (true if the packet has been sent correctly, false otherwise).
recv @brief Receive data from the socket the function is not blocking and will fill the buffer with the received data up to size.
recvDatagram @brief Receive a datagram using the opened socket, the function is not blocking and will return the last received datagram.
recvAvail @brief Return the number of bytes available to receive :material-keyboard-return: Return : Number of bytes available to receive
recvCb @brief Set the receive callback :material-location-enter: handler : Receive callback
recvDatagramCb @brief Set the receive datagram callback :material-location-enter: handler : Receive datagram callback

Variable Details

maxRepeaters

!!! variable "static const uint8_t maxRepeaters"

@brief Maximum number of repeaters allowed for a socket

Function Details

MeshSocket

!!! function "MeshSocket(uint8_t port)"

@brief Create a new datagram socket that will bind all protcols for incoming data.

:material-location-enter: `port`
:    Port t bind on all protocols

!!! function "MeshSocket(const MeshAddress &target)"

@brief Create a new socket that will send and receive data from the target.
    If the target is the broadcast address, the socket will send and receive data to all neighboors.

:material-location-enter: `port`
:    Port to use for the socket

:material-location-enter: `target`
:    Target to send data to

:material-location-enter: `type`
:    Type of socket

:material-location-enter: `zero`
:    terminated array of addresses of the repeaters  to use for multihop protocols

close

!!! function "uint8_t close()"

@brief Close the socket and release the resources

getTargetAddress

!!! function "uint32_t getTargetAddress() const"

@brief Return the target address of the socket

:material-keyboard-return: **Return**
:    Target address of the socket

isBroadcastTarget

!!! function "bool isBroadcastTarget() const"

@brief Return true if the target address is the broadcast address

:material-keyboard-return: **Return**
:    True if the target address is the broadcast address

listen

!!! function "uint8_t listen(SocketNewConnectionHandler handler)"

@brief Listen for incoming connections

:material-keyboard-return: **Return**
:    0 if the socket is listening correctly, otherwise an error code

open

!!! function "int8_t open(SocketType type = SOCK_DGRAM)"

@brief Open the socket and allocate the resource to handle its connection.

:material-keyboard-return: **Return**
:    0 if the socket is opened correctly, otherwise an error code

recv

!!! function "int16_t recv(uint8_t *data, uint16_t size)"

@brief Receive data from the socket the function is not blocking and will fill the buffer with the received data up to size.
    If the type of socket is not SOCK_DGRAM or SOCK_FLOOD, the function will return the data coorresponding to one or more received datagrams.
    IF the size of the biffer is not enough to contain the first received datagram, the function will return an error code.
    If the sieze of buffer is enough, the function will return more the one datagram concatenated. If you need to receive only one datagram,
    you can use the recvDatagram function.

:material-location-enter: `data`
:    Data to receive

:material-location-enter: `size`
:    Size of the data

:material-keyboard-return: **Return**
:    Number of bytes received or -1 if there is an error

recvAvail

!!! function "int16_t recvAvail() const"

@brief Return the number of bytes available to receive

:material-keyboard-return: **Return**
:    Number of bytes available to receive

recvCb

!!! function "void recvCb(SocketReceiveHandler handler)"

@brief Set the receive callback

:material-location-enter: `handler`
:    Receive callback

recvDatagram

!!! function "int16_t recvDatagram(uint8_t *data, uint16_t size, MeshAddress &from, int16_t &rssi)"

@brief Receive a datagram using the opened socket, the function is not blocking and will return the last received datagram.
    If the socket is not opened, the function will return an error code, if the type of socket is not SOCK_DGRAM or SOCK_FLOOD,
    the function will return an error code.

:material-location-enter: `data`
:    buffer that will contain the received data

:material-location-enter: `size`
:    the maximum size of the data to receive

:material-location-enter: `from`
:    a variable that will contain the source address of the datagram

:material-location-enter: `rssi`
:    a variable that will contain the received signal strength indication

:material-keyboard-return: **Return**
:    in case of error, the function will return an error code, otherwise it will return the number of bytes received

recvDatagramCb

!!! function "void recvDatagramCb(SocketRecvDatagramHandler handler)"

@brief Set the receive datagram callback

:material-location-enter: `handler`
:    Receive datagram callback

send

!!! function "int16_t send(const uint8_t *data, uint16_t size, SentStatusHandler handler=nullptr)"

@brief Send a single datagram to the target node using the appropriate protocol.

:material-location-enter: `data`
:    The data to send.

:material-location-enter: `size`
:    The size of the data.

:material-location-enter: `target`
:    The target address.

:material-location-enter: `Optional`
:    callback to receive the sent status information (true if the packet has been sent correctly, false otherwise).
      this callback is prioritary over the callback set the sentStatusCb function. If this parameter is prvided the sentStatusCb
      function will not be called for this packet.

:material-keyboard-return: **Return**
:    errSuccess if the data is sent correctly, otherwise an error code.

sendDatagram

!!! function "int16_t sendDatagram(const uint8_t *data, uint16_t size, MeshAddress target, SocketSentStatusHandler handler=nullptr)"

@brief Overloaded of the sendDatagram function to use a vector of repeaters

:material-location-enter: `data`
:    A buffer containing the data to send

:material-location-enter: `size`
:    The size of the buffer

:material-location-enter: `target`
:    The address of the target node

:material-location-enter: `optional`
:    callback to receive the sent status information (true if the packet has been sent correctly, false otherwise).

status

!!! function "StatusFlags status() const"

@brief Return the status of the socket

:material-keyboard-return: **Return**
:    Status of the socket

~MeshSocket

!!! function "virtual ~MeshSocket()"

@brief Destructor