2016-10-28 15:17:00 +03:00
# Azure IoT Toolkit
2016-10-28 08:46:08 +03:00
2017-08-18 05:49:53 +03:00
[![Join the chat at https://gitter.im/Microsoft/azure-iot-toolkit ](https://badges.gitter.im/Microsoft/azure-iot-toolkit.svg )](https://gitter.im/Microsoft/azure-iot-toolkit?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2017-11-13 09:49:03 +03:00
Interact with Azure IoT Hub, IoT Device Management, IoT Edge Management, IoT Hub Code Snippets.
2016-10-28 08:46:08 +03:00
2017-06-05 11:10:36 +03:00
## Device Explorer
2017-12-22 08:21:37 +03:00
* IoT Hub management
* Create IoT Hub
* Select IoT Hub
2018-06-22 10:34:15 +03:00
* Copy IoT Hub Connection String
2017-06-05 11:10:36 +03:00
* Device management
* List devices
* Get device info
2017-12-22 08:21:37 +03:00
* Create IoT device
* Create Edge device
2017-06-05 11:10:36 +03:00
* Delete device
2018-06-22 10:34:15 +03:00
* Copy Device Connection String
2017-06-05 11:10:36 +03:00
* Interact with Azure IoT Hub
* Send D2C message to IoT Hub
* Monitor IoT Hub D2C message
2017-06-15 09:16:55 +03:00
* Send C2D message to device
* Monitor C2D message from IoT Hub
2017-08-02 11:43:25 +03:00
* Invoke Direct Method
2018-06-11 08:37:09 +03:00
* Edit Device Twin
2017-11-15 06:18:59 +03:00
* Interact with Azure IoT Edge < sup > Preview</ sup > (Install [Azure IoT Edge ](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-edge ) for more IoT Edge support)
2017-12-22 08:21:37 +03:00
* List Edge Moudles
2018-06-11 08:37:09 +03:00
* Edit Module Twin
2017-11-13 09:49:03 +03:00
* Create deployment for Edge device
2017-06-05 11:10:36 +03:00
### Prerequisites
2018-03-08 05:18:18 +03:00
1. In Explorer of VS Code, click "Azure IoT Hub Devices" in the bottom left corner.
2017-06-05 11:10:36 +03:00
2018-03-22 16:04:28 +03:00
![Click Device Explorer ](images/device-explorer-click.png )
2017-06-05 11:10:36 +03:00
2017-09-12 09:29:21 +03:00
2. Click "Set IoT Hub Connection String" in context menu.
2018-03-22 16:04:28 +03:00
![Set Connection String ](images/set-connection-string.png )
2017-09-12 09:29:21 +03:00
2017-11-14 06:16:37 +03:00
3. An input box will pop up, then enter your IoT Hub Connection String (It is one-time configuration, and please make sure it is **IoT Hub Connection String** not **Device Connection String** . The format is `HostName=<my-hub>.azure-devices.net;SharedAccessKeyName=<my-policy>;SharedAccessKey=<my-policy-key>` ).
2017-06-05 11:10:36 +03:00
2018-03-22 16:04:28 +03:00
![Enter Connection String ](images/enter-connection-string.png )
2017-06-05 11:10:36 +03:00
2017-09-12 09:29:21 +03:00
4. The device list will be shown.
2017-06-05 11:10:36 +03:00
2018-03-22 16:04:28 +03:00
![Device Explorer ](images/device-explorer.png )
2016-10-28 08:46:08 +03:00
2017-09-12 09:29:21 +03:00
**NOTE**: You could also go to **File** > **Preferences** > **Settings** (**Code** > **Preferences** > **Settings** on Mac), update the config of `azure-iot-toolkit.iotHubConnectionString` to change your IoT Hub Connection String.
2017-08-17 06:51:44 +03:00
2017-09-29 11:24:21 +03:00
### Sign in to Azure
Instead of copying and pasting to set IoT Hub Connection String, you could sign in to Azure to select IoT Hub from your Azure Subscription.
1. Click "Select IoT Hub" in context menu.
2018-03-22 16:04:28 +03:00
![Select IoT Hub ](images/select-iot-hub.png )
2017-09-29 11:24:21 +03:00
2017-10-17 06:37:10 +03:00
2. If you have not signed in to Azure, a pop-up will show to let you sign in to Azure.
3. After you sign in, your Azure Subscription list will be shown, then select an Azure Subscription.
2017-09-29 11:24:21 +03:00
4. Your IoT Hub list will be shown, then select an IoT Hub.
5. The device list will be shown.
2017-08-16 14:31:44 +03:00
## Code Snippets
2017-03-06 10:10:54 +03:00
2017-03-06 10:30:59 +03:00
| Trigger | Content |
| ---- | ---- |
| iotSendD2CMessage | Send D2C message to IoT Hub |
| iotMonitorD2CMessage | Monitor D2C message for IoT Hub |
2017-03-08 05:44:21 +03:00
| iotSendC2DMessage | Send C2D message to device |
| iotMonitorC2DMessage | Monitor C2D message from IoT Hub |
2017-06-05 11:10:36 +03:00
| iotCallDirectMethods | Send direct methods to device |
| iotReceiveDirectMethods | Receive direct methods from IoT Hub |
2017-03-06 10:10:54 +03:00
2018-03-22 16:04:28 +03:00
![Snippet ](images/snippet.gif )
2017-03-06 10:30:59 +03:00
> After code snippet is created, you need to install corresponding npm package (e.g. [azure-iot-device-mqtt](https://www.npmjs.com/package/azure-iot-device-mqtt)) to run the code snippet.
> If you want to 'Run Code' directly, you need to install [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner).
2017-03-06 10:10:54 +03:00
2016-10-28 15:06:48 +03:00
## Configuration
2016-10-28 08:46:08 +03:00
2017-08-16 14:31:44 +03:00
IoT Hub Connection String:
2016-10-28 15:06:48 +03:00
```json
{
2017-08-16 14:31:44 +03:00
"azure-iot-toolkit.iotHubConnectionString": "HostName=< my-hub > .azure-devices.net;SharedAccessKeyName=< my-policy > ;SharedAccessKey=< my-policy-key > "
2016-10-28 15:06:48 +03:00
}
```
2016-10-28 08:46:08 +03:00
2017-08-16 14:31:44 +03:00
Device Connection String:
2016-10-28 15:06:48 +03:00
```json
{
2017-08-16 14:31:44 +03:00
"azure-iot-toolkit.deviceConnectionString": "HostName=< my-hub > .azure-devices.net;DeviceId=< known-device-id > ;SharedAccessKey=< known-device-key > "
2016-10-28 15:06:48 +03:00
}
```
2016-10-28 08:46:08 +03:00
2017-08-17 06:51:44 +03:00
IoT Hub Consumer Group (default is `"$Default"` ):
2016-10-28 15:06:48 +03:00
```json
{
2017-02-27 16:23:08 +03:00
"azure-iot-toolkit.iotHubConsumerGroup": "$Default"
}
```
2017-08-16 14:31:44 +03:00
Whether to show verbose info when monitoring messages (default is `false` ):
2017-02-28 10:34:34 +03:00
```json
{
2017-08-16 14:31:44 +03:00
"azure-iot-toolkit.showVerboseMessage": false
2017-02-28 10:34:34 +03:00
}
```
2017-08-16 14:31:44 +03:00
Whether to stringify device-to-cloud messages (default is `false` ):
2017-06-28 04:21:03 +03:00
```json
{
2017-08-16 14:31:44 +03:00
"azure-iot-toolkit.iotHubD2CMessageStringify": false
2016-10-28 15:06:48 +03:00
}
```
2017-09-22 07:03:21 +03:00
Whether to show IoT Hub info when IoT Hub Connection String is not set (default is `true` ):
```json
{
"azure-iot-toolkit.showIoTHubInfo": true
}
```
2017-12-22 06:57:27 +03:00
2018-06-15 09:16:22 +03:00
## Resources
- [Channel 9 video: Walkthrough of Azure IoT Toolkit extension ](https://channel9.msdn.com/Shows/Internet-of-Things-Show/Azure-IoT-Toolkit-extension-for-Visual-Studio-Code )
- [Handy Tool When You Develop With Azure IoT ](https://blogs.msdn.microsoft.com/iotdev/2017/09/01/handy-tool-when-you-develop-with-azure-iot/ )
2017-12-22 06:57:27 +03:00
2018-03-13 06:42:06 +03:00
## Data/Telemetry
This project collects usage data and sends it to Microsoft to help improve our products and services. Read our [privacy statement ](http://go.microsoft.com/fwlink/?LinkId=521839 ) to learn more.
If you don’ t wish to send usage data to Microsoft, you can set the `telemetry.enableTelemetry` setting to `false` . Learn more in our [FAQ ](https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting ).