-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to receive payload data? #156
Comments
What type of data are you expecting in the Might be helpful for you to either print the hex representation (can use Tuulbox's For example: val decoded = encoded.decode<Udp>()
Log.d("CoAP: ", decoded.payload.toHexString()) // or: decoded.payload.decodeToString() As for the The For example:
Might be constructed via the following options: import com.juul.koap.Message.Option.UriHost
import com.juul.koap.Message.Option.UriPath
import com.juul.koap.Message.Option.UriPort
listOf(UriHost("192.168.4.1"), UriPort(5683), UriPath("hello"), UriPath("world")) |
Awesome! Thanks so much for you response. The data from my CoAP server is string data converted from a float using snprintf.
And decoding as such:
I believe my URI path is ok because I used the Copper Chrome extension to make GET requests to my SpO2 resource and I am able to read the payload. |
We haven't needed resource discovery in our projects, so didn't implement any kind of support in KoAP.
Any chance you can grab the raw data (preferable in hex notation) that the extension is sending (where you said it is working)? I could help you reverse engineer the request to determine how to shape the request using KoAP. |
Unfortunately I do not have access to the hex data, but I can provide screenshot with as much data possible. |
Hmm...is there a particular reason why you're using According to the screenshot |
Being that your payload is expected to be a float, I think you'll want something like: val value = ByteBuffer.wrap(payload).getFloat() Note, the above example is JVM only, if you want to read a float in common code you'll have to find a pure Kotlin mechanism of converting a |
🤦 I tried to put the full path like so UriPath(192.168.4.1:5683/SpO2) before and didn't update it after. Thanks so much for that catch. My data should still be string data because I am echoing the payload through serial COM on my ESP8266 and I am reading it correctly. |
Can you try logging either the Just trying to confirm if your I would think (hope) that your peripheral would respond with a failure CoAP response if you have the host/path incorrect. Alternatively, if you can share the full raw (in hex notation) requests that you're sending (i.e. provide the bytes that you encoded to using KoAP) and responses that you're receiving (i.e. the bytes you're getting back before decoding w/ KoAP) then I can help debug further. |
Here is my log
Encoded messaged for transmission: 400100003B3139322E3136382E342E314216334453704F32 |
Is The bytes you provided for both the request and "response" are identical, indicating that perhaps |
From my understanding, the Message class method 'encode' will transmit the CoAP message and update the payload from the response message within the same Message class. Do I need to call another method to receive the response? I set my CoAP server log to the most verbose settings and I do not see any negative response, only the creating and binding of the CoAP server socket |
KoAP is just an encoder/decoder, it doesn't have a transport layer; it is expected that the library consumer transmits the data. So, you'll essentially use KoAP to encode a CoAP message (as a For example: val coapRequest = Message.Udp(..)
val requestBytes = coapRequest.encode()
// hypothetical `transport` that sends bytes over-the-wire/air
val responseBytes = transport.send(requestBytes)
val coapResponse = responseBytes.decode<Udp>()
println(coapResponse) |
Oh my god! So sorry for wasting your time.... Are there any future plans to be the first kotlin written CoAP client/server? |
No worries. 😄
Unfortunately, no. Just too many other priorities to work on, and we only needed the encoding/decoding side of things. |
Hello, I am connecting my kotlin app to an ESP8266 Coap server. I have defined my message like so:
Then I have a scheduled timer task sending the encoded message periodically and am trying to decode:
However I keep receiving garbage data. "[B@91f6bff, [B@b82ddcc, [B@e14c815, [B@90dc72a, [B@208c91b" etc...
Is there a way to verify I have the right URI path?
The text was updated successfully, but these errors were encountered: