Send D2C Message to IoT Hub - microsoft/vscode-azure-iot-toolkit GitHub Wiki

Command: Azure IoT Hub: Send D2C message to IoT Hub

Right-click your device and select Send D2C message to IoT Hub. Fill the device(s), message count, interval and content of message. Click Start, IoT Hub Toolkit will start sending messages on behalf of the selected device(s). You can view the summary in output channel Send D2C Messages.

send d2c

Entry

Besides the command palette, you can also trigger the command from context menu of a device tiem and menu of Azure IoT Hub explorer.

Multi-select filter

The device list is a multi-selector, which means you can select one or more item(s). The selector contains a filter, you can just input the key words and the list will search the related devices. When you input a key word, you can select more than one item if you like, and the filter will not be reset. But if you move out of the selector, and focus on it again, the filter will be reset. If you want to type in another key word, just type in what you want with no need to delete the previous one.

Message types

There are two types of messages: plain text and data template. The data template leverages Dummy JSON as the template engine. For Plain Text, there is no Preview Pane, and once you click the send button, the inputted message will be sent to the IoT Hub. If you choose the Dummy JSON, there is a default template about the IoT scenario shown as default value in the text area, and you can preview it when switch to the Preview Pane. The Preview Pane is read-only.

Sending in backend

During the sending process, you can click on the cancel button and the progress will be canceled. When finish sending, there will be a summary in output channel Send D2C Messages, including start time, end time and the sending status of the simulation. During the sending process, feel free to close the WebView. Messages will keep sending in the backend. But be aware that if you close the Visual Studio Code, all progresses will be terminated.

Data Durability

When you close the WebView, what you input in the simulator, except the device list, will be totally stored in the memory so that next time you start the simulator, you can use the previous Dummy JSON template, the Interval, and so on. The only thing you need to do is to select the device(s) again. If you close the Visual Studio Code, all data will be reset, so that next time you open it, you will get the default value in all fields.

JSON Format and Stringify

The setting azure-iot-toolkit.iotHubD2CMessageStringify controls whether to stringify device-to-cloud messages. If the setting is true, message will be sent as string, no matter whehter the message is a json object or not. If the setting is false, message will be sent as JSON object if it's a valid json. If the message is not a valid json, the message will be sent as string.