vscode-azure-iot-toolkit
vscode-azure-iot-toolkit copied to clipboard
Empty D2C and C2D message is not sent to IoT Hub
Repro step:
- Start monitoring D2C messages
- Click "Send D2C message to IoT Hub" for a device
- Press Enter directly after input window popup
Expected behavior: I will see the message printed in output window
Actual behavior: I can only see one message: Sending message to [IoT Hub]. No D2C message printed in output window.
Hi, I tried to investigate. This function should be called, after sending message, but it's never called when message is empty. https://github.com/Microsoft/vscode-azure-iot-toolkit/blob/3861db2643154abe328eb2f6488785fafbb368ec/src/baseExplorer.ts#L103
It's used in this place https://github.com/Microsoft/vscode-azure-iot-toolkit/blob/3861db2643154abe328eb2f6488785fafbb368ec/src/iotHubMessageExplorer.ts#L34 sendEvent is called without catching exception, so I believe something inside it is failing and not calling the function, I tried to replace it with client.sendEvent(new Message(stringify ? JSON.stringify(message) : message), (err, result) => this.outputLine(Constants.IoTHubMessageLabel, `Test`));
And Test was never printed for empty message. I had other application running waiting for messages and I don't think anything went through IoT Hub, I think it's client SDK issue.
I tried to run example in node from here https://github.com/Microsoft/vscode-azure-iot-toolkit/blob/master/resources/code-template/node/sendD2C.js for empty message I'm getting this exception https://github.com/Azure/azure-iot-sdk-node/blob/734bd35f0a48b519ee4de233d1762e7ef2d4521c/common/transport/mqtt/src/mqtt_base.ts#L171 Try catch is not working for it, it's likely asynchronous code, so that could be a reason, but I'm not 100% sure. That line is actually never called https://github.com/Microsoft/vscode-azure-iot-toolkit/blob/3861db2643154abe328eb2f6488785fafbb368ec/resources/code-template/node/sendD2C.js#L29
I could add validation, that message can't be empty, on the other hand when sending empty message from C# code, it will accept it, but toolkit when monitoring d2c will display undefined. SDKs seem a bit inconsistent here.
Seems like an issue of Node SDK. Python SDK is also expected to support to send empty message: https://github.com/Azure/azure-iot-sdk-python/issues/179
Create an issue to Node SDK: https://github.com/Azure/azure-iot-sdk-node/issues/400