This commit is contained in:
Jun Han 2017-08-15 15:53:09 +08:00 коммит произвёл GitHub
Родитель b1718b5888
Коммит b657b76820
6 изменённых файлов: 7 добавлений и 363 удалений

Просмотреть файл

@ -1,7 +1,5 @@
# Azure IoT Toolkit
[![Join the chat at https://gitter.im/formulahendry/vscode-azure-iot-toolkit](https://badges.gitter.im/formulahendry/vscode-azure-iot-toolkit.svg)](https://gitter.im/formulahendry/vscode-azure-iot-toolkit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Marketplace Version](https://vsmarketplacebadge.apphb.com/version-short/formulahendry.azure-iot-toolkit.svg)](https://marketplace.visualstudio.com/items?itemName=formulahendry.azure-iot-toolkit) [![Installs](https://vsmarketplacebadge.apphb.com/installs-short/formulahendry.azure-iot-toolkit.svg)](https://marketplace.visualstudio.com/items?itemName=formulahendry.azure-iot-toolkit) [![Rating](https://vsmarketplacebadge.apphb.com/rating-short/formulahendry.azure-iot-toolkit.svg)](https://marketplace.visualstudio.com/items?itemName=formulahendry.azure-iot-toolkit) [![Build Status](https://travis-ci.org/formulahendry/vscode-azure-iot-toolkit.svg?branch=master)](https://travis-ci.org/formulahendry/vscode-azure-iot-toolkit) [![Build status](https://ci.appveyor.com/api/projects/status/fh583240003oggc0?svg=true)](https://ci.appveyor.com/project/formulahendry/vscode-azure-iot-toolkit)
Toolkit makes Azure IoT Development easier. For more awesome Azure IoT projects and resources, please visit https://aka.ms/azure.iot
## Features
@ -14,25 +12,14 @@ Toolkit makes Azure IoT Development easier. For more awesome Azure IoT projects
[x] Code snippet for IoT Hub
[x] Send messages to Azure Event Hub
[x] Monitor Event Hub messages
[x] Send/monitor messages from Azure IoT Hub to device (cloud-to-device message)
[x] Device management (List, Create, Delete)
[x] Discover devices connected via Ethernet, USB serial and WiFi
[x] Deploy and run in remote machine
[x] Invoke Direct Method
[x] Get/update Device Twin
[ ] Debug in remote machines
[ ] And more...
## Device Explorer
@ -73,15 +60,9 @@ Toolkit makes Azure IoT Development easier. For more awesome Azure IoT projects
| IoT: Send C2D message to device | None | view/item/context |
| IoT: Start monitoring C2D message | None | view/item/context |
| IoT: Stop monitoring C2D message | None | editor/context (in output panel) |
| IoT: Send message to Event Hub | None | editor/context |
| IoT: Start monitoring Event Hub message | None | editor/context |
| IoT: Stop monitoring Event Hub message | None | editor/context (in output panel) |
| IoT: List device | Ctrl+Alt+F1 | None |
| IoT: Create device | Ctrl+Alt+F2 | view/title |
| IoT: Delete device | Ctrl+Alt+F3 | view/item/context |
| IoT: Discover connected device | Ctrl+Alt+F6 | editor/context |
| IoT: Deploy to remote machine | Ctrl+Alt+F4 | None |
| IoT: Run in remote machine | Ctrl+Alt+F5 | None |
## Usages
@ -101,33 +82,6 @@ Toolkit makes Azure IoT Development easier. For more awesome Azure IoT projects
> 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).
* Send/monitor messages for Azure Event Hub
![Event Hub](images/event-hub.gif)
* Deploy and run in remote machine
| Config | description |
| ---- | ---- |
| azure-iot-toolkit.localFolder | The folder of current machine to deploy |
| azure-iot-toolkit.remoteFolder | The folder of remote machine to deploy |
| azure-iot-toolkit.host | The hostname or IP address of remote machine |
| azure-iot-toolkit.username | The username of remote machine |
| azure-iot-toolkit.password | The password of remote machine |
| azure-iot-toolkit.command | The command to run in remote machine |
![Remote](images/remote.gif)
* Discover Ethernet, USB serial, WiFi devices
1. Install Node.js or install [device-discovery-cli](https://github.com/Azure/device-discovery-cli):
```
$ npm install --global device-discovery-cli
```
2. Discover devices in VS Code:
![Device](images/discover.gif)
## Configuration
To set the Device Connection String which is used to send device-to-cloud message or other functions as a device simulator:
@ -151,27 +105,6 @@ To set the IoT Hub Consumer Group (default is "$Default"):
}
```
To set the Event Hub Connection String:
```json
{
"azure-iot-toolkit.eventHubConnectionString": "{Event Hubs connection string}"
}
```
To set the Event Hub Path:
```json
{
"azure-iot-toolkit.eventHubPath": "{Event Hub path/name}"
}
```
To set the Event Hub Consumer Group (default is "$Default"):
```json
{
"azure-iot-toolkit.eventHubConsumerGroup": "$Default"
}
```
To set whether to show verbose info when monitoring messages (default is `true`):
```json
{
@ -198,7 +131,7 @@ By default, anonymous telemetry data collection is turned on to understand user
See Change Log [here](CHANGELOG.md)
## Issues
Submit the [issues](https://github.com/formulahendry/vscode-azure-iot-toolkit/issues) if you find any bug or have any suggestion.
Submit the [issues](https://github.com/Microsoft/vscode-azure-iot-toolkit/issues) if you find any bug or have any suggestion.
## Contribution
Fork the [repo](https://github.com/formulahendry/vscode-azure-iot-toolkit) and submit pull requests.
Fork the [repo](https://github.com/Microsoft/vscode-azure-iot-toolkit) and submit pull requests.

Просмотреть файл

@ -1,7 +1,7 @@
{
"name": "azure-iot-toolkit",
"displayName": "Azure IoT Toolkit",
"description": "Interact with Azure IoT Hub and Azure Event Hub; IoT Device Management; IoT Hub Code Snippets; Discover Ethernet, USB serial, WiFi connected devices; Deploy and run in remote machine (e.g. Raspberry Pi, Arduino)",
"description": "Interact with Azure IoT Hub; IoT Device Management; IoT Hub Code Snippets;",
"version": "0.1.4",
"publisher": "formulahendry",
"icon": "logo.png",
@ -21,13 +21,12 @@
"cloud"
],
"bugs": {
"url": "https://github.com/formulahendry/vscode-azure-iot-toolkit/issues",
"email": "formulahendry@gmail.com"
"url": "https://github.com/Microsoft/vscode-azure-iot-toolkit/issues"
},
"homepage": "https://github.com/formulahendry/vscode-azure-iot-toolkit/blob/master/README.md",
"homepage": "https://github.com/Microsoft/vscode-azure-iot-toolkit/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/formulahendry/vscode-azure-iot-toolkit.git"
"url": "https://github.com/Microsoft/vscode-azure-iot-toolkit.git"
},
"activationEvents": [
"*",
@ -35,14 +34,9 @@
"onCommand:azure-iot-toolkit.startMonitorIoTHubMessage",
"onCommand:azure-iot-toolkit.sendC2DMessage",
"onCommand:azure-iot-toolkit.startMonitorC2DMessage",
"onCommand:azure-iot-toolkit.sendMessageToEventHub",
"onCommand:azure-iot-toolkit.startMonitorEventHubMessage",
"onCommand:azure-iot-toolkit.listDevice",
"onCommand:azure-iot-toolkit.createDevice",
"onCommand:azure-iot-toolkit.deleteDevice",
"onCommand:azure-iot-toolkit.discoverDevice",
"onCommand:azure-iot-toolkit.deploy",
"onCommand:azure-iot-toolkit.run",
"onCommand:azure-iot-toolkit.invokeDeviceMethod",
"onCommand:azure-iot-toolkit.getDeviceTwin",
"onCommand:azure-iot-toolkit.updateDeviceTwin"
@ -82,18 +76,6 @@
"command": "azure-iot-toolkit.stopMonitorC2DMessage",
"title": "IoT: Stop monitoring C2D message"
},
{
"command": "azure-iot-toolkit.sendMessageToEventHub",
"title": "IoT: Send message to Event Hub"
},
{
"command": "azure-iot-toolkit.startMonitorEventHubMessage",
"title": "IoT: Start monitoring Event Hub message"
},
{
"command": "azure-iot-toolkit.stopMonitorEventHubMessage",
"title": "IoT: Stop monitoring Event Hub message"
},
{
"command": "azure-iot-toolkit.listDevice",
"title": "IoT: List device"
@ -106,18 +88,6 @@
"command": "azure-iot-toolkit.deleteDevice",
"title": "IoT: Delete device"
},
{
"command": "azure-iot-toolkit.discoverDevice",
"title": "IoT: Discover connected device"
},
{
"command": "azure-iot-toolkit.deploy",
"title": "IoT: Deploy to remote machine"
},
{
"command": "azure-iot-toolkit.run",
"title": "IoT: Run in remote machine"
},
{
"command": "azure-iot-toolkit.invokeDeviceMethod",
"title": "IoT: Invoke Direct Method"
@ -243,21 +213,6 @@
"command": "azure-iot-toolkit.sendMessageToEventHub",
"group": "azure-iot-toolkit@1"
},
{
"when": "!inOutput",
"command": "azure-iot-toolkit.startMonitorEventHubMessage",
"group": "azure-iot-toolkit@2"
},
{
"when": "inOutput",
"command": "azure-iot-toolkit.stopMonitorEventHubMessage",
"group": "azure-iot-toolkit@3"
},
{
"when": "!inOutput",
"command": "azure-iot-toolkit.discoverDevice",
"group": "azure-iot-toolkit@3"
},
{
"when": "resourceFilename == azure-iot-device-twin.json",
"command": "azure-iot-toolkit.updateDeviceTwin",
@ -279,26 +234,11 @@
"default": "<<insert your IoT Hub Connection String>>",
"description": "IoT Hub Connection String"
},
"azure-iot-toolkit.eventHubConnectionString": {
"type": "string",
"default": "<<insert your Event Hub Connection String>>",
"description": "Event Hub Connection String"
},
"azure-iot-toolkit.eventHubPath": {
"type": "string",
"default": "<<insert your Event Hub Path>>",
"description": "Event Hub Path"
},
"azure-iot-toolkit.iotHubConsumerGroup": {
"type": "string",
"default": "$Default",
"description": "IoT Hub Consumer Group"
},
"azure-iot-toolkit.eventHubConsumerGroup": {
"type": "string",
"default": "$Default",
"description": "Event Hub Consumer Group"
},
"azure-iot-toolkit.showVerboseMessage": {
"type": "boolean",
"default": true,
@ -313,36 +253,6 @@
"type": "boolean",
"default": true,
"description": "Whether to enable AppInsights to track anonymous telemetry data."
},
"azure-iot-toolkit.localFolder": {
"type": "string",
"default": "",
"description": "The folder of current machine to deploy"
},
"azure-iot-toolkit.remoteFolder": {
"type": "string",
"default": "",
"description": "The folder of remote machine to deploy"
},
"azure-iot-toolkit.host": {
"type": "string",
"default": "",
"description": "The hostname or IP address of remote machine"
},
"azure-iot-toolkit.username": {
"type": "string",
"default": "",
"description": "The username of remote machine"
},
"azure-iot-toolkit.password": {
"type": "string",
"default": "",
"description": "The password of remote machine"
},
"azure-iot-toolkit.command": {
"type": "string",
"default": "",
"description": "The command to run in remote machine"
}
}
},
@ -373,9 +283,6 @@
"azure-event-hubs": "0.0.6",
"azure-iot-device": "1.1.7",
"azure-iot-device-mqtt": "1.1.7",
"azure-iothub": "^1.1.13",
"device-discovery-cli": "^0.5.9",
"scp2": "^0.5.0",
"simple-ssh": "^0.9.0"
"azure-iothub": "^1.1.13"
}
}

Просмотреть файл

@ -1,8 +1,6 @@
"use strict";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { DeviceController } from "./deviceController";
import { DeviceDiscoverer } from "./deviceDiscoverer";
import { DeviceExplorer } from "./deviceExplorer";
import { EventHubMessageExplorer } from "./eventHubMessageExplorer";
import { IotHubC2DMessageExplorer } from "./iotHubC2DMessageExplorer";
@ -17,8 +15,6 @@ export class AzureIoTExplorer {
private _iotHubMessageExplorer: IoTHubMessageExplorer;
private _eventHubMessageExplorer: EventHubMessageExplorer;
private _deviceExplorer: DeviceExplorer;
private _deviceDiscoverer: DeviceDiscoverer;
private _deviceController: DeviceController;
private _snippetManager: SnippetManager;
private _iotHubDirectMethodExplorer: IotHubDirectMethodExplorer;
private _iotHubDeviceTwinExplorer: IotHubDeviceTwinExplorer;
@ -30,8 +26,6 @@ export class AzureIoTExplorer {
this._iotHubMessageExplorer = new IoTHubMessageExplorer(outputChannel);
this._eventHubMessageExplorer = new EventHubMessageExplorer(outputChannel);
this._deviceExplorer = new DeviceExplorer(outputChannel);
this._deviceDiscoverer = new DeviceDiscoverer(context, outputChannel);
this._deviceController = new DeviceController(outputChannel);
this._snippetManager = new SnippetManager(outputChannel);
this._iotHubDirectMethodExplorer = new IotHubDirectMethodExplorer(outputChannel);
this._iotHubDeviceTwinExplorer = new IotHubDeviceTwinExplorer(outputChannel);
@ -89,18 +83,6 @@ export class AzureIoTExplorer {
await this._deviceExplorer.deleteDevice(deviceItem);
}
public discoverDevice(): void {
this._deviceDiscoverer.discoverDevice();
}
public deploy(): void {
this._deviceController.deploy();
}
public run(): void {
this._deviceController.run();
}
public invokeDeviceMethod(deviceItem: DeviceItem): void {
this._iotHubDirectMethodExplorer.invokeDeviceMethod(deviceItem);
}

Просмотреть файл

@ -1,98 +0,0 @@
"use strict";
import * as vscode from "vscode";
import scp2 = require("scp2");
import SSH = require("simple-ssh");
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Utility } from "./utility";
export class DeviceController extends BaseExplorer {
private _localFolder: string;
private _remoteFolder: string;
private _host: string;
private _username: string;
private _password: string;
private _command: string;
private _label = "Remote";
constructor(outputChannel: vscode.OutputChannel) {
super(outputChannel);
}
public deploy(run = false): void {
this.getConfiguration();
this._outputChannel.show();
this.outputLine(this._label, `Deploying from '${this._localFolder}' to '${this._remoteFolder}'`);
let options = this.getScpOptions();
scp2.scp(this._localFolder, options, (err) => {
if (err) {
this.outputLine(this._label, "Deployment failed");
this.outputLine(this._label, err);
AppInsightsClient.sendEvent(`${this._label}.deploy`, { Result: "Fail" });
} else {
this.outputLine(this._label, "Deployment done");
AppInsightsClient.sendEvent(`${this._label}.deploy`, { Result: "Success" });
if (run) {
this.run();
}
}
});
}
public run(): void {
this.getConfiguration();
this._outputChannel.show();
this.outputLine(this._label, `Running '${this._command}'`);
this.sshExecCmd(this._command);
}
private sshExecCmd(cmd: string, callback = null) {
let ssh = new SSH(this.getSshOptions());
ssh.exec(cmd, {
pty: true,
out: (stdout) => {
this.outputLine(this._label, stdout);
},
err: (stderr) => {
this.outputLine(this._label, stderr);
},
exit: (code) => {
this.outputLine(this._label, `Exited with code=${code}`);
AppInsightsClient.sendEvent(`${this._label}.run`, { Code: code.toString() });
if (code === 0 && callback) {
callback();
}
},
}).start();
}
private getConfiguration(): void {
let config = Utility.getConfiguration();
this._localFolder = config.get<string>("localFolder");
this._remoteFolder = config.get<string>("remoteFolder");
this._host = config.get<string>("host");
this._username = config.get<string>("username");
this._password = config.get<string>("password");
this._command = config.get<string>("command");
}
private getScpOptions(): any {
return {
host: this._host,
username: this._username,
password: this._password,
path: this._remoteFolder,
};
}
private getSshOptions(): any {
return {
host: this._host,
user: this._username,
pass: this._password,
baseDir: this._remoteFolder,
timeout: 30000,
};
}
}

Просмотреть файл

@ -1,65 +0,0 @@
"use strict";
import { exec } from "child_process";
import * as path from "path";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Utility } from "./utility";
const types = ["eth", "usb", "wifi"];
const devdisco = "devdisco";
export class DeviceDiscoverer extends BaseExplorer {
private _deviceStatus = {};
private _context: vscode.ExtensionContext;
constructor(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel) {
super(outputChannel);
this._context = context;
}
public discoverDevice(): void {
let label = "Discovery";
vscode.window.showQuickPick(types, { placeHolder: "Enter device type to discover" }).then((type) => {
if (type !== undefined) {
this._outputChannel.show();
this.outputLine(label, `Start discovering ${type} devices..`);
this.deviceDiscovery(label, type);
}
});
}
private deviceDiscovery(label: string, type: string): void {
let devdiscoDir = this._context.asAbsolutePath(path.join("node_modules", "device-discovery-cli"));
let process = exec(`${devdisco} list --${type}`, { cwd: devdiscoDir });
let startTime = new Date();
let devdiscoNotFound = false;
let nodeNotFound = false;
process.stdout.on("data", (data) => {
this._outputChannel.append(data.toString());
});
process.stderr.on("data", (data) => {
data = data.toString();
this._outputChannel.append(data);
if (data.indexOf(devdisco) >= 0) {
devdiscoNotFound = true;
} else if (data.indexOf("node") >= 0) {
nodeNotFound = true;
}
});
process.on("close", (code) => {
let endTime = new Date();
let elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000;
AppInsightsClient.sendEvent(`${label}.${type}`, { Code: code.toString() });
this.outputLine(label, "Finished with exit code=" + code + " in " + elapsedTime + " seconds");
if (devdiscoNotFound && code >= 1) {
this.outputLine(label, "[Note!!!] Please install device-discovery-cli with below command if not yet:");
this.outputLine(label, "npm install --global device-discovery-cli");
} else if (nodeNotFound && code >= 1) {
this.outputLine(label, "[Note!!!] Please install Node.js if not yet");
}
});
}
}

Просмотреть файл

@ -67,18 +67,6 @@ export function activate(context: vscode.ExtensionContext) {
setTimeout(() => { deviceTree.refresh(); }, 2000);
});
let discoverDevice = vscode.commands.registerCommand("azure-iot-toolkit.discoverDevice", () => {
azureIoTExplorer.discoverDevice();
});
let deploy = vscode.commands.registerCommand("azure-iot-toolkit.deploy", () => {
azureIoTExplorer.deploy();
});
let run = vscode.commands.registerCommand("azure-iot-toolkit.run", () => {
azureIoTExplorer.run();
});
let invokeDeviceMethod = vscode.commands.registerCommand("azure-iot-toolkit.invokeDeviceMethod", (DeviceItem) => {
azureIoTExplorer.invokeDeviceMethod(DeviceItem);
});
@ -105,9 +93,6 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(listDevice);
context.subscriptions.push(createDevice);
context.subscriptions.push(deleteDevice);
context.subscriptions.push(discoverDevice);
context.subscriptions.push(deploy);
context.subscriptions.push(run);
context.subscriptions.push(invokeDeviceMethod);
context.subscriptions.push(getDeviceTwin);
context.subscriptions.push(updateDeviceTwin);