Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into telemetry_update
Browse files Browse the repository at this point in the history
  • Loading branch information
hellyzh committed May 20, 2020
2 parents 1caffc1 + b490480 commit 84192b8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 109 deletions.
20 changes: 10 additions & 10 deletions docs/embedded-linux/embedded-linux-pnp.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

1. Create a `pnp_app` directory in your local drive. You use this folder for the device model files and device code stub.

2. Download the [device capability model](https://github.com/Azure/IoTPlugandPlay/blob/master/samples/SampleDevice.capabilitymodel.json) and [interface sample](https://github.com/Azure/IoTPlugandPlay/blob/master/samples/EnvironmentalSensor.interface.json) files and save files into `pnp_app` folder.
2. Download the [device capability model](https://github.com/Azure/IoTPlugandPlay/blob/9004219bff1e958b7cd6ff2a52209f4b7ae19396/samples/SampleDevice.capabilitymodel.json) and [interface sample](https://github.com/Azure/IoTPlugandPlay/blob/9004219bff1e958b7cd6ff2a52209f4b7ae19396/samples/EnvironmentalSensor.interface.json) files and save files into `pnp_app` folder.

> To download a file from GitHub, navigate to the file, right-click on **Raw**, and then select **Save link as**.
> To download a file from GitHub, navigate to the file, right-click on **Raw**, and then select **Save link as**.
3. Open `pnp_app` folder with VS Code. You can view the files with IntelliSense:

![](../images/author-pnp-dcm.png)
![](../images/author-pnp-dcm.png)

4. In the files you downloaded, replace `<YOUR_COMPANY_NAME_HERE>` in the `@id` and `schema` fields with a unique value. Use only the characters a-z, A-Z, 0-9, and underscore. For more information, see [Digital Twin identifier format](https://github.com/Azure/IoTPlugandPlay/tree/master/DTDL#digital-twin-identifier-format).

Expand All @@ -26,7 +26,7 @@ Now that you have a DCM and its associated interfaces, you can generate the devi

1. With the `pnp_app` folder open in VS Code, use **Ctrl+Shift+P** to open the command palette, select "**IoT Plug and Play: Generate Device Code Stub...**"

> The first time you use the IoT Plug and Play CodeGen CLI, it takes a few seconds to download and install automatically.
> The first time you use the IoT Plug and Play CodeGen CLI, it takes a few seconds to download and install automatically.
2. Choose the **SampleDevice.capabilitymodel.json** file to use for generating the device code stub.

Expand Down Expand Up @@ -56,16 +56,16 @@ You use the built-in containerized toolchain to build the generated device code

4. Select **No** to open the configured project in remote container.

> The first time you use a container, it takes around 1 to 3 minutes to download and prepare the dev container. Click the details link on the notification for the progress:
![](../images/prepare-dev-container.png)
> The first time you use a container, it takes around 1 to 3 minutes to download and prepare the dev container. Click the details link on the notification for the progress:
> ![](../images/prepare-dev-container.png)
5. Select **Azure IoT Device Workbench: Compile Device Code** to build device code. The cross-compiling of the code happens in the dev container. Once it's done, it shows the notification:

![](../images/pnp-with-container-compile-success.png)
![](../images/pnp-with-container-compile-success.png)

6. Select **Azure IoT Device Workbench: Upload Device Code** to upload device code to your target machine. Select **Manual setup** and enter the `IP address`, `port`, `user name`, `password` and `project destinarion path` to deploy the compiled binary via SSH to your target x86 Linux machine:

![](../images/upload-options.png)
![](../images/upload-options.png)

## Run the Application on target machine

Expand All @@ -77,8 +77,8 @@ Navigate to your target x86 Linux machine, check the binary file is successfully

You can see the target device starts sending telemetry data to the Azure IoT Hub:

![](../images/pnp-with-container-result.jpg)
![](../images/pnp-with-container-result.jpg)

To verify the reception of the data, use Azure IoT Hub Toolkit, right click on the device and select **Start Monitoring Built-in Event Endpoint**. In the output window, you can see that IoT Hub gets telemetry data sent from Raspberry Pi:

![](../images/pnp-with-container-iothub-d2c.png)
![](../images/pnp-with-container-iothub-d2c.png)
3 changes: 1 addition & 2 deletions resources/pnp/definitions/constraint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"@context": {
"v1": "http://azureiot.com/v1/contexts/IoTModel.json",
"v2": "http://azure.com/v2/contexts/Model.json"
"v1": "http://azureiot.com/v1/contexts/IoTModel.json"
},
"@id": {
"minLength": 1,
Expand Down
3 changes: 0 additions & 3 deletions src/DigitalTwin/pnp/src/intelliSense/digitalTwinConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ export class DigitalTwinConstants {
static readonly SCHEMA_NODE = "Schema";
static readonly UNIT_NODE = "Unit";
static readonly INTERFACE_SCHEMA_NODE = "InterfaceInstance/schema";
static readonly INTERFACE_INSTANCE_NODE = "InterfaceInstance";
static readonly COMPONENT_NODE = "Component";
static readonly NAMED_ENTITY_NODE = "NamedEntity";
static readonly WORD_STOP = ' \t\n\r\v":{[,';
static readonly REQUIRED_PROPERTY_LABEL = "(required)";
static readonly SUPPORT_SEMANTIC_TYPES = new Set<string>(["Telemetry", "Property"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export class DigitalTwinDiagnosticProvider {
switch (propertyName) {
case DigitalTwinConstants.ID:
// @id is available for each class
// TODO(erichen): @id format may be differnt in v2
propertyNode = IntelliSenseUtility.getPropertyNode(DigitalTwinConstants.ID);
if (propertyNode) {
DigitalTwinDiagnosticProvider.validateNode(version, propertyPair.value, propertyNode, problems);
Expand All @@ -316,7 +315,6 @@ export class DigitalTwinDiagnosticProvider {
break;
default:
// validate expected property
// TODO(erichen): semantic types may have additional property
propertyNode = expectedProperties.get(propertyName);
if (!propertyNode) {
DigitalTwinDiagnosticProvider.addProblemOfUnexpectedProperty(propertyPair.name, problems);
Expand Down
92 changes: 0 additions & 92 deletions src/DigitalTwin/pnp/src/intelliSense/digitalTwinGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@ export class DigitalTwinGraph {

// handle interfaceSchema
this.handleInterfaceSchema(stringNode);

// handle definition change
this.handleDefinitionChange();
}

/**
Expand Down Expand Up @@ -573,95 +570,6 @@ export class DigitalTwinGraph {
}
}

/**
* patch definition change for different DTDL version
*/
private handleDefinitionChange(): void {
// DTDL v2 change
const version = 2;
// rename InterfaceInstance to Component
const componentNode: ClassNode | undefined = this.renameClassNode(
DigitalTwinConstants.INTERFACE_INSTANCE_NODE,
DigitalTwinConstants.COMPONENT_NODE,
version
);
if (componentNode) {
this.addChildrenOfClass(DigitalTwinConstants.NAMED_ENTITY_NODE, componentNode);
this.addRangeOfProperty(DigitalTwinConstants.IMPLEMENTS, componentNode);
}
}

/**
* rename class node in target version
* @param oldName old name
* @param newName new name
* @param version target version
*/
private renameClassNode(oldName: string, newName: string, version: number): ClassNode | undefined {
const oldClass: ClassNode | undefined = this.getClassNode(oldName);
if (!oldClass) {
return undefined;
}
const newClass: ClassNode = this.cloneNode(oldClass) as ClassNode;
newClass.id = this.getId(newName);
newClass.label = newName;
newClass.version = { includeSince: version };
oldClass.version = { excludeSince: version };
return newClass;
}

/**
* clone DigitalTwin node
* @param node node
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private cloneNode(node: any): any {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const clone: any = {};
for (const key in node) {
if (Array.isArray(node[key])) {
// create new array to hold elements
clone[key] = [...node[key]];
} else {
// shallow copy
clone[key] = node[key];
}
}
return clone;
}

/**
* add class node as range of target property
* @param name target property name
* @param classNode class node
*/
private addRangeOfProperty(name: string, classNode: ClassNode): void {
const propertyNode: PropertyNode | undefined = this.getPropertyNode(name);
if (!propertyNode) {
return;
}
if (!propertyNode.range) {
propertyNode.range = [];
}
propertyNode.range.push(classNode);
}

/**
* add class node as children of target class
* @param name target class name
* @param classNode class node
*/
private addChildrenOfClass(name: string, classNode: ClassNode): void {
const parent: ClassNode | undefined = this.getClassNode(name);
if (!parent) {
return;
}
if (!parent.children) {
parent.children = [];
}
parent.children.push(classNode);
}

/**
* expand properties from base class node
*/
Expand Down

0 comments on commit 84192b8

Please sign in to comment.