Skip to content

Commit

Permalink
Update README, handle error message when creating IoT Hub, align with…
Browse files Browse the repository at this point in the history
… Azure Portal to show modules (#62)

* Update README

* Add description for new Edge snippets

* Update ChangeLog, handle error message when creating IoT Hub

* Align with Azure Portal to show modules only when it is in $edgeAgent reportedTwin

* Add comment
  • Loading branch information
formulahendry authored Dec 22, 2017
1 parent 47454b3 commit 958d89e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* [Added] Show different icons for Edge devices
* [Added] Command to log in to container registry for Edge
* [Added] Code snippet for Edge module and route authoring
* [Added] List Edge Moudles
* [Added] List Edge Modules
* [Added] View Module Twin

### 0.4.3 (2017-12-06)
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ Interact with Azure IoT Hub, IoT Device Management, IoT Edge Management, IoT Hub

## Device Explorer

* IoT Hub management
* Create IoT Hub
* Select IoT Hub
* Device management
* List devices
* Get device info
* Create device
* Create IoT device
* Create Edge device
* Delete device
* Interact with Azure IoT Hub
* Send D2C message to IoT Hub
Expand All @@ -19,6 +23,8 @@ Interact with Azure IoT Hub, IoT Device Management, IoT Edge Management, IoT Hub
* Invoke Direct Method
* Get/update Device Twin
* 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)
* List Edge Moudles
* View Module Twin
* Manage Edge runtime
* Create deployment for Edge device
* Generate Edge setup configuration file
Expand Down Expand Up @@ -67,6 +73,8 @@ Instead of copying and pasting to set IoT Hub Connection String, you could sign
| iotMonitorC2DMessage | Monitor C2D message from IoT Hub |
| iotCallDirectMethods | Send direct methods to device |
| iotReceiveDirectMethods | Receive direct methods from IoT Hub |
| edgeModule | Add Edge module in Edge deployment manifest |
| edgeRoute | Add Edge route in Edge deployment manifest |

![Snippet](https://github.com/formulahendry/vscode-azure-iot-toolkit/raw/master/images/snippet.gif)

Expand Down
12 changes: 10 additions & 2 deletions src/iotHubResourceExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ export class IoTHubResourceExplorer extends BaseExplorer {
return iotHubDescription;
})
.catch((err) => {
vscode.window.showErrorMessage(err.message);
TelemetryClient.sendEvent(Constants.IoTHubAICreateDoneEvent, { Result: "Fail", Message: err.message });
let errorMessage: string;
if (err.message) {
errorMessage = err.message;
} else if (err.body && err.body.message) {
errorMessage = err.body.message;
} else {
errorMessage = "Error occurred when creating IoT Hub.";
}
vscode.window.showErrorMessage(errorMessage);
TelemetryClient.sendEvent(Constants.IoTHubAICreateDoneEvent, { Result: "Fail", Message: errorMessage });
return Promise.reject(err);
});
});
Expand Down
26 changes: 14 additions & 12 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,28 @@ export class Utility {
}

public static async getModuleItems(iotHubConnectionString: string, deviceId: string, context: vscode.ExtensionContext) {
/**
* modules: contains connection state of each module
* edgeAgent.properties.reported: contains runtime status of each module
*/
const [modules, edgeAgent] = await Promise.all([Utility.getModules(iotHubConnectionString, deviceId), Utility.getModuleTwin(iotHubConnectionString, deviceId, "$edgeAgent")]);
const reportedTwin = (edgeAgent as any).properties.reported;
// Only return modules that exist in edgeAgent.properties.reported
return modules.map((module) => {
const isConnected = module.connectionState === "Connected";
const state = isConnected ? "on" : "off";
const iconPath = context.asAbsolutePath(path.join("resources", `module-${state}.svg`));
if (isConnected) {
if (module.moduleId.startsWith("$")) {
const moduleId = module.moduleId.substring(1);
if (reportedTwin.systemModules && reportedTwin.systemModules[moduleId]) {
return new ModuleItem(deviceId, module.moduleId, reportedTwin.systemModules[moduleId].runtimeStatus, iconPath);
}
} else {
if (reportedTwin.modules && reportedTwin.modules[module.moduleId]) {
return new ModuleItem(deviceId, module.moduleId, reportedTwin.modules[module.moduleId].runtimeStatus, iconPath);
}
if (module.moduleId.startsWith("$")) {
const moduleId = module.moduleId.substring(1);
if (reportedTwin.systemModules && reportedTwin.systemModules[moduleId]) {
return new ModuleItem(deviceId, module.moduleId, isConnected ? reportedTwin.systemModules[moduleId].runtimeStatus : null, iconPath);
}
} else {
if (reportedTwin.modules && reportedTwin.modules[module.moduleId]) {
return new ModuleItem(deviceId, module.moduleId, isConnected ? reportedTwin.modules[module.moduleId].runtimeStatus : null, iconPath);
}
}
return new ModuleItem(deviceId, module.moduleId, null, iconPath);
});
}).filter((module) => module);
}

public static async getModules(iotHubConnectionString: string, deviceId: string): Promise<any[]> {
Expand Down

0 comments on commit 958d89e

Please sign in to comment.