diff --git a/simple-js-examples/README.md b/simple-js-examples/README.md index 27918fa..4555892 100644 --- a/simple-js-examples/README.md +++ b/simple-js-examples/README.md @@ -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 + ├── 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 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 +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 @@ -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 @@ -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 - ├── 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: @@ -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. 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);