From 29f169cbcb8cbb23756bd0ef66acf0c000ca9697 Mon Sep 17 00:00:00 2001 From: Elena Horton Date: Wed, 21 Oct 2020 09:49:33 -0700 Subject: [PATCH] remove old digital twins files --- .../device/javascript/deviceInformation.js | 20 --- .../javascript/environmentalinterface.js | 23 ---- .../Samples/device/javascript/package.json | 21 ---- .../Samples/device/javascript/readme.md | 38 ------ .../device/javascript/sample_device.js | 65 ---------- digital-twins/Samples/device/readme.md | 12 -- .../Samples/device/typescript/package.json | 41 ------ .../Samples/device/typescript/readme.md | 45 ------- .../typescript/src/deviceinfointerface.ts | 32 ----- .../typescript/src/environmentalinterface.ts | 38 ------ .../device/typescript/src/exitInterface.ts | 13 -- .../device/typescript/src/sample_device.ts | 118 ------------------ .../Samples/device/typescript/tsconfig.json | 16 --- .../environmentalinterface.js | 24 ---- .../Samples/iot_central_device/package.json | 24 ---- .../Samples/iot_central_device/readme.md | 47 ------- .../iot_central_device/sample_device.js | 72 ----------- .../Samples/model_repository/model_repo.js | 60 --------- .../Samples/model_repository/package.json | 21 ---- .../Samples/model_repository/readme.md | 38 ------ digital-twins/Samples/readme.md | 26 ---- .../Samples/service/get_digital_twin.js | 29 ----- .../get_digital_twin_interface_instance.js | 30 ----- digital-twins/Samples/service/get_model.js | 27 ---- .../Samples/service/invoke_command.js | 31 ----- digital-twins/Samples/service/package.json | 21 ---- .../Samples/service/query_interface.js | 21 ---- digital-twins/Samples/service/readme.md | 42 ------- .../Samples/service/receive_telemetry.js | 44 ------- .../Samples/service/update_digital_twin.js | 51 -------- .../service/update_digital_twin_property.js | 40 ------ 31 files changed, 1130 deletions(-) delete mode 100644 digital-twins/Samples/device/javascript/deviceInformation.js delete mode 100644 digital-twins/Samples/device/javascript/environmentalinterface.js delete mode 100644 digital-twins/Samples/device/javascript/package.json delete mode 100644 digital-twins/Samples/device/javascript/readme.md delete mode 100644 digital-twins/Samples/device/javascript/sample_device.js delete mode 100644 digital-twins/Samples/device/readme.md delete mode 100644 digital-twins/Samples/device/typescript/package.json delete mode 100644 digital-twins/Samples/device/typescript/readme.md delete mode 100644 digital-twins/Samples/device/typescript/src/deviceinfointerface.ts delete mode 100644 digital-twins/Samples/device/typescript/src/environmentalinterface.ts delete mode 100644 digital-twins/Samples/device/typescript/src/exitInterface.ts delete mode 100644 digital-twins/Samples/device/typescript/src/sample_device.ts delete mode 100644 digital-twins/Samples/device/typescript/tsconfig.json delete mode 100644 digital-twins/Samples/iot_central_device/environmentalinterface.js delete mode 100644 digital-twins/Samples/iot_central_device/package.json delete mode 100644 digital-twins/Samples/iot_central_device/readme.md delete mode 100644 digital-twins/Samples/iot_central_device/sample_device.js delete mode 100644 digital-twins/Samples/model_repository/model_repo.js delete mode 100644 digital-twins/Samples/model_repository/package.json delete mode 100644 digital-twins/Samples/model_repository/readme.md delete mode 100644 digital-twins/Samples/readme.md delete mode 100644 digital-twins/Samples/service/get_digital_twin.js delete mode 100644 digital-twins/Samples/service/get_digital_twin_interface_instance.js delete mode 100644 digital-twins/Samples/service/get_model.js delete mode 100644 digital-twins/Samples/service/invoke_command.js delete mode 100644 digital-twins/Samples/service/package.json delete mode 100644 digital-twins/Samples/service/query_interface.js delete mode 100644 digital-twins/Samples/service/readme.md delete mode 100644 digital-twins/Samples/service/receive_telemetry.js delete mode 100644 digital-twins/Samples/service/update_digital_twin.js delete mode 100644 digital-twins/Samples/service/update_digital_twin_property.js diff --git a/digital-twins/Samples/device/javascript/deviceInformation.js b/digital-twins/Samples/device/javascript/deviceInformation.js deleted file mode 100644 index ad55d85..0000000 --- a/digital-twins/Samples/device/javascript/deviceInformation.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -'use strict'; - -const BaseInterface = require('azure-iot-digitaltwins-device').BaseInterface; -const Property = require('azure-iot-digitaltwins-device').Property; - -module.exports.DeviceInformation = class DeviceInformation extends BaseInterface { - constructor(name, propertyCallback, commandCallback) { - super(name, 'urn:azureiot:DeviceManagement:DeviceInformation:1', propertyCallback, commandCallback); - this.manufacturer = new Property(); - this.model = new Property(); - this.swVersion = new Property(); - this.osName = new Property(); - this.processorArchitecture = new Property(); - this.processorManufacturer = new Property(); - this.totalStorage = new Property(); - this.totalMemory = new Property(); - } -}; diff --git a/digital-twins/Samples/device/javascript/environmentalinterface.js b/digital-twins/Samples/device/javascript/environmentalinterface.js deleted file mode 100644 index c993c42..0000000 --- a/digital-twins/Samples/device/javascript/environmentalinterface.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -'use strict'; - -const BaseInterface = require('azure-iot-digitaltwins-device').BaseInterface; -const Telemetry = require('azure-iot-digitaltwins-device').Telemetry; -const Property = require('azure-iot-digitaltwins-device').Property; -const Command = require('azure-iot-digitaltwins-device').Command; - -module.exports.EnvironmentalSensor = class EnvironmentalSensor extends BaseInterface { - constructor(name, propertyCallback, commandCallback) { - super(name, 'urn:contoso:com:EnvironmentalSensor:1', propertyCallback, commandCallback); - this.temp = new Telemetry(); - this.humid = new Telemetry(); - this.state = new Property(); - this.blink = new Command(); - this.turnOff = new Command(); - this.turnOn = new Command(); - this.runDiagnostics = new Command(); - this.name = new Property(true); - this.brightness = new Property(true); - } -}; diff --git a/digital-twins/Samples/device/javascript/package.json b/digital-twins/Samples/device/javascript/package.json deleted file mode 100644 index c65a07e..0000000 --- a/digital-twins/Samples/device/javascript/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "azure-iot-digitaltwins-device-samples", - "version": "1.0.0-preview.1", - "description": "Samples for the azure-iot-digitaltwins-device client library", - "repository": { - "type": "git", - "url": "git+https://github.com/azure/azure-iot-sdk-node-digitaltwins.git" - }, - "author": "Microsoft Corp.", - "license": "MIT", - "bugs": { - "url": "https://github.com/azure/azure-iot-sdk-node-digitaltwins/issues" - }, - "homepage": "https://github.com/azure/azure-iot-sdk-node-digitaltwins#readme", - "dependencies": { - "azure-iot-device": "1.12.0-preview.1", - "azure-iot-common": "1.12.0-preview.1", - "azure-iot-device-mqtt": "1.12.0-preview.1", - "azure-iot-digitaltwins-device": "1.0.0-preview.1" - } -} \ No newline at end of file diff --git a/digital-twins/Samples/device/javascript/readme.md b/digital-twins/Samples/device/javascript/readme.md deleted file mode 100644 index 1859400..0000000 --- a/digital-twins/Samples/device/javascript/readme.md +++ /dev/null @@ -1,38 +0,0 @@ -# Azure IoT Digital Twins: Environmental Sensor Example - -This sample shows how to implement a simulated environmental sensor using javascript and the `DigitalTwinClient` class. - -## Prerequisite - -You should have [Node.js](https://nodejs.org/en/) installed. - -## How to install the sample - -1. Download the files in this folder -2. Install the dependencies by opening a terminal that contains the sample you downloaded and the `package.json` file and type: - -```shell -npm install -``` - -3. Set the following environment variables: - -```shell -set DEVICE_CONNECTION_STRING= -``` -*use `export` instead of `set` if you're running MacOS or Linux.* - -4. Run the sample with the following command: - -```shell -node sample_device.js -``` - -## What does this sample do? - -`environmentalinterface.js` shows how to create an interface instance based on the Environmental Sensor interface published in the public model repository. - -`sample_device.js` shows how to: -- instantiate the `DigitalTwinClient` class -- instantiate the interface instance class created with `environmentalinterface.js` -- Combine them together to send telemetry, handle commands, and handle property updates. diff --git a/digital-twins/Samples/device/javascript/sample_device.js b/digital-twins/Samples/device/javascript/sample_device.js deleted file mode 100644 index f84bd5f..0000000 --- a/digital-twins/Samples/device/javascript/sample_device.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -'use strict'; - -const DigitalTwinClient = require('azure-iot-digitaltwins-device').DigitalTwinClient; -const DeviceClient = require('azure-iot-device').Client; -const Mqtt = require('azure-iot-device-mqtt').Mqtt; - -const EnvironmentalSensor = require('./environmentalinterface').EnvironmentalSensor; -const DeviceInformation = require('./deviceInformation').DeviceInformation; - -const propertyUpdateHandler = (interfaceInstance, propertyName, reportedValue, desiredValue, version) => { - console.log('Received an update for ' + propertyName + ': ' + JSON.stringify(desiredValue)); - interfaceInstance[propertyName].report(desiredValue, { - code: 200, - description: 'helpful descriptive text', - version: version - }) - .then(() => console.log('updated the property')) - .catch(() => console.log('failed to update the property')); -}; - -const commandHandler = (request, response) => { - console.log('received command: ' + request.commandName + ' for interfaceInstance: ' + request.interfaceInstanceName); - response.acknowledge(200, 'helpful response text') - .then(() => console.log('acknowledgement succeeded.')) - .catch(() => console.log('acknowledgement failed')); -}; - -const environmentalSensor = new EnvironmentalSensor('environmentalSensor', propertyUpdateHandler, commandHandler); -const deviceInformation = new DeviceInformation('deviceInformation'); - -const deviceClient = DeviceClient.fromConnectionString(process.env.DEVICE_CONNECTION_STRING, Mqtt); - -const capabilityModel = 'urn:azureiot:samplemodel:1'; - -async function main() { - const digitalTwinClient = new DigitalTwinClient(capabilityModel, deviceClient); - digitalTwinClient.addInterfaceInstance(environmentalSensor); - digitalTwinClient.addInterfaceInstance(deviceInformation); - await digitalTwinClient.register(); - - // report all of the device information. - await deviceInformation.manufacturer.report('Contoso Device Corporation'); - await deviceInformation.model.report('Contoso 4762B-turbo'); - await deviceInformation.swVersion.report('3.1'); - await deviceInformation.osName.report('ContosoOS'); - await deviceInformation.processorArchitecture.report('4762'); - await deviceInformation.processorManufacturer.report('Contoso Foundries'); - await deviceInformation.totalStorage.report('64000'); - await deviceInformation.totalMemory.report('640'); - console.log('Done sending device Information'); - - // send telemetry - await environmentalSensor.temp.send(65.5); - await environmentalSensor.humid.send(12.2); - console.log('Done sending telemetry.'); - - // report a property - await environmentalSensor.state.report('online'); - console.log('reported state property as online'); -}; - -main(); diff --git a/digital-twins/Samples/device/readme.md b/digital-twins/Samples/device/readme.md deleted file mode 100644 index 93cd34c..0000000 --- a/digital-twins/Samples/device/readme.md +++ /dev/null @@ -1,12 +0,0 @@ -# azure-iot-digitaltwins-device samples - -The **javascript** and **typescript** folders contain two implementations of a simulated environmental sensor. -They show how to: - -- Implement the environmental sensor interface -- Create an interfaceInstance for this interface -- Use the digital twin device client to register this interfaceInstance and interact with the Digital Twins services. - -Please note that the `DigitalTwinClient` depends on the `Client` class from `azure-iot-device` to communicate with the hub. The sample shows how to compose these two together. - -To get started with these samples, please refer to the instructions in each of the folder. \ No newline at end of file diff --git a/digital-twins/Samples/device/typescript/package.json b/digital-twins/Samples/device/typescript/package.json deleted file mode 100644 index ff01909..0000000 --- a/digital-twins/Samples/device/typescript/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "azure-iot-digitaltwins-ts-samples", - "version": "1.0.0-preview.1", - "description": "Azure IoT SDK - Digital Twin Client typescript samples", - "author": "Microsoft Corporation", - "license": "MIT", - "dependencies": { - "azure-iot-device": "1.12.0-preview.1", - "azure-iot-common": "1.12.0-preview.1", - "azure-iot-device-mqtt": "1.12.0-preview.1", - "azure-iot-digitaltwins-device": "1.0.0-preview.1" - }, - "devDependencies": { - "tslint": "^5.9.1", - "typescript": "2.9.2" - }, - "scripts": { - "lint": "tslint --project .", - "build": "tsc", - "ci": "npm -s run lint && npm -s run build" - }, - "engines": { - "node": ">= 0.10" - }, - "files": [ - "dist/**/*.js", - "dist/**/*.js.map", - "dist/**/*.d.ts", - "dist/**/*.d.ts.map", - "src/**/*.ts", - "tsconfig.json" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-iot-sdk-node.git" - }, - "bugs": { - "url": "https://github.com/Azure/azure-iot-sdk-node/issues" - }, - "homepage": "https://github.com/Azure/azure-iot-sdk-node#readme" -} \ No newline at end of file diff --git a/digital-twins/Samples/device/typescript/readme.md b/digital-twins/Samples/device/typescript/readme.md deleted file mode 100644 index f9a425f..0000000 --- a/digital-twins/Samples/device/typescript/readme.md +++ /dev/null @@ -1,45 +0,0 @@ -# Azure IoT Digital Twins: Environmental Sensor Example - -This sample shows how to implement a simulated environmental sensor using typescript and the `DigitalTwinClient` class. - -## Prerequisite - -You should have [Node.js](https://nodejs.org/en/) installed. -You should have the typescript compiler installed. (`npm install -g typescript`) - -## How to install the sample - -1. Download the files in this folder -2. Install the dependencies by opening a terminal that contains the sample you downloaded and the `package.json` file and type: - -```shell -npm install -``` - -3. Set the following environment variables: - -```shell -set IOTHUB_CONNECTION_STRING= -``` -*use `export` instead of `set` if you're running MacOS or Linux.* - -4. Compile the code: - -``` -$ npm run build -``` - -5. Run the sample with the following command: - -``` -$ node simple_sample.js -``` - -## What does this sample do? - -`environmentalinterface.js` shows how to create an interfaceInstance class based on the Environmental Sensor interface published in the public model repository. - -`sample_device.js` shows how to: -- instantiate the `DigitalTwinClient` -- instantiate the interfaceInstance created with `environmentalinterface.js` -- Combine them together to send telmetry, handle commands, and handle property updates. diff --git a/digital-twins/Samples/device/typescript/src/deviceinfointerface.ts b/digital-twins/Samples/device/typescript/src/deviceinfointerface.ts deleted file mode 100644 index 7a199f0..0000000 --- a/digital-twins/Samples/device/typescript/src/deviceinfointerface.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -'use strict'; - -import { - BaseInterface, - Property -} from 'azure-iot-digitaltwins-device'; - -export class DeviceInformation extends BaseInterface { - manufacturer: Property; - model: Property; - swVersion: Property; - osName: Property; - processorArchitecture: Property; - processorManufacturer: Property; - totalStorage: Property; - totalMemory: Property; - - constructor(interfaceInstanceName: string) { - super(interfaceInstanceName, 'urn:azureiot:DeviceInformation:1'); - this.manufacturer = new Property(); - this.model = new Property(); - this.swVersion = new Property(); - this.osName = new Property(); - this.processorArchitecture = new Property(); - this.processorManufacturer = new Property(); - this.totalStorage = new Property(); - this.totalMemory = new Property(); - } -} diff --git a/digital-twins/Samples/device/typescript/src/environmentalinterface.ts b/digital-twins/Samples/device/typescript/src/environmentalinterface.ts deleted file mode 100644 index 0076bac..0000000 --- a/digital-twins/Samples/device/typescript/src/environmentalinterface.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -'use strict'; - -import { - BaseInterface, - Command, - Property, - Telemetry, - PropertyChangedCallback, - CommandCallback -} from 'azure-iot-digitaltwins-device'; - -export class EnvironmentalSensor extends BaseInterface { - temp: Telemetry; - humid: Telemetry; - state: Property; - blink: Command; - turnOff: Command; - turnOn: Command; - runDiagnostics: Command; - name: Property; - brightness: Property; - - constructor(interfaceInstanceName: string, propertyChangedCallback?: PropertyChangedCallback, commandCallback?: CommandCallback) { - super(interfaceInstanceName, 'urn:contoso:com:EnvironmentalSensor:1', propertyChangedCallback, commandCallback); - this.temp = new Telemetry(); - this.humid = new Telemetry(); - this.state = new Property(); - this.blink = new Command(); - this.turnOff = new Command(); - this.turnOn = new Command(); - this.runDiagnostics = new Command(); - this.name = new Property(true); - this.brightness = new Property(true); - } -} diff --git a/digital-twins/Samples/device/typescript/src/exitInterface.ts b/digital-twins/Samples/device/typescript/src/exitInterface.ts deleted file mode 100644 index 3b48545..0000000 --- a/digital-twins/Samples/device/typescript/src/exitInterface.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -'use strict'; - -import { BaseInterface, Command, PropertyChangedCallback, CommandCallback } from 'azure-iot-digitaltwins-device'; - -export class SampleExit extends BaseInterface { - exit: Command; - constructor(interfaceInstanceName: string, propertyChangedCallback?: PropertyChangedCallback, commandCallback?: CommandCallback) { - super(interfaceInstanceName, 'urn:azureiotsdknode:SampleInterface:SampleExit:1', propertyChangedCallback, commandCallback); - this.exit = new Command(); - } -} diff --git a/digital-twins/Samples/device/typescript/src/sample_device.ts b/digital-twins/Samples/device/typescript/src/sample_device.ts deleted file mode 100644 index 56fb8a1..0000000 --- a/digital-twins/Samples/device/typescript/src/sample_device.ts +++ /dev/null @@ -1,118 +0,0 @@ -import { Client } from 'azure-iot-device'; -import { Mqtt as Protocol } from 'azure-iot-device-mqtt'; -import { DigitalTwinClient, CommandCallback, CommandRequest, CommandResponse, PropertyChangedCallback, BaseInterface } from 'azure-iot-digitaltwins-device'; -import { EnvironmentalSensor } from './environmentalinterface'; -import { DeviceInformation } from './deviceinfointerface'; -import { SampleExit } from './exitInterface'; - -const environmentCommandCallback: CommandCallback = (request: CommandRequest, response: CommandResponse) => { - console.log('Callback for command for environment interface'); - switch (request.commandName) { - case 'blink': { - console.log('Got the blink command.'); - response.acknowledge(200, 'blink response', (err?: Error) => { - if (err) { - console.log('responding to the blink command failed.'); - } - }); - break; - } - case 'turnOn': { - console.log('Got the turnOn command.'); - response.acknowledge(200, 'turn on response', (err?: Error) => { - if (err) { - console.log('responding to the turnOn command failed.'); - } - }); - break; - } - case 'turnOff': { - console.log('Got the turnOff command.'); - response.acknowledge(200, 'turn off response', (err?: Error) => { - if (err) { - console.log('responding to the blink command failed.'); - } - }); - break; - } - case 'runDiagnostics': { - console.log('Got the runDiagnostics command.'); - response.acknowledge(200, 'runDiagnostics response', (err?: Error) => { - if (err) { - console.log('responding to the runDiagnostics command failed ' + err.toString()); - } - // response.update(200, 'runDiagnostics updated response', (updateError?: Error) => { - // if (updateError) { - // console.log('got an error on the update Response ' + updateError.toString()); - // } - // }); - response.update(200, 'runDiagnostics updated response') - .then(() => { - console.log('in the then for the update.'); - }) - .catch((err: Error) => {console.log('Got an error on the update: ' + err.toString());}); - }); - break; - } - } -}; - -const environmentReadWriteCallback: PropertyChangedCallback = (interfaceObject: BaseInterface, propertyName: string, reportedValue: any, desiredValue: any, version: number) => { - interfaceObject[propertyName].report(desiredValue + ' the boss', {responseVersion: version, statusCode: 200, statusDescription: 'a promotion'}, (err: Error) => { - if (err) { - console.log('did not do the update'); - } else { - console.log('The update worked!!!!'); - } - }); -}; - -const exitHandler = (request: CommandRequest, response: CommandResponse) => { - console.log('received command: ' + request.commandName + ' for interfaceInstance: ' + request.interfaceInstanceName); - response.acknowledge(200, null, (err?: Error) => { - if (err) { - console.log('Acknowledge failed. Error is: ' + err.toString()); - } - setTimeout(() => {process.exit(0);}, 2000); - }); -}; - -const environmentalSensor = new EnvironmentalSensor('environmentalSensor', environmentReadWriteCallback, environmentCommandCallback ); -const deviceInformation = new DeviceInformation('deviceInformation'); -const exitInterface = new SampleExit('urn_azureiotsdknode_SampleInterface_SampleExit', undefined, exitHandler); - - -const client = Client.fromConnectionString(process.env.DEVICE_CONNECTION_STRING as string, Protocol); - -const capabilityModel = 'urn:azureiot:samplemodel:1'; - -let dtClient = new DigitalTwinClient(capabilityModel, client); - -const main = async () => { - try { - await environmentalSensor.humid.send(7.3); - await environmentalSensor.temp.send(65.5); - await environmentalSensor.state.report('on'); - await deviceInformation.manufacturer.report('Contoso Device Corporation'); - await deviceInformation.model.report('Contoso 4762B-turbo'); - await deviceInformation.swVersion.report('3.1'); - await deviceInformation.osName.report('ContosoOS'); - await deviceInformation.processorArchitecture.report('4762'); - await deviceInformation.processorManufacturer.report('Contoso Foundries'); - await deviceInformation.totalStorage.report('64000'); - await deviceInformation.totalMemory.report('640'); - } catch (err) { - console.log('error from operation is: ' + err.toString()); - } -}; - -dtClient.addInterfaceInstance(environmentalSensor); -dtClient.addInterfaceInstance(deviceInformation); -dtClient.addInterfaceInstance(exitInterface); - -dtClient.register() - .then(() => { - console.log('registered the interfaceInstances.'); - main(); - }) - .catch(() => {console.log('the registration failed.');}); diff --git a/digital-twins/Samples/device/typescript/tsconfig.json b/digital-twins/Samples/device/typescript/tsconfig.json deleted file mode 100644 index 59596ad..0000000 --- a/digital-twins/Samples/device/typescript/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "outDir": "./dist", - "strict": true, - "target": "es5", - "sourceMap": true, - "declarationMap": true, - "lib": [ - "es6" - ], - "declaration": true, - "noUnusedLocals": true - }, - "include": ["./src/**/*.ts"], - "exclude": ["node_modules"] - } diff --git a/digital-twins/Samples/iot_central_device/environmentalinterface.js b/digital-twins/Samples/iot_central_device/environmentalinterface.js deleted file mode 100644 index 8c648ea..0000000 --- a/digital-twins/Samples/iot_central_device/environmentalinterface.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -'use strict'; - -const BaseInterface = require('azure-iot-digitaltwins-device').BaseInterface; -const Telemetry = require('azure-iot-digitaltwins-device').Telemetry; -const Property = require('azure-iot-digitaltwins-device').Property; -const Command = require('azure-iot-digitaltwins-device').Command; - -module.exports.EnvironmentalSensor = class EnvironmentalSensor extends BaseInterface { - constructor(name, propertyCallback, commandCallback) { - // Edit this to match your IoT Central solution - super(name, 'urn:{yourname}:sample_device:1', propertyCallback, commandCallback); - this.temp = new Telemetry(); - this.humid = new Telemetry(); - this.state = new Property(); - this.blink = new Command(); - this.turnOff = new Command(); - this.turnOn = new Command(); - this.runDiagnostics = new Command(); - this.name = new Property(true); - this.brightness = new Property(true); - } -}; diff --git a/digital-twins/Samples/iot_central_device/package.json b/digital-twins/Samples/iot_central_device/package.json deleted file mode 100644 index da7c558..0000000 --- a/digital-twins/Samples/iot_central_device/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "azure-iot-digitaltwins-pnp-device-provisioning-samples", - "version": "1.0.0-preview.1", - "description": "Samples for the azure-iot-digitaltwins-device client library", - "repository": { - "type": "git", - "url": "git+https://github.com/azure/azure-iot-sdk-node-digitaltwins.git" - }, - "author": "Microsoft Corp.", - "license": "MIT", - "bugs": { - "url": "https://github.com/azure/azure-iot-sdk-node-digitaltwins/issues" - }, - "homepage": "https://github.com/azure/azure-iot-sdk-node-digitaltwins#readme", - "dependencies": { - "azure-iot-device": "1.12.0-preview.1", - "azure-iot-common": "1.12.0-preview.1", - "azure-iot-device-mqtt": "1.12.0-preview.1", - "azure-iot-digitaltwins-device": "1.0.0-preview.1", - "azure-iot-provisioning-device": "1.8.0-preview.1", - "azure-iot-provisioning-device-mqtt": "1.8.0-preview.1", - "azure-iot-security-symmetric-key": "1.8.0-preview.1" - } -} \ No newline at end of file diff --git a/digital-twins/Samples/iot_central_device/readme.md b/digital-twins/Samples/iot_central_device/readme.md deleted file mode 100644 index 1b19a38..0000000 --- a/digital-twins/Samples/iot_central_device/readme.md +++ /dev/null @@ -1,47 +0,0 @@ -# Azure IoT Digital Twins: Environmental Sensor Example - -This sample shows how to implement a simulated environmental sensor using javascript and the `DigitalTwinClient` class. - -## Prerequisite - -You should have [Node.js](https://nodejs.org/en/) installed. - -## How to install the sample - -1. Download the files in this folder -2. Install the dependencies by opening a terminal that contains the sample you downloaded and the `package.json` file and type: - -```shell -npm install -``` - -3. Set the following environment variables: - -```shell -set AZURE_IOT_PROVISIONING_REGISTRATION_ID= -set AZURE_IOT_PROVISIONING_ID_SCOPE= -set AZURE_IOT_PROVISIONING_KEY= -set AZURE_IOT_PROVISIONING_ENDPOINT= -``` -*use `export` instead of `set` if you're running MacOS or Linux.* - -4. Modify the samples to fit your IoT Central application: -- In `environmentalinterface.js`, change the interface id to the one you created in your IoT Central solution. -- In `sample_device.js` change the capability model id to the one you created in your IoT Central solution. - -5. Run the sample with the following command: - -```shell -node sample_device.js -``` - -## What does this sample do? - -`environmentalinterface.js` shows how to create a interface class based on the Environmental Sensor interface published in the public model repository. - -`sample_device.js` shows how to: -- instantiate a `ProvisioningDeviceClient` to proceed with the device registration. -- use the result of the registration to create a device connection string that will be used by the `DigitalTwinClient` to connect -- instantiate the `DigitalTwinClient` -- instantiate the interface class created with `environmentalinterface.js` -- Combine them together to send telemetry, handle commands, and handle property updates. diff --git a/digital-twins/Samples/iot_central_device/sample_device.js b/digital-twins/Samples/iot_central_device/sample_device.js deleted file mode 100644 index a901f3c..0000000 --- a/digital-twins/Samples/iot_central_device/sample_device.js +++ /dev/null @@ -1,72 +0,0 @@ -const DigitalTwinClient = require('azure-iot-digitaltwins-device').DigitalTwinClient; -const DeviceClient = require('azure-iot-device').Client; -const Mqtt = require('azure-iot-device-mqtt').Mqtt; -const ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient; -const ProvisioningTransport = require('azure-iot-provisioning-device-mqtt').Mqtt; -const SymmetricKeySecurityClient = require('azure-iot-security-symmetric-key').SymmetricKeySecurityClient; - -const EnvironmentalSensor = require('./environmentalinterface').EnvironmentalSensor; - -// Edit this to match your IoT Central solution -const capabilityModel = 'urn:{yourname}:sample_device:1'; - -const registrationId = process.env.AZURE_IOT_PROVISIONING_REGISTRATION_ID; -const idScope = process.env.AZURE_IOT_PROVISIONING_ID_SCOPE; -const symmetricKey = process.env.AZURE_IOT_PROVISIONING_KEY; -const provisioningEndpoint = process.env.AZURE_IOT_PROVISIONING_ENDPOINT; - -async function main() { - const provisioningClient = ProvisioningDeviceClient.create( - provisioningEndpoint, - idScope, - new ProvisioningTransport(), - new SymmetricKeySecurityClient(registrationId, symmetricKey) - ); - - // IoT Central requires a special payload to be sent when the device is provisioned - provisioningClient.setProvisioningPayload({ - '__iot:interfaces': { - CapabilityModelId: capabilityModel - } - }); - - const registrationResult = await provisioningClient.register(); - const deviceConnectionString = `HostName=${registrationResult.assignedHub};DeviceId=${registrationResult.deviceId};SharedAccessKey=${symmetricKey}`; - - const propertyUpdateHandler = (interfaceInstance, propertyName, reportedValue, desiredValue, version) => { - console.log('Received an update for ' + propertyName + ': ' + JSON.stringify(desiredValue)); - interfaceInstance[propertyName].report(desiredValue, { - code: 200, - description: 'helpful descriptive text', - version: version - }) - .then(() => console.log('updated the property')) - .catch(() => console.log('failed to update the property')); - }; - - const commandHandler = (request, response) => { - console.log('received command: ' + request.commandName + ' for interfaceInstance: ' + request.interfaceInstanceName); - response.acknowledge(200, 'helpful response text') - .then(() => console.log('acknowledgement succeeded.')) - .catch(() => console.log('acknowledgement failed')); - }; - - const environmentalSensor = new EnvironmentalSensor('sensor', propertyUpdateHandler, commandHandler); - const deviceClient = DeviceClient.fromConnectionString(deviceConnectionString, Mqtt); - - const digitalTwinClient = new DigitalTwinClient(capabilityModel, deviceClient); - digitalTwinClient.addInterfaceInstance(environmentalSensor); - - await digitalTwinClient.register(); - - // send telemetry - setInterval(async () => { - const temp = 65.5 + Math.ceil(Math.random() * 10); - const humidity = 12.2 + Math.ceil(Math.random() * 10); - await environmentalSensor.temp.send(temp); - await environmentalSensor.humid.send(humidity); - console.log('Done sending telemetry: temp: ' + temp + ' humidity ' + humidity); - }, 3000); -}; - -main(); diff --git a/digital-twins/Samples/model_repository/model_repo.js b/digital-twins/Samples/model_repository/model_repo.js deleted file mode 100644 index d5ba54c..0000000 --- a/digital-twins/Samples/model_repository/model_repo.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -const ModelRepoClient = require('azure-iot-digitaltwins-model-repository').DigitalTwinRepositoryService; -const AuthorizationHeader = require('@azure/ms-rest-js').Constants.HeaderConstants.AUTHORIZATION; -const crypto = require('crypto'); -const ConnectionString = require('azure-iot-common').ConnectionString; - -const apiVersion = '2019-07-01-Preview'; - -class SimpleTokenCredentials { - constructor(connectionString) { - this._connectionString = ConnectionString.parse(connectionString, ['HostName', 'RepositoryId', 'SharedAccessKey', 'SharedAccessKeyName']); - } - - getBaseUri() { - if (this._connectionString.HostName.startsWith('https://')) { - return this._connectionString.HostName; - } else { - return 'https://' + this._connectionString.HostName; - } - } - - signRequest(webResource) { - // SAS Token format: SharedAccessSignature sr=URLENCODED()&sig=URLENCODED()&se=&skn=URLENCODED()&rid=URLENCODED() - const expiry = Math.floor(new Date() / 1000) + 1200; // 20 minutes - const stringToSign = `${this._connectionString.RepositoryId}\n${encodeURIComponent(this._connectionString.HostName)}\n${expiry}`.toLowerCase(); - const signature = crypto.createHmac('sha256', Buffer.from(this._connectionString.SharedAccessKey, 'base64')).update(stringToSign).digest('base64'); - const modelRepoSas = `SharedAccessSignature sr=${encodeURIComponent(this._connectionString.HostName)}&sig=${encodeURIComponent(signature)}&se=${encodeURIComponent(expiry)}&skn=${encodeURIComponent(this._connectionString.SharedAccessKeyName)}&rid=${encodeURIComponent(this._connectionString.RepositoryId)}`; - - webResource.headers.set(AuthorizationHeader, modelRepoSas); - return Promise.resolve(webResource); - } -} - -async function main() { - const creds = new SimpleTokenCredentials(process.env.AZURE_IOT_MODEL_REPOSITORY_CONNECTION_STRING); - - const modelRepoClient = new ModelRepoClient(creds, { - baseUri: creds.getBaseUri(), - deserializationContentTypes: { // application/ld+json isn't supported by autorest by default, which is why we need these options - json: [ - 'application/ld+json', - 'application/json', - 'text/json' - ] - } - }); - - try { - const models = await modelRepoClient.searchModel({ searchKeyword: 'ModelDiscovery', modelFilterType: 'interface' }, apiVersion); - console.log(JSON.stringify(models.results, null, 2)); - - const modelDiscovery = await modelRepoClient.getModel('urn:azureiot:ModelDiscovery:ModelInformation:1', apiVersion); - console.log(JSON.stringify(modelDiscovery, null, 2)); - } catch (err) { - console.error(err.toString()); - } -} - -main(); diff --git a/digital-twins/Samples/model_repository/package.json b/digital-twins/Samples/model_repository/package.json deleted file mode 100644 index 27bb20e..0000000 --- a/digital-twins/Samples/model_repository/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "azure-iot-digitaltwins-model-repository-samples", - "version": "1.0.0-preview.1", - "description": "Samples for the azure-iot-digitaltwins-service client library", - "main": "model_repo.js", - "repository": { - "type": "git", - "url": "git+https://github.com/azure/azure-iot-sdk-node-digitaltwins.git" - }, - "author": "Microsoft Corp.", - "license": "MIT", - "bugs": { - "url": "https://github.com/azure/azure-iot-sdk-node-digitaltwins/issues" - }, - "homepage": "https://github.com/azure/azure-iot-sdk-node-digitaltwins#readme", - "dependencies": { - "azure-iot-digitaltwins-model-repository": "1.0.0-preview.1", - "azure-iothub": "1.12.0-preview.1", - "azure-iot-common": "1.12.0-preview.1" - } -} \ No newline at end of file diff --git a/digital-twins/Samples/model_repository/readme.md b/digital-twins/Samples/model_repository/readme.md deleted file mode 100644 index c13078c..0000000 --- a/digital-twins/Samples/model_repository/readme.md +++ /dev/null @@ -1,38 +0,0 @@ -# Azure IoT Digital Twins: Model Repository Example - -This sample shows how to use the temporary auto-generated client library for the model repository. -**This is a preview version that is auto-generated and does not represent the final shape of the API** - -## Prerequisite - -You should have [Node.js](https://nodejs.org/en/) installed. - -## How to install the sample - -1. Download the files in this folder -2. Install the dependencies by opening a terminal that contains the sample you downloaded and the `package.json` file and type: - -```shell -npm install -``` - -3. Set the following environment variable: -```shell -set AZURE_IOT_MODEL_REPOSITORY_CONNECTION_STRING= -``` -*use `export` instead of `set` if you're running MacOS or Linux.* - - -4. Run the sample with the following command: - -``` -$ node model_repo.js -``` - -## What does this sample do? - -The first part of the sample shows a simplistic implementation of a class that generates an authentication token for the model repository client. - -The second part shows how to use the client to run a full text search on existing models. - -The third part shows how to get an existing model for which you know the unique identifier. \ No newline at end of file diff --git a/digital-twins/Samples/readme.md b/digital-twins/Samples/readme.md deleted file mode 100644 index a28a5fc..0000000 --- a/digital-twins/Samples/readme.md +++ /dev/null @@ -1,26 +0,0 @@ -# Azure IoT Digital Twins Samples - -This folder contains all the samples for the Azure Digital Twins Public Preview. They are organized in 3 subfolders: - -**device** contains all the samples for the `azure-iot-digitaltwins-device` package to create an Azure IoT Plug-and-Play device client: - -- Implement interfaces and instantiate them as instances for this device -- Register this device with its capability model and instances using the `DigitalTwinClient` class. -- Send telemetry, act on commands, receive writable property updates, and report property changes. - -Please refer to the [device samples readme](./device/readme.md) for more details. - -**service** contains all the samples for the `azure-iot-digitaltwins-service` package that show how to: - -- Get the digital twin for a device from an Azure IoT hub -- Update this digital twin writable properties -- Invoke commands on a device that supports IoT Plug-and-Play - -Please note that the digital twins service client library does not duplicate features of the existing Azure IoT Hub client library. The samples in this folder will also show how to use the `azure-iothub` package to: -- create or delete device identities -- run queries to find digital twins matching specific criteria (device implementing properties, etc) - -**model_repository** contains all the samples for the digital twins model repository client that show how to: - -- get, create, update and delete models in a private model repository. -- publish models to the public model repository *(please note that once published to the public model repository, a model cannot be deleted!)* diff --git a/digital-twins/Samples/service/get_digital_twin.js b/digital-twins/Samples/service/get_digital_twin.js deleted file mode 100644 index 09ec4fa..0000000 --- a/digital-twins/Samples/service/get_digital_twin.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const deviceId = ''; - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - get the Digital Twin -// - list all the Digital Twin Components -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - // Create digital twin service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - console.log('getting full digital twin for device ' + deviceId + '...'); - // Get digital twin - const digitalTwin = await digitalTwinServiceClient.getDigitalTwin(deviceId); - - // Print digital twin components - console.log(JSON.stringify(digitalTwin.interfaces, null, 2)); -}; - -main(); diff --git a/digital-twins/Samples/service/get_digital_twin_interface_instance.js b/digital-twins/Samples/service/get_digital_twin_interface_instance.js deleted file mode 100644 index f00eba6..0000000 --- a/digital-twins/Samples/service/get_digital_twin_interface_instance.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const deviceId = ''; -const interfaceInstanceName = ''; // for the environmental sensor, try "environmentalSensor" - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - get a single Digital Twin Interface Instance by name -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - - // Create service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - console.log('getting ' + interfaceInstanceName + ' on device ' + deviceId + '...'); - // Get interface instance by name - const partialDigitalTwin = await digitalTwinServiceClient.getDigitalTwinInterfaceInstance(deviceId, interfaceInstanceName); - - // Print the interface instance - console.log(JSON.stringify(partialDigitalTwin.interfaces, null, 2)); -}; - -main(); diff --git a/digital-twins/Samples/service/get_model.js b/digital-twins/Samples/service/get_model.js deleted file mode 100644 index e7eaf91..0000000 --- a/digital-twins/Samples/service/get_model.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const modelId = ''; // suggestion: urn:azureiot:Client:SDKInformation:1 - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - get a Digital Twin Model by model ID -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - // Create service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - // Get digital twin model - const digitalTwinModel = await digitalTwinServiceClient.getModel(modelId); - const idName = '@id'; - console.log('ModelId: ' + JSON.stringify(digitalTwinModel[idName], null, 2)); - console.log('Model: ' + JSON.stringify(digitalTwinModel.contents, null, 2)); -}; - -main(); diff --git a/digital-twins/Samples/service/invoke_command.js b/digital-twins/Samples/service/invoke_command.js deleted file mode 100644 index 07b4a42..0000000 --- a/digital-twins/Samples/service/invoke_command.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const deviceId = ''; -const interfaceInstanceName = ''; // for the environmental sensor, you can try "environmentalSensor" -const commandName = ''; // for the environmental sensor, you can try "blink", "turnOff" or "turnOn" -const commandArgument = ''; // for the environmental sensor, it really doesn't matter. any string will do. - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - invoke a command on a Digital Twin enabled device -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - // Create service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - console.log('invoking command ' + commandName + ' on interface instance' + interfaceInstanceName + ' for device ' + deviceId + '...'); - // Invoke a command - const digitalTwinCommandResult = await digitalTwinServiceClient.invokeCommand(deviceId, interfaceInstanceName, commandName, commandArgument); - - // Print result of the command - console.log(JSON.stringify(digitalTwinCommandResult, null, 2)); -}; - -main(); diff --git a/digital-twins/Samples/service/package.json b/digital-twins/Samples/service/package.json deleted file mode 100644 index bda881f..0000000 --- a/digital-twins/Samples/service/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "azure-iot-digitaltwins-service-samples", - "version": "1.0.0-preview.1", - "description": "Samples for the azure-iot-digitaltwins-service client library", - "main": "get_digital_twin.js", - "repository": { - "type": "git", - "url": "git+https://github.com/azure/azure-iot-sdk-node-digitaltwins.git" - }, - "author": "Microsoft Corp.", - "license": "MIT", - "bugs": { - "url": "https://github.com/azure/azure-iot-sdk-node-digitaltwins/issues" - }, - "homepage": "https://github.com/azure/azure-iot-sdk-node-digitaltwins#readme", - "dependencies": { - "azure-iot-digitaltwins-service": "1.0.0-preview.1", - "azure-iothub": "1.12.0-preview.1", - "@azure/event-hubs": "^2.1.1" - } -} \ No newline at end of file diff --git a/digital-twins/Samples/service/query_interface.js b/digital-twins/Samples/service/query_interface.js deleted file mode 100644 index b884a58..0000000 --- a/digital-twins/Samples/service/query_interface.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -'use strict'; - -const Registry = require('azure-iothub').Registry; - -const interfaceId = ''; // suggestion to find your environmental sensor: 'urn:contoso:com:EnvironmentalSensor' -const interfaceVersion = 1; // replace this with the version number you want. we suggest to start with 1 :); - -async function main() { - const registryClient = Registry.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING); - console.log('querying devices that have interface ' + interfaceId + '...'); - const query = registryClient.createQuery(`SELECT * from devices WHERE has_interface('${interfaceId}', ${interfaceVersion})`); - while (query.hasMoreResults) { - const queryResponse = await query.next(query.continuationToken); - queryResponse.result.forEach((device) => console.log(device.deviceId)); - } -} - -main(); diff --git a/digital-twins/Samples/service/readme.md b/digital-twins/Samples/service/readme.md deleted file mode 100644 index 4afcc55..0000000 --- a/digital-twins/Samples/service/readme.md +++ /dev/null @@ -1,42 +0,0 @@ -# Azure IoT Digital Twins: Service Client Example - -This sample shows how to use `DigitalTwinServiceClient` class from the `azure-iot-digitaltwins-service` package. - -## Prerequisite - -You should have [Node.js](https://nodejs.org/en/) installed. - -## How to install the sample - -1. Download the samples you want to run from this folder of the repository -2. Install the dependencies by opening a terminal that contains the sample you downloaded and the `package.json` file and type: - -```shell -npm install -``` - -3. Set the following environment variables: - -```shell -set IOTHUB_CONNECTION_STRING= -``` -*use `export` instead of `set` if you're running MacOS or Linux.* - -4. Edit the sample to change the values at the top of the file to match your scenario - -5. Run the sample with the following command: - -```shell -node -``` - -## What do these samples do? - -- `invoke_command.js` invokes a command on a device interface instance. -- `get_digital_twin.js` gets the digital twin for a specific device. -- `get_digital_twin_interface_instance.js` gets the data for a specific interface instance of a specific device. -- `get_model.js` gets a model from the public model repository. -- `update_digital_twin_property.js` updates a single writable property on a digital twin. -- `update_digital_twin.js` creates a patch to updates multiple writable properties on a digital twin, potentially on multiple interface instances. -- `query_interface.js` runs a query that returns all devices implementing a specific interface. -- `receive_telemetry.js` uses the Event Hubs client library to read telemetry messages coming from devices. \ No newline at end of file diff --git a/digital-twins/Samples/service/receive_telemetry.js b/digital-twins/Samples/service/receive_telemetry.js deleted file mode 100644 index d24bdc0..0000000 --- a/digital-twins/Samples/service/receive_telemetry.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -'use strict'; - -// Connection string for the IoT Hub service -// Using the Azure CLI: -// az iot hub show-connection-string --hub-name {YourIoTHubName} --policy-name service --output table -const connectionString = process.env.IOTHUB_CONNECTION_STRING; - -// Using the Node.js SDK for Azure Event hubs: -// https://github.com/Azure/azure-event-hubs-node -// The sample connects to an IoT hub's Event Hubs-compatible endpoint -// to read messages sent from a device. -const { EventHubClient, EventPosition } = require('@azure/event-hubs'); - -const printError = function (err) { - console.log(err.message); -}; - -// Display the message content - telemetry and properties. -const printMessage = function (message) { - console.log('Telemetry received: '); - console.log(JSON.stringify(message.body, null, 2)); - console.log('Application properties (set by device): '); - console.log(JSON.stringify(message.applicationProperties, null, 2)); - console.log('System properties (set by IoT Hub): '); - console.log(JSON.stringify(message.annotations, null, 2)); - console.log(''); -}; - -// Connect to the partitions on the IoT Hub's Event Hubs-compatible endpoint. -// This example only reads messages sent after this application started. -let ehClient; -EventHubClient.createFromIotHubConnectionString(connectionString).then(function (client) { - console.log('Successfully created the EventHub Client from iothub connection string.'); - ehClient = client; - return ehClient.getPartitionIds(); -}).then(function (ids) { - console.log('The partition ids are: ', ids); - return ids.map(function (id) { - return ehClient.receive(id, printMessage, printError, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) }); - }); -}).catch(printError); diff --git a/digital-twins/Samples/service/update_digital_twin.js b/digital-twins/Samples/service/update_digital_twin.js deleted file mode 100644 index bf2c5a0..0000000 --- a/digital-twins/Samples/service/update_digital_twin.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const deviceId = ''; -const patch = { - interfaces: { - '': { // for the environmental sensor, try "environmentalSensor" - properties: { - '': { // for the environmental sensor, try "brightness" - desired: { - value: '' // for the environmental sensor, try 42 (note that this is a number, not a string, so don't include quotes). - } - } - } - } - } -}; - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - create a patch for modifying the Digital Twin -// - update the Digital Twin with patch -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - // Create service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - // Get digital twin - const digitalTwin = await digitalTwinServiceClient.getDigitalTwin(deviceId); - - // Print original Twin - console.log(JSON.stringify(digitalTwin.interfaces, null, 2)); - - // Update digital twin and verify the update - try { - const updatedDigitalTwin = await digitalTwinServiceClient.updateDigitalTwin(deviceId, patch); - - // Print updated Twin - console.log(JSON.stringify(updatedDigitalTwin.interfaces, null, 2)); - } catch (err) { - console.log(err); - } -}; - -main(); diff --git a/digital-twins/Samples/service/update_digital_twin_property.js b/digital-twins/Samples/service/update_digital_twin_property.js deleted file mode 100644 index 227e518..0000000 --- a/digital-twins/Samples/service/update_digital_twin_property.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials; -const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient; - -const deviceId = ''; -const interfaceInstanceName = ''; // for the environmental sensor, you can try "environmentalSensor" -const propertyName = ''; // for the environmental sensor, try "brightness" -const propertyValue = ''; // for the environmental sensor, try 42 (note that this is a number, not a string, so don't include quotes). - -// Simple example of how to: -// - create a Digital Twin Service Client using the DigitalTwinServiceClient constructor -// - update the Digital Twin property using property update API -async function main() { - // IoT Hub connection string has to be set to system environment variable IOTHUB_CONNECTION_STRING - // Twin enabled device must be exist on the IoT Hub - - // Create service client - const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING); - const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials); - - // Get digital twin - const digitalTwin = await digitalTwinServiceClient.getDigitalTwin(deviceId); - - // Print original Twin - console.log(JSON.stringify(digitalTwin.interfaces, null, 2)); - - // Update digital twin and verify the update - try { - const updatedDigitalTwin = await digitalTwinServiceClient.updateDigitalTwinProperty(deviceId, interfaceInstanceName, propertyName, propertyValue); - - // Print updated Twin - console.log(JSON.stringify(updatedDigitalTwin.interfaces, null, 2)); - } catch (err) { - console.log(err); - } -}; - -main();