Description
I have a TD where eg. an event is being declared in events
like this:
"customContentType": {
"type": "string",
"forms": [{ "contentType": "application/octet-stream" }]
}
When the thing has been exposed, the directory contains this description:
"customContentType": {
"forms": [
{
"contentType": "application/octet-stream",
"href": "http://<ip>:8080/mything/events/customContentType",
"op": ["subscribeevent", "unsubscribeevent"],
"subprotocol": "longpoll"
},
{
"contentType": "application/json",
"href": "mqtt://<brokerip>:1883/mything/events/customContentType",
"op": ["subscribeevent", "unsubscribeevent"]
}
],
"type": "string"
}
I am using node-wot to expose the thing, so when the event is being emitted as in thing.emitEvent('customContentType', Readable.from(Buffer.from('...')));
the value gets converted to JSON (exposing internal state of a Readable) and emitted.
Obviously, you cannot get the actual data from that emission (this was spyed on with mosquitto_sub):
{"_readableState":{"objectMode":true,"highWaterMark":16,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":null,"ended":false,"endEmitted":false,"reading":false,"constructed":true,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"dataEmitted":false,"decoder":null,"encoding":null},"_events":{},"_eventsCount":0}
When requesting the value w/ HTTP longpolling, the application crashes with an error:
Error: Unable to handle dataType undefined
at OctetstreamCodec.valueToBytes (.../node_modules/@node-wot/core/dist/codecs/octetstream-codec.js:155:23)
at ContentSerdes.valueToContent (.../node_modules/@node-wot/core/dist/content-serdes.js:108:27)
at ProtocolListenerRegistry.notify (.../node_modules/@node-wot/core/dist/protocol-listener-registry.js:59:54)
at ExposedThing.emitEvent (.../node_modules/@node-wot/core/dist/exposed-thing.js:91:35)
at Kelvin.emitBeat (.../dist/kelvin.thing.js:90:20)
What I'd actually like to achieve would be to send a binary payload over both HTTP and MQTT channels and get the actual data in a suitable format. With MQTT, it would obviously not be possible to transmit a content type information, but this information can be extracted from the thing description.