QCoapClient#
The QCoapClient
class allows the application to send CoAP requests and receive replies. More…
Synopsis#
Functions#
def
cancelObserve
(url)def
cancelObserve
(notifiedReply)def
deleteResource
(request)def
deleteResource
(url)def
disconnect
()def
discover
([group=QtCoap.MulticastGroup.AllCoapNodesIPv4[, port=QtCoap.DefaultPort[, discoveryPath=QLatin1String(“/.well-known/core”)]]])def
discover
(baseUrl[, discoveryPath=QLatin1String(“/.well-known/core”)])def
get
(request)def
get
(url)def
observe
(request)def
observe
(request)def
post
(request[, data=QByteArray()])def
post
(url[, data=QByteArray()])def
post
(request, device)def
put
(request, device)def
put
(request[, data=QByteArray()])def
put
(url[, data=QByteArray()])def
setAckRandomFactor
(ackRandomFactor)def
setAckTimeout
(ackTimeout)def
setBlockSize
(blockSize)def
setMaximumRetransmitCount
(maximumRetransmitCount)def
setMaximumServerResponseDelay
(responseDelay)def
setMinimumTokenSize
(tokenSize)def
setSecurityConfiguration
(configuration)def
setSocketOption
(option, value)
Signals#
def
error
(reply, error)def
finished
(reply)def
responseToMulticastReceived
(reply, message, sender)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
The QCoapClient
class contains signals that get triggered when the reply of a sent request has arrived.
The application can use a QCoapClient
to send requests over a CoAP network. It provides functions for standard requests: each returns a QCoapReply
object, to which the response data shall be delivered; this can be read when the finished()
signal arrives.
A simple request can be sent with:
QCoapClient *client = new QCoapClient(this); connect(client, &QCoapClient::finished, this, &TestClass::slotFinished); client->get(QCoapRequest(Qurl("coap://coap.me/test")));
Note
After processing of the request has finished, it is the responsibility of the user to delete the QCoapReply
object at an appropriate time. Do not directly delete it inside the slot connected to finished()
. You can use the deleteLater()
function.
You can also use an observe request. This can be used as above, or more conveniently with the notified()
signal:
QCoapRequest request = QCoapRequest(Qurl("coap://coap.me/obs")); QCoapReply *reply = client->observe(request); connect(reply, &QCoapReply::notified, this, &TestClass::slotNotified);
And the observation can be cancelled with:
client->cancelObserve(reply);
When a reply arrives, the QCoapClient
emits a finished()
signal.
Note
For a discovery request, the returned object is a QCoapResourceDiscoveryReply
. It can be used the same way as a QCoapReply
but contains also a list of resources.
- class PySide6.QtCoap.QCoapClient([securityMode=QtCoap.SecurityMode.NoSecurity[, parent=None]])#
- Parameters:
securityMode –
SecurityMode
parent –
PySide6.QtCore.QObject
Constructs a QCoapClient
object for the given securityMode
and sets parent
as the parent object.
The default for securityMode
is NoSecurity
, which disables security.
This connects using a QCoapQUdpConnection; to use a custom transport, sub-class QCoapConnection and pass an instance to one of the other constructors.
- PySide6.QtCoap.QCoapClient.cancelObserve(url)#
- Parameters:
url –
PySide6.QtCore.QUrl
This is an overloaded function.
Cancels the observation of a resource identified by the url
.
See also
- PySide6.QtCoap.QCoapClient.cancelObserve(notifiedReply)
- Parameters:
notifiedReply –
PySide6.QtCoap.QCoapReply
This is an overloaded function.
Cancels the observation of a resource using the reply notifiedReply
returned by the observe()
method.
See also
- PySide6.QtCoap.QCoapClient.deleteResource(request)#
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
- Return type:
Sends the request
using the DELETE method and returns a new QCoapReply
object.
See also
- PySide6.QtCoap.QCoapClient.deleteResource(url)
- Parameters:
url –
PySide6.QtCore.QUrl
- Return type:
This is an overloaded function.
Sends a DELETE request to the target url
.
See also
- PySide6.QtCoap.QCoapClient.disconnect()#
Closes the open sockets and connections to free the transport.
Note
In the secure mode this needs to be called before changing the security configuration or connecting to another server.
See also
- PySide6.QtCoap.QCoapClient.discover([group=QtCoap.MulticastGroup.AllCoapNodesIPv4[, port=QtCoap.DefaultPort[, discoveryPath=QLatin1String("/.well-known/core")]]])#
- Parameters:
group –
MulticastGroup
port – int
discoveryPath – str
- Return type:
This is an overloaded function.
Discovers the resources available at the endpoints which have joined the group
at the given port
. Returns a new QCoapResourceDiscoveryReply
object which emits the discovered()
signal whenever a response arrives. The group
is one of the CoAP multicast group addresses and defaults to AllCoapNodesIPv4
.
Discovery path defaults to “/.well-known/core”, but can be changed by passing a different path to discoveryPath
. Discovery is described in RFC 6690 .
See also
- PySide6.QtCoap.QCoapClient.discover(baseUrl[, discoveryPath=QLatin1String("/.well-known/core")])
- Parameters:
baseUrl –
PySide6.QtCore.QUrl
discoveryPath – str
- Return type:
Discovers the resources available at the given url
and returns a new QCoapResourceDiscoveryReply
object which emits the discovered()
signal whenever the response arrives.
Discovery path defaults to “/.well-known/core”, but can be changed by passing a different path to discoveryPath
. Discovery is described in RFC 6690 .
See also
- PySide6.QtCoap.QCoapClient.error(reply, error)#
- Parameters:
reply –
PySide6.QtCoap.QCoapReply
error –
Error
This signal is emitted whenever an error occurs. The reply
parameter can be None
if the error is not related to a specific QCoapReply
. The error
parameter contains the error code.
See also
- PySide6.QtCoap.QCoapClient.finished(reply)#
- Parameters:
reply –
PySide6.QtCoap.QCoapReply
This signal is emitted along with the finished()
signal whenever a CoAP reply is received, after either a success or an error. The reply
parameter will contain a pointer to the reply that has just been received.
See also
- PySide6.QtCoap.QCoapClient.get(request)#
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
- Return type:
Sends the request
using the GET method and returns a new QCoapReply
object.
See also
- PySide6.QtCoap.QCoapClient.get(url)
- Parameters:
url –
PySide6.QtCore.QUrl
- Return type:
This is an overloaded function.
Sends a GET request to url
and returns a new QCoapReply
object.
See also
- PySide6.QtCoap.QCoapClient.observe(request)#
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
- Return type:
Sends a request to observe the target request
and returns a new QCoapReply
object which emits the notified()
signal whenever a new notification arrives.
- PySide6.QtCoap.QCoapClient.observe(request)
- Parameters:
request –
PySide6.QtCore.QUrl
- Return type:
This is an overloaded function.
Sends a request to observe the target url
and returns a new QCoapReply
object which emits the notified()
signal whenever a new notification arrives.
- PySide6.QtCoap.QCoapClient.post(request[, data=QByteArray()])#
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
data –
PySide6.QtCore.QByteArray
- Return type:
Sends the request
using the POST method and returns a new QCoapReply
object. Uses data
as the payload for this request. If data
is empty, the payload of the request
will be used.
See also
- PySide6.QtCoap.QCoapClient.post(url[, data=QByteArray()])
- Parameters:
url –
PySide6.QtCore.QUrl
data –
PySide6.QtCore.QByteArray
- Return type:
This is an overloaded function.
Sends a POST request to url
and returns a new QCoapReply
object. Uses data
as the payload for this request.
See also
- PySide6.QtCoap.QCoapClient.post(request, device)
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
device –
PySide6.QtCore.QIODevice
- Return type:
This is an overloaded function.
Sends the request
using the POST method and returns a new QCoapReply
object. Uses device
content as the payload for this request. A null device is treated as empty content.
Note
The device has to be open and readable before calling this function.
See also
- PySide6.QtCoap.QCoapClient.put(request, device)#
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
device –
PySide6.QtCore.QIODevice
- Return type:
This is an overloaded function.
Sends the request
using the PUT method and returns a new QCoapReply
object. Uses device
content as the payload for this request. A null device is treated as empty content.
Note
The device has to be open and readable before calling this function.
See also
- PySide6.QtCoap.QCoapClient.put(request[, data=QByteArray()])
- Parameters:
request –
PySide6.QtCoap.QCoapRequest
data –
PySide6.QtCore.QByteArray
- Return type:
Sends the request
using the PUT method and returns a new QCoapReply
object. Uses data
as the payload for this request. If data
is empty, the payload of the request
will be used.
See also
- PySide6.QtCoap.QCoapClient.put(url[, data=QByteArray()])
- Parameters:
url –
PySide6.QtCore.QUrl
data –
PySide6.QtCore.QByteArray
- Return type:
This is an overloaded function.
Sends a PUT request to url
and returns a new QCoapReply
object. Uses data
as the payload for this request.
See also
- PySide6.QtCoap.QCoapClient.responseToMulticastReceived(reply, message, sender)#
- Parameters:
reply –
PySide6.QtCoap.QCoapReply
message –
PySide6.QtCoap.QCoapMessage
sender –
PySide6.QtNetwork.QHostAddress
This signal is emitted when a unicast response to a multicast request arrives. The reply
parameter contains a pointer to the reply that has just been received, message
contains the payload and the message details, and sender
contains the sender address.
See also
- PySide6.QtCoap.QCoapClient.setAckRandomFactor(ackRandomFactor)#
- Parameters:
ackRandomFactor –
double
Sets the ACK_RANDOM_FACTOR
value defined in RFC 7252 - Section 4.2 , to ackRandomFactor
. This value should be greater than or equal to 1. The default is 1.5.
See also
- PySide6.QtCoap.QCoapClient.setAckTimeout(ackTimeout)#
- Parameters:
ackTimeout –
uint
Sets the ACK_TIMEOUT
value defined in RFC 7252 - Section 4.2 to ackTimeout
in milliseconds. The default is 2000 ms.
This timeout only applies to confirmable messages. The actual timeout for reliable transmissions is a random value between ACK_TIMEOUT
and ACK_TIMEOUT * ACK_RANDOM_FACTOR
.
See also
- PySide6.QtCoap.QCoapClient.setBlockSize(blockSize)#
- Parameters:
blockSize –
quint16
Sets the maximum block size used by the protocol to blockSize
when sending requests and receiving replies. The block size must be a power of two.
- PySide6.QtCoap.QCoapClient.setMaximumRetransmitCount(maximumRetransmitCount)#
- Parameters:
maximumRetransmitCount –
uint
Sets the MAX_RETRANSMIT
value defined in RFC 7252 - Section 4.2 to maximumRetransmitCount
. This value should be less than or equal to 25. The default is 4.
- PySide6.QtCoap.QCoapClient.setMaximumServerResponseDelay(responseDelay)#
- Parameters:
responseDelay –
uint
Sets the MAX_SERVER_RESPONSE_DELAY
value to responseDelay
in milliseconds. The default is 250 seconds.
As defined in RFC 7390 - Section 2.5 , MAX_SERVER_RESPONSE_DELAY
is the expected maximum response delay over all servers that the client can send a multicast request to.
- PySide6.QtCoap.QCoapClient.setMinimumTokenSize(tokenSize)#
- Parameters:
tokenSize – int
Sets the minimum token size to tokenSize
in bytes. For security reasons it is recommended to use tokens with a length of at least 4 bytes. The default value for this parameter is 4 bytes.
- PySide6.QtCoap.QCoapClient.setSecurityConfiguration(configuration)#
- Parameters:
configuration –
PySide6.QtCoap.QCoapSecurityConfiguration
Sets the security configuration parameters from configuration
. Configuration will be ignored if the NoSecurity
mode is used.
Note
This method must be called before the handshake starts. If you need to change the security configuration after establishing a secure connection with the server, the client needs to be disconnected first.
See also
- PySide6.QtCoap.QCoapClient.setSocketOption(option, value)#
- Parameters:
option –
SocketOption
value – object
Sets the QUdpSocket
socket option
to value
.