Skip to content
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

fix(binding-mqtt): fix sending plain value instead of content object #987

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/binding-mqtt/src/mqtt-broker-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from "@node-wot/core";
import { InteractionOptions } from "wot-typescript-definitions";
import { ActionElement, PropertyElement } from "wot-thing-description-types";
import { Readable } from "stream";

const { info, debug, error, warn } = createLoggers("binding-mqtt", "mqtt-broker-server");

Expand Down Expand Up @@ -235,6 +236,7 @@ export default class MqttBrokerServer implements ProtocolServer {
* For further discussion see https://github.com/eclipse/thingweb.node-wot/pull/253
*/
let value;

if ("properties" in packet && "contentType" in packet.properties) {
try {
value = ContentSerdes.get().contentToValue(
Expand Down Expand Up @@ -266,7 +268,11 @@ export default class MqttBrokerServer implements ProtocolServer {
};

thing
.handleInvokeAction(segments[3], value, options)
.handleInvokeAction(
segments[3],
new Content(ContentSerdes.DEFAULT, Readable.from(value)),
options
)
.then((output: unknown) => {
if (output) {
warn(`MqttBrokerServer at ${this.brokerURI} cannot return output '${segments[3]}'`);
Expand Down Expand Up @@ -300,7 +306,11 @@ export default class MqttBrokerServer implements ProtocolServer {
};

try {
thing.handleWriteProperty(segments[3], JSON.parse(payload.toString()), options);
thing.handleWriteProperty(
segments[3],
new Content(ContentSerdes.DEFAULT, Readable.from(payload.toString())),
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
options
);
} catch (err) {
error(
`MqttBrokerServer at ${this.brokerURI} got error on writing to property '${segments[3]}': ${err.message}`
Expand Down