From e116dea4abf953041112d303ff669f6977f4f813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Fri, 27 Sep 2024 12:28:01 +0300 Subject: [PATCH 1/3] simple-fota-example.js - README tip & improve logs Add the tip on the manifest file (vendor and class ID). Add a bit more logging to the example. --- simple-js-examples/README.md | 21 +++++++++++++++++---- simple-js-examples/simple-fota-example.js | 7 ++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/simple-js-examples/README.md b/simple-js-examples/README.md index 27918fa..e08160a 100644 --- a/simple-js-examples/README.md +++ b/simple-js-examples/README.md @@ -1,9 +1,12 @@ # Simple Javascript protocol translator and management example +Please note that these example require a working Node.JS environment in your system. +LmP Edge devices do not by default have it. + ## 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 | @@ -16,7 +19,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 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 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 it received from the `manifest_meta_data` API. + +Please note that the manifest file you use must have matching vendor and class ID. + +``` +vendor: + vendor-id: 5355424445564943452d56454e444f52 +device: + class-id: 5355424445564943452d2d434c415353 +``` ## simple-pt-example.js and pt-crypto-api-example.js @@ -54,7 +66,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 @@ -113,6 +125,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. diff --git a/simple-js-examples/simple-fota-example.js b/simple-js-examples/simple-fota-example.js index ba6ef34..3da2a58 100644 --- a/simple-js-examples/simple-fota-example.js +++ b/simple-js-examples/simple-fota-example.js @@ -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"); @@ -428,6 +428,9 @@ 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({ @@ -435,6 +438,7 @@ EdgePTExample.prototype.exposeVendorandClass = function () { "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'); @@ -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); From c5aafd265fb1ce590ce51fbcb9b82e1c9adbd096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Fri, 27 Sep 2024 13:47:08 +0300 Subject: [PATCH 2/3] simple-js-examples - bring pre-reqs to top They are sort of hidden now (and they are common to all), so raise them to the top. --- simple-js-examples/README.md | 54 +++++++++++++++++------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/simple-js-examples/README.md b/simple-js-examples/README.md index e08160a..e6f090e 100644 --- a/simple-js-examples/README.md +++ b/simple-js-examples/README.md @@ -1,8 +1,33 @@ # Simple Javascript protocol translator and management example -Please note that these example require a working Node.JS environment in your system. +## 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 + ├── es6-promisify@6.0.0 + ├─┬ json-rpc-ws@5.0.0 + │ ├─┬ debug@3.1.0 + │ │ └── ms@2.0.0 + │ ├── uuid@3.2.1 + │ └─┬ ws@4.1.0 + │ ├── async-limiter@1.0.0 + │ └── safe-buffer@5.1.2 + └── repl.history@0.1.4 + +The list with version can be listed with: +```bash +npm ls +``` + ## simple-fota-example.js These example protocol translators (PT) demostrate the FOTA capabilities. The PT needs to register these resources: @@ -78,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 - ├── es6-promisify@6.0.0 - ├─┬ json-rpc-ws@5.0.0 - │ ├─┬ debug@3.1.0 - │ │ └── ms@2.0.0 - │ ├── uuid@3.2.1 - │ └─┬ ws@4.1.0 - │ ├── async-limiter@1.0.0 - │ └── safe-buffer@5.1.2 - └── repl.history@0.1.4 - -The list with version can be listed with: -```bash -npm ls -``` - ## Running the protocol translator example Fixed values for the example: From 6bcc588f6171bd00937e04646ecef74a6797a37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Mon, 30 Sep 2024 10:12:41 +0300 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Jenia Kogan --- simple-js-examples/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simple-js-examples/README.md b/simple-js-examples/README.md index e6f090e..4555892 100644 --- a/simple-js-examples/README.md +++ b/simple-js-examples/README.md @@ -44,9 +44,9 @@ These example protocol translators (PT) demostrate the FOTA capabilities. The PT | 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 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 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 and class ID. +Please note that the manifest file you use must have matching vendor ID and class ID. ``` vendor: