Hello,
we are currently developing a customer product based on the nRF9160 SIP.
The requirement is to send the battery voltage periodically over the CoAP protocol (PUT method) to an already existing CoAP server which has a server address like:
coap://123.456.789.12/mqtt/batterytest?c=testname&u=username&p=password
For this, we are using Zephyrs CoAP libraries. Unfortunately, we have a lot of unsuccessful attempts to transmit the data and we guess that the problem is in how we configure a CoAP packet. We use Nordics coap-client example as the code base to do our tests.
What we do:
- Create and connect a socket
Create a new socket based on the IPv4 address “123.456.789.12”. We let the code for create the socket as it is in the coap client example, just changed the IP address. It seems, this works fine (server_resolve() and client_init() functions).
- Update the client_get_send() function
Since the original CoAP send function uses the POST-method, we change the parameter for the coap_packet_init function to COAP_METHODE_PUT.
- Change the URI_PATH and URI_QUERY
Since our CoAP server has this complex access address, we think we have to split the address into several blocks and add this to the CoAP packet (with help of the coap_append_option() function).
- At COAP_OPTION_URI_PATH option we append “mqtt/batterytest”
- At COAP_OPTION_URI_QUERY option we append “c=testname&u=username&p=password”
- Append the payload_marker
- Append the payload (it is just a string with the text “payload”)
With these settings we do not see any incoming CoAP message at the server side. We guess we may be misunderstood something and messed something up.
Questions:
- What is in above’s server address example the correct IP address to open a socket for?
- Is the way we split the server address into several URI block the correct approach?
- Finally: How can we send a simple CoAP message with the PUT method to a server with such a complex address? A code snipped which shows how to create a CoAP packet with PUT method and send it to a server address like our would be very nice.
We guess the solution is quite simple, but we run out of ideas what could went wrong. We hope you may can help us.
Thanks in advance
Thomas