MeshSocket
class MeshSocket
Variables
| Name | Description |
|---|---|
| broadCastAddress | @brief Broadcast address used to send and receive data to all neighboors. |
| maxRepeaters | @brief Maximum number of repeaters allowed for a socket |
Functions
| Name | Description |
|---|---|
| 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 |
| isBradcastTarget | @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 data to the target :material-location-enter: data : A buffer containing the data to send :material-location-enter: size : The size of the buffer :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 : 0 if the data is sent correctly, otherwise an error code |
| sendDatagram | @brief Send data to the target :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: port : The destination port of this message :material-location-enter: repeaters : A list with the addresses of the repeaters to use in multipath protocol. This list must be zero terminated. :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 : 0 if the data is sent correctly, otherwise an error code |
| sentStatusCb | @brief Set the sent status callback for all the packets sent from this socket. |
| 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
broadCastAddress
!!! variable "static const uint32_t broadCastAddress"
@brief Broadcast address used to send and receive data to all neighboors.
maxRepeaters
!!! variable "static const uint8_t maxRepeaters"
@brief Maximum number of repeaters allowed for a socket
Function Details
MeshSocket
!!! function "MeshSocket(uint8_t port, uint32_t target, uint32_t *repeaters = nullptr)"
@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
isBradcastTarget
!!! function "bool isBradcastTarget() 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, uint32_t &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, SocketSentStatusHandler handler=nullptr)"
@brief Send data to the target
:material-location-enter: `data`
: A buffer containing the data to send
:material-location-enter: `size`
: The size of the buffer
: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**
: 0 if the data is sent correctly, otherwise an error code
sendDatagram
!!! function "int16_t sendDatagram(const uint8_t *data, uint16_t size, uint32_t target, uint16_t port, uint32_t *repeaters = nullptr, SocketSentStatusHandler handler=nullptr)"
@brief Send data to the target
: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: `port`
: The destination port of this message
:material-location-enter: `repeaters`
: A list with the addresses of the repeaters to use in multipath protocol. This list must be zero terminated.
: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**
: 0 if the data is sent correctly, otherwise an error code
sentStatusCb
!!! function "void sentStatusCb(SocketSentStatusHandler handler)"
@brief Set the sent status callback for all the packets sent from this socket.
This callback is called when a packet has been sent from radio layer.
The callback will be called with true argument if the packet has been sent correctly, otherwise with false. This callback function
is not called if a prioritary handler is provided with the send or sendDatagram functions.
:material-location-enter: `handler`
: Sent status callback.
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