From bda9d8589068aee2354008ba158f3698ff031d65 Mon Sep 17 00:00:00 2001 From: Dong Zhao Date: Sun, 18 Sep 2016 14:36:05 +0800 Subject: [PATCH 01/10] Fix bug don't show correct device name for device type thingdev --- src/lib/usb-mapping.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/usb-mapping.csv b/src/lib/usb-mapping.csv index 61a811b..8324f69 100644 --- a/src/lib/usb-mapping.csv +++ b/src/lib/usb-mapping.csv @@ -10,7 +10,7 @@ USB\VID_10C4&PID_EA60\ Silicon Labs CP210x USB to UART Bridge huzzah # for Adafruit Feather M0 USB\VID_239A&PID_800B&MI_00\ USB Serial Device adafruit_feather_m0_usb # for SparkFun ESP8266 Thing Dev -FTDIBUS\VID_0403+PID_6015+DN01AIYZA\ USB Serial Port thingdev +FTDIBUS\VID_0403+PID_6015+ USB Serial Port thingdev # for Linux # for Intel Edison From aaf37105a5732747a1945e8d31c61ba31a56b1df Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 20 Sep 2016 18:17:32 +0800 Subject: [PATCH 02/10] update license --- LICENSE.txt | 1 + readme.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index fa7891d..a3143d5 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -3,6 +3,7 @@ Copyright (c) Microsoft Corporation All rights reserved. MIT License + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights diff --git a/readme.md b/readme.md index 34fc515..b20acd0 100644 --- a/readme.md +++ b/readme.md @@ -68,4 +68,4 @@ $ npm install --global device-discovery-cli ## License -[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) +[MIT License](./LICENSE.txt) From fd88e317600ea8695ba7c41068b60adc8d5b26b7 Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Mon, 26 Sep 2016 15:41:29 +0800 Subject: [PATCH 03/10] bi and minor fix --- package.json | 2 +- readme.md | 6 +++--- src/devdisco.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 950c0a5..355692b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "url": "https://github.com/Azure/device-discovery-cli" }, "dependencies": { - "az-iot-bi-test": "0.0.3", + "az-iot-bi": "0.1.2", "dns": "^0.2.2", "mdns-js": "^0.5.0", "node-arp": "^1.0.5", diff --git a/readme.md b/readme.md index b20acd0..48b1e34 100644 --- a/readme.md +++ b/readme.md @@ -27,11 +27,11 @@ $ npm install --global device-discovery-cli devdisco list --usb list the USB serial devices devdisco list --wifi list the Wi-Fi devices - devdisco@0.5.0 /usr/bin/devdisco + devdisco@0.5.5 /usr/bin/devdisco ## Sample Output -##### Ethernet Devices +##### Ethernet LAN Devices: IP Address MAC Address Type Host Name @@ -52,7 +52,7 @@ $ npm install --global device-discovery-cli 10.172.15.148 94:57:a5:cc:99:86 ? -##### USB UART Devices +##### USB UART Devices: COM Port Device Name\Manufacturer Device Type (Friendly Name) diff --git a/src/devdisco.js b/src/devdisco.js index a2b8e11..5c96a9a 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -18,7 +18,7 @@ 'use strict'; -var bi = require('az-iot-bi-test'); +var bi = require('az-iot-bi'); var path = require('path'); var UsbUartTransport = require('./lib/usb-uart-transport'); @@ -197,7 +197,7 @@ function cmd_list_wifi_ap() { function cmd_list_usb_uart() { console.log(''); - console.log('USB Devices:'); + console.log('USB UART Devices:'); console.log(''); console.log(rpad('COM Port', 28), rpad('Device Name\\Manufacturer', 40), rpad('Device Type (Friendly Name)', 46)); console.log(''); From 5997afe4fbc488c3cfcd7ed37d647384fe857fe5 Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Thu, 29 Sep 2016 09:50:04 +0800 Subject: [PATCH 04/10] Add exception handling --- src/devdisco.js | 17 +++++++++--- src/lib/ethernet-transport.js | 7 +++++ src/lib/usb-uart-transport.js | 51 ++++++++++++++++++++--------------- src/lib/wifi-ap-transport.js | 47 ++++++++++++++++++-------------- 4 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/devdisco.js b/src/devdisco.js index 5c96a9a..2f12994 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -204,6 +204,17 @@ function cmd_list_usb_uart() { UsbUartTransport.beginDiscovery(onDeviceDiscovered); } -bi.start(); -main(process.argv.slice(1)); -bi.flush(); +var d = require('domain').create() +d.on('error', function(err){ + bi.trackEvent('unknown_error', { + error: err + }); + bi.flush(); + console.log(err); +}) + +d.run(function(){ + bi.start(); + main(process.argv.slice(1)); + bi.flush(); +}) diff --git a/src/lib/ethernet-transport.js b/src/lib/ethernet-transport.js index 0f3b8c1..b430565 100644 --- a/src/lib/ethernet-transport.js +++ b/src/lib/ethernet-transport.js @@ -1,6 +1,7 @@ 'use-strict'; var arp = require('node-arp'); +var bi = require('az-iot-bi'); var dns = require('dns'); var mdns = require('mdns-js'); var vow = require('vow'); @@ -11,6 +12,9 @@ function resolveIpAddressToHostNameAsync(address) { return new vow.Promise(function(resolve, reject /*, notify */) { dns.reverse(address, function(err, domains) { if(err) { + bi.trackEvent('ethernet_error', { + error: err + }); reject(err); return; } @@ -23,6 +27,9 @@ function resolveIpAddressToMacAddressAsync(address) { return new vow.Promise(function(resolve, reject /*, notify */) { arp.getMAC(address, function(err, mac) { if(err) { + bi.trackEvent('ethernet_error', { + error: err + }); reject(err); return; } diff --git a/src/lib/usb-uart-transport.js b/src/lib/usb-uart-transport.js index 5e20a6d..10018ce 100644 --- a/src/lib/usb-uart-transport.js +++ b/src/lib/usb-uart-transport.js @@ -1,32 +1,41 @@ 'use-strict'; +var bi = require('az-iot-bi'); var serialPort = require('serialport'); var UsbLookup = require('./usb-lookup'); exports.beginDiscovery = function beginDiscovery(callback) { - serialPort.list(function (err, ports) { - if(err){ - return; - } - ports.forEach(function(port) { - var pnpId = port.pnpId; - if(!pnpId && port.vendorId && port.productId){ - pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1]; + return new Promise(function(resolve, reject) { + serialPort.list(function (err, ports) { + if(err){ + bi.trackEvent('usb_error', { + error: err + }); + reject(err); + return; } - var deviceName = UsbLookup.resolveUsbName(pnpId); - var deviceType = UsbLookup.resolveDeviceType(pnpId); - var deviceNameOrManufacturer = deviceName ? deviceName : port.manufacturer; - (function(com_name, device_name_or_manufacturer, device_type) { - if(com_name && device_name_or_manufacturer) { - var record = { - com_name: com_name, - device_name_or_manufacturer: device_name_or_manufacturer, - device_type: device_type, - transport: 'usb-uart', - }; - callback(record); + + ports.forEach(function(port) { + var pnpId = port.pnpId; + if(!pnpId && port.vendorId && port.productId){ + pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1]; } - })(port.comName, deviceNameOrManufacturer, deviceType); + var deviceName = UsbLookup.resolveUsbName(pnpId); + var deviceType = UsbLookup.resolveDeviceType(pnpId); + var deviceNameOrManufacturer = deviceName ? deviceName : port.manufacturer; + (function(com_name, device_name_or_manufacturer, device_type) { + if(com_name && device_name_or_manufacturer) { + var record = { + com_name: com_name, + device_name_or_manufacturer: device_name_or_manufacturer, + device_type: device_type, + transport: 'usb-uart', + }; + callback(record); + } + })(port.comName, deviceNameOrManufacturer, deviceType); + }); + resolve(ports); }); }); }; diff --git a/src/lib/wifi-ap-transport.js b/src/lib/wifi-ap-transport.js index 1ceaf23..0380c7b 100644 --- a/src/lib/wifi-ap-transport.js +++ b/src/lib/wifi-ap-transport.js @@ -1,29 +1,36 @@ 'use-strict'; +var bi = require('az-iot-bi'); var wifiscanner = require('node-wifiscanner'); - var OuiLookup = require('./oui-lookup'); exports.beginDiscovery = function beginDiscovery(callback) { - wifiscanner.scan(function(err, data) { - if (err) { - return; - } - for (var i = 0; i < data.length; i++) { - (function(ssid, mac_address, channel, signal_level) { - var device_type = OuiLookup.resolveMacToDeviceType(mac_address); - var record = { - channel: channel, - device_type: device_type, - mac_address: mac_address, - signal_level: signal_level, - ssid: ssid, - transport: 'wifi-ap', - }; - callback(record); - })(data[i].ssid, data[i].mac, data[i].channel, data[i].signal_level); - } - }); + return new Promise(function(resolve, reject) { + wifiscanner.scan(function(err, data) { + if (err) { + bi.trackEvent('wifi_error', { + error: err + }); + reject('\nProbably no Wi-Fi module on this computer.\n' + err.message); + return; + } + for (var i = 0; i < data.length; i++) { + (function(ssid, mac_address, channel, signal_level) { + var device_type = OuiLookup.resolveMacToDeviceType(mac_address); + var record = { + channel: channel, + device_type: device_type, + mac_address: mac_address, + signal_level: signal_level, + ssid: ssid, + transport: 'wifi-ap', + }; + callback(record); + })(data[i].ssid, data[i].mac, data[i].channel, data[i].signal_level); + } + resolve(data); + }); + }) }; exports.endDiscovery = function endDiscovery(/* callback */) { From 066662a602c96907293ed585b112615d109bb10c Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Thu, 29 Sep 2016 09:54:38 +0800 Subject: [PATCH 05/10] Minor fix --- src/devdisco.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devdisco.js b/src/devdisco.js index 2f12994..e17fb50 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -204,7 +204,7 @@ function cmd_list_usb_uart() { UsbUartTransport.beginDiscovery(onDeviceDiscovered); } -var d = require('domain').create() +var d = require('domain').create(); d.on('error', function(err){ bi.trackEvent('unknown_error', { error: err From 5e25729b9e7088b0e843ee86a87d3b578fb8f1ed Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Thu, 29 Sep 2016 17:38:32 +0800 Subject: [PATCH 06/10] Minor fix --- src/devdisco.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devdisco.js b/src/devdisco.js index e17fb50..b583162 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -204,8 +204,8 @@ function cmd_list_usb_uart() { UsbUartTransport.beginDiscovery(onDeviceDiscovered); } -var d = require('domain').create(); -d.on('error', function(err){ +var domain = require('domain').create(); +domain.on('error', function(err){ bi.trackEvent('unknown_error', { error: err }); @@ -213,7 +213,7 @@ d.on('error', function(err){ console.log(err); }) -d.run(function(){ +domain.run(function(){ bi.start(); main(process.argv.slice(1)); bi.flush(); From 909b2c549aa3f39bcc8daf7b4e6780b26be93b62 Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Fri, 30 Sep 2016 14:48:54 +0800 Subject: [PATCH 07/10] Change the key of the log to info --- src/devdisco.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devdisco.js b/src/devdisco.js index b583162..ca7068d 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -30,7 +30,7 @@ var VERSION = require('../package.json').version; function main(argv) { bi.trackEvent('command_line_arguments', { - argv: argv + info: argv }); if (argv.length === 1) { From 1aa52285ffa40e158fd110ad3d6de81757abcaf9 Mon Sep 17 00:00:00 2001 From: "FAREAST\\donzh" Date: Fri, 30 Sep 2016 15:23:05 +0800 Subject: [PATCH 08/10] Update usage of bi --- src/devdisco.js | 4 ++-- src/lib/ethernet-transport.js | 4 ++-- src/lib/usb-uart-transport.js | 2 +- src/lib/wifi-ap-transport.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devdisco.js b/src/devdisco.js index ca7068d..e0032f0 100644 --- a/src/devdisco.js +++ b/src/devdisco.js @@ -30,7 +30,7 @@ var VERSION = require('../package.json').version; function main(argv) { bi.trackEvent('command_line_arguments', { - info: argv + info: argv.join(' ') }); if (argv.length === 1) { @@ -207,7 +207,7 @@ function cmd_list_usb_uart() { var domain = require('domain').create(); domain.on('error', function(err){ bi.trackEvent('unknown_error', { - error: err + error: err.message }); bi.flush(); console.log(err); diff --git a/src/lib/ethernet-transport.js b/src/lib/ethernet-transport.js index b430565..f819f56 100644 --- a/src/lib/ethernet-transport.js +++ b/src/lib/ethernet-transport.js @@ -13,7 +13,7 @@ function resolveIpAddressToHostNameAsync(address) { dns.reverse(address, function(err, domains) { if(err) { bi.trackEvent('ethernet_error', { - error: err + error: err.message }); reject(err); return; @@ -28,7 +28,7 @@ function resolveIpAddressToMacAddressAsync(address) { arp.getMAC(address, function(err, mac) { if(err) { bi.trackEvent('ethernet_error', { - error: err + error: err.message }); reject(err); return; diff --git a/src/lib/usb-uart-transport.js b/src/lib/usb-uart-transport.js index 10018ce..52e46ca 100644 --- a/src/lib/usb-uart-transport.js +++ b/src/lib/usb-uart-transport.js @@ -9,7 +9,7 @@ exports.beginDiscovery = function beginDiscovery(callback) { serialPort.list(function (err, ports) { if(err){ bi.trackEvent('usb_error', { - error: err + error: err.message }); reject(err); return; diff --git a/src/lib/wifi-ap-transport.js b/src/lib/wifi-ap-transport.js index 0380c7b..88a4b68 100644 --- a/src/lib/wifi-ap-transport.js +++ b/src/lib/wifi-ap-transport.js @@ -9,7 +9,7 @@ exports.beginDiscovery = function beginDiscovery(callback) { wifiscanner.scan(function(err, data) { if (err) { bi.trackEvent('wifi_error', { - error: err + error: err.message }); reject('\nProbably no Wi-Fi module on this computer.\n' + err.message); return; From 0de75af775e0b049f3d1f72b1149a10188195a47 Mon Sep 17 00:00:00 2001 From: Kevin Zhao Date: Wed, 19 Oct 2016 12:42:55 +0800 Subject: [PATCH 09/10] update az-iot-bi to 0.1.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 355692b..910e3fa 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "url": "https://github.com/Azure/device-discovery-cli" }, "dependencies": { - "az-iot-bi": "0.1.2", + "az-iot-bi": "0.1.7", "dns": "^0.2.2", "mdns-js": "^0.5.0", "node-arp": "^1.0.5", From e043897629e53e20d4088021cbcfaac57441eec3 Mon Sep 17 00:00:00 2001 From: ZhijunZhao Date: Thu, 20 Oct 2016 13:33:28 +0800 Subject: [PATCH 10/10] 0.5.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 910e3fa..64c2bfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "device-discovery-cli", - "version": "0.5.5", + "version": "0.5.6", "description": "device discovery and management command line utility", "bin": { "devdisco": "./dist/devdisco.js"