Reputation: 162
I'm trying to run an application with coap but I'm new. I am using the python coapthon3 library. But I want to get the payloads from the library using the encoding path. But I could not do this. My client code is as follows. Thank you
from coapthon.client.helperclient import HelperClient
host = "127.0.0.1"
port = 5683
path = "encoding"
payload = 'text/plain'
client = HelperClient(server=(host, port))
response = client.get(path + 'application/xml' + '<value>"+str(payload)+"</value>')
client.stop()
Upvotes: 0
Views: 1671
Reputation: 1300
No, you shouldn't concatenate all the stuff to the path.
Unfortunately HelperClient#get does not provide an ability to specify a payload though it is pretty legal according to CoAP spec.
So you need to create a request and fill all the needed fields, and to use send_request method.
I guess my snippet is not that pythonish so please bear with me.
from coapthon.client.helperclient import HelperClient
from coapthon.messages.request import Request
from coapthon import defines
host = "127.0.0.1"
port = 5683
path = "encoding"
payload = 'text/plain'
client = HelperClient(server=(host, port))
request = Request()
request.code = defines.Codes.GET.number
request.type = defines.Types['NON']
request.destination = (host, port)
request.uri_path = path
request.content_type = defines.Content_types["application/xml"]
request.payload = '<value>"+str(payload)+"</value>'
response = client.send_request(request)
client.stop()
Upvotes: 1