juullabs / koap Goto Github PK
View Code? Open in Web Editor NEWKotlin CoAP encoder/decoder.
Home Page: https://juullabs.github.io/koap
License: Apache License 2.0
Kotlin CoAP encoder/decoder.
Home Page: https://juullabs.github.io/koap
License: Apache License 2.0
Currently it is not possible to see anything about a message that includes an unsupported option, except that option number.
For example, the UDP message 40020011c13cffd1e91a8401020304
: "Unsupported option number 258"
(Option 258 is the No-Response option RFC-7967, listed in IANA CoAP Option Numbers)
Removing the unsupported option, 40020011c13cff8401020304
, you get to see the full message details:
Message:
{
"type": "Confirmable",
"code": "POST",
"id": 17,
"token": 0,
"options": [
"Content-Format: application/cbor"
]
}Payload (CBOR):
[1, 2, 3, 4]
It would be nice if unsupported options could be listed as opaque option number, value pairs in the options list, perhaps with a warning at the end.
NOTE: Public Repos are disabled for this organization! Repository was automatically converted to a Private Repo. Please contact an admin to override.
/cc @twyatt
/cc @perl2ruby @jessecollier @zafarabbas @IamMrCupp @carterandrew
Hello, I am connecting my kotlin app to an ESP8266 Coap server. I have defined my message like so:
private val message = Message.Udp(
type = Udp.Type.Confirmable,
code = Message.Code.Method.GET,
id = 0x0,
token = 0x0,
options = listOf(Message.Option.UriPath("192.168.4.1"), Message.Option.UriPort(5683), Message.Option.LocationPath("/SpO2")),
payload = byteArrayOf()
)
Then I have a scheduled timer task sending the encoded message periodically and am trying to decode:
val encoded = message.encode()
val decoded = encoded.decode<Udp>()
Log.d("CoAP: ", decoded.payload.toString())
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 RFC defines numeric types as unsigned; in KoAP (to prevent overflow) the next larger numeric type is used (e.g. a Long
is used to store an unsigned int32
).
unsigned integers would simplify a lot of internal code as well as simplify the public facing API. unsigned integers should be used when no longer experimental.
Per RFC 7252 12.3.:
The Content-Format Option indicates the representation format of the message payload. The representation format is given as a numeric Content-Format identifier that is defined in the "CoAP Content-Formats" registry (Section 12.3).
KoAP should provide constants for the media types listed in Table 9: CoAP Content-Formats (found in section 12.3):
+--------------------------+----------+----+------------------------+
| Media type | Encoding | ID | Reference |
+--------------------------+----------+----+------------------------+
| text/plain; | - | 0 | [RFC2046] [RFC3676] |
| charset=utf-8 | | | [RFC5147] |
| application/link-format | - | 40 | [RFC6690] |
| application/xml | - | 41 | [RFC3023] |
| application/octet-stream | - | 42 | [RFC2045] [RFC2046] |
| application/exi | - | 47 | [REC-exi-20140211] |
| application/json | - | 50 | [RFC7159] |
+--------------------------+----------+----+------------------------+
Hello! Just discovered this implementation, very cool. I've had the idea to use CoAP over BLE for some time and was wondering if you had any examples of that, perhaps with kable?
#42 integrated a CoAP decoder webapp that is deployed to GitHub Pages.
It utlilizes browserDevelopmentWebpack
Gradle task for building the static pages for the webapp. Unfortunately the development builds are extremely bloated. Attempts to use the production tasks for generating web distributions failed (unable to call Kotlin from JavaScript).
Testing with the js(IR)
compiler worked (for calling Kotlin from JavaScript) but did not work with the current version of Okio (which is not compiled with IR compiler).
In the future we should either:
js(LEGACY)
has fixes that properly allow calling Kotlin from JavaScriptjs(IR)
when Okio supports it (preferred)More details can be found at https://stackoverflow.com/a/65680291/196486.
Unable to invoke the Message.encode
method from js, method is defined here:
https://github.com/JuulLabs/koap/blob/main/koap/src/commonMain/kotlin/Encoder.kt#L56
Example:
import koapModule from '@juullabs/koap'
import kotlin from 'kotlin'
const koap = koapModule.com.juul.koap
let token = new kotlin.Long(66)
let emptyPayload = new Uint8Array()
let kMsg = new koap.Message.Tcp(
koap.Message.Code.Method.GET,
token,
new kotlin.kotlin.collections.ArrayList(
[
new koap.Message.Option.UriPath("dev"),
new koap.Message.Option.UriQuery("abd")
]
),
emptyPayload
}
let outMsg = koap.encode(kMsg)
Results in the exception: "Unhandled Rejection (TypeError): koap.encode is not a function"
IMHO there needs to be some javascript unit tests added to exercise the API to verify it performs as expected when published as a library.
Looks like the koap page hosted on github pages is down, in case you weren't aware.
Caused by java.lang.IllegalStateException: Unsupported option number 21
at com.juul.koap.DecoderKt.readOption(DecoderKt.java:412)
at com.juul.koap.DecoderKt.readOptions(DecoderKt.java:329)
at com.juul.koap.DecoderKt.decodeContent(DecoderKt.java:194)
at com.juul.koap.DecoderKt.decode(DecoderKt.java:178)
at com.juul.koap.DecoderKt.decode$default(DecoderKt.java:175)
<redacted>
at kotlinx.coroutines.flow.FlowKt__TransformKt$onEach$$inlined$unsafeTransform$1$2.emit(FlowKt__TransformKt.java:137)
at com.juul.kable.Observers$acquire$$inlined$map$1$2.emit(Observers.java:137)
at com.juul.kable.Observers$acquire$$inlined$filter$1$2.emit(Observers.java:137)
at kotlinx.coroutines.flow.SubscribedFlowCollector.emit(SubscribedFlowCollector.java:2)
at kotlinx.coroutines.flow.SharedFlowImpl.collect(SharedFlowImpl.java:351)
at kotlinx.coroutines.flow.SharedFlowImpl$collect$1.invokeSuspend(SharedFlowImpl.java:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
Similar to cbor.me, an online encoder/decoder tool should be created. Tool should be published to GitHub Pages on commits merged to main
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.