Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple-fota-example.js - README tip & improve logs #30

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 42 additions & 31 deletions simple-js-examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
# Simple Javascript protocol translator and management example

## Dependencies / pre-requisites

This example uses `node.js v8` or higher.
LmP Edge devices do not by default have it.

Install the dependencies:
```bash
npm install
```

Dependencies are:

simple-edge-api-examples
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]

The list with version can be listed with:
```bash
npm ls
```

## simple-fota-example.js
These example protocol translators demostrate the fota capabilities. The PT needs to register these resources:
These example protocol translators (PT) demostrate the FOTA capabilities. The PT needs to register these resources:

| Resource | Object id | Instance id | Resource id |
| Resource | Object id | Instance id | Resource id |
|----------------------------|------------|-------------|-------------|
| Component Identity | 14 | 0 | 0 |
| Component Version | 14 | 0 | 2 |
Expand All @@ -16,7 +44,16 @@ These example protocol translators demostrate the fota capabilities. The PT need
| Vendor UUID | 10255 | 0 | 3 |
| Class UUID | 10255 | 0 | 4 |

The edge-core uses these resources to receive the manifest, send the status as well as the result back to the cloud. The PT needs to implement the function that receives the vendorid, classid, version and firmware size using `manifest_meta_data` api. The PT then needs to verifies the vendor and class id. Upon successful verification, the PT needs to send the download request to the edge-core using `download_asset` api. If the edge-core successfully downloaded the firmware, the PT receives the path of the downloaded binary, otherwise it gets the error. The PT then needs to deregister the device and starts the firmware update process. The PT then registers the device with the new firmware version(14/0/2) that it received from the `manifest_meta_data` api.
The edge-core uses these resources to receive the manifest, send the status as well as the result back to the cloud. The PT needs to implement the function that receives the vendor ID, class ID, version and firmware size using `manifest_meta_data` API. The PT then needs to verify the vendor ID and class ID. Upon successful verification, the PT needs to send the download request to the edge-core using `download_asset` API. If the edge-core successfully downloaded the firmware, the PT receives the path of the downloaded binary, otherwise, it gets the error code. The PT then needs to deregister the device and start the firmware update process. The PT then re-registers the device with the new firmware version (14/0/2) that is received from the `manifest_meta_data` API.

Please note that the manifest file you use must have matching vendor ID and class ID.

```
vendor:
vendor-id: 5355424445564943452d56454e444f52
device:
class-id: 5355424445564943452d2d434c415353
```

## simple-pt-example.js and pt-crypto-api-example.js

Expand Down Expand Up @@ -54,7 +91,7 @@ API and read the relevant documentation for Edge APIs from

## simple-grm-example.js

These example gateway resource managers demonstrate the calls and parameters to pass to
This example gateway resource manager demonstrates the calls and parameters to pass to
Edge Core gateway resource management API. The `simple-grm-example.js` demonstrates the
basic resource manager functionality, ie. registering, adding resources and
updation. The websocket connection and JSONRPC 2.0 specification and communication
Expand All @@ -66,33 +103,6 @@ Please study the example code to see how to use the gateway resource manager
JSONRPC 2.0 API and read the relevant documentation for Edge APIs from
[Device Management Docs](https://developer.izumanetworks.com/docs/device-management-edge/latest/protocol-translator/index.html).

## Dependencies

This example uses `node.js v8` or higher.

Install the dependencies:
```bash
npm install
```

Dependencies are:

simple-edge-api-examples
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]

The list with version can be listed with:
```bash
npm ls
```

## Running the protocol translator example

Fixed values for the example:
Expand All @@ -113,6 +123,7 @@ Fixed values for the example:
```
Or, using docker
```
docker build
docker run -v /tmp:/tmp -it simple-pt-example:latest
```
1. Monitor the registered Edge and endpoint device from Device Management Portal.
Expand Down
7 changes: 6 additions & 1 deletion simple-js-examples/simple-fota-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ EdgePTExample.prototype.exposeVendorandClass = function () {
}, null);
return;
}
console.log(GREEN, "received fota request")
console.log(GREEN, "Received FOTA request")
console.log(params)
var fw_size = params.size
var classid = new Buffer.from(params.classid, "base64");
Expand All @@ -428,13 +428,17 @@ EdgePTExample.prototype.exposeVendorandClass = function () {
deviceId: deviceid,
size: fw_size
}
console.log(GREEN, "Class ID : ", classid.toString("ascii"))
console.log(GREEN, "Vendor ID : ", vendorid.toString("ascii"))
console.log(GREEN, "FW version: ", fw_version)
// checking vendor and class id from manifest is equal or not.
if((Buffer.compare(vendorid, VENDORID)!= 0) && (Buffer.compare(classid, CLASSID)!= 0)) {
response({
"code": -32602,
"data": "wrong vendor or class ID",
"message": "wrong vendor or class ID"
}, /* success */ null);
console.log(RED, "Wrong vendor or class ID")
}
else {
response( null,'ok');
Expand Down Expand Up @@ -511,6 +515,7 @@ const holdProgress = async (message) => {
await holdProgress("Press any key to register the example device.");
response = await edge.registerExampleDevice(DEVICE_ID,"0.0.0");
console.log(GREEN, "Registered an example device. Response:", response);
console.log(GREEN, "Subdevice FOTA can be started.")

await holdProgress("Press any key to update example device values.");
response = await edge.updateExampleDeviceResources(DEVICE_ID);
Expand Down
Loading