Coder Social home page Coder Social logo

nordicsemiconductor / asset-tracker-cloud-coiote-aws-converter-js Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 1.0 1.48 MB

Convert the LwM2M JSON encoding written by AVSystem's Coiote AWS integration to nRF Asset Tracker's LwM2M JSON encoding.

Home Page: https://github.com/NordicSemiconductor/asset-tracker-cloud-coiote-aws-converter-js#readme

License: BSD 3-Clause "New" or "Revised" License

JavaScript 0.24% TypeScript 99.76%
coiote iot lwm2m nrf-asset-tracker

asset-tracker-cloud-coiote-aws-converter-js's People

Contributors

coderbyheart avatar mlopezj avatar renovate[bot] avatar

Watchers

 avatar  avatar  avatar

Forkers

mlopezj

asset-tracker-cloud-coiote-aws-converter-js's Issues

Convert shadow

Uses the convert function (src/convert.ts) to transform the shadow (docs/coiote-example.json)

Issues

  • Not recognized valid date value #13
  • Location Assistance is not recognized as custom Av System object #17
  • Invalid props in LwM2M Server after conversion #18
  • Remove duplicate method name #20

Error when converting prop as `date` type with value `1970-01-01T00:00:00Z`

When trying to convert

"Location": {
  "0": {
    "Altitude": "0.0",
    "Latitude": "0.0",
    "Longitude": "0.0",
    "Radius": "0.0",
    "Speed": "0.0",
    "Timestamp": "1970-01-01T00:00:00Z",
    "Velocity": ""
  }
},

an error was thrown

Error: Invalid LwM2M object definition received: [{"instancePath":"/6/5","schemaPath":"#/properties/6/properties/5/unixTimestamp","keyword":"unixTimestamp","params":{},"message":"Timestamps must be expressed as an integer between 11111111111 and 9999999999, for example \"1476186613\" seconds since Jan 01 1970, which represents 2016-10-11T11:50:13.000Z"}]

It does not happen when value of Timestamp prop is 2022-10-07T13:33:22Z

So minimum and maximum range must be updated for values that accepts 1970-01-01T00:00:00Z as a value

Coiote's shadow composition

TLDR

  1. HOCON-based LwM2M object
  2. Custom Av System object
  3. Not recognized objects in Coiote

1- HOCON-based LwM2M object

Coiote's shadow is composed by their version of LwM2M objects, which is generated using a HOCON-based system and basically what it does is to replace ids of objects with their name, making the output human friendly.

{
"Temperature": {
  "0": {
    "Application Type": "",
    "Fractional Timestamp": {
      "noValue": true
    },
    "Max Measured Value": "23.51",
    "Max Range Value": "85.0",
    "Measurement Quality Indicator": {
      "noValue": true
    },
    "Measurement Quality Level": {
      "noValue": true
    },
    "Min Measured Value": "23.51",
    "Min Range Value": "-40.0",
    "Reset Min and Max Measured Values": {
      "noValue": true
    },
    "Sensor Units": "Celsius degrees",
    "Sensor Value": "24.57",
    "Timestamp": "2022-10-07T13:33:22Z"
    }
  }
}

However, in the shadow can be other escenarios

2- Custom Av System objects

"Location Assistance": {
  "0": {
    "Assistance type": "4",
    "A-GPS assistance mask": "128",
    "P-GPS predictionCount": "0",
    "P-GPS predictionIntervalMinutes": "0",
    "P-GPS startGpsDay": "0",
    "P-GPS startGpsTimeOfDaySeconds": "0",
    "accuracy": "526.0",
    "altitude": {
      "noValue": true
    },
    "assistance_data": {
      "noValue": true
    },
    "latitude": "63.42061758",
    "longitude": "10.43935061",
    "result code": {
      "noValue": true
    }
  }
}

3- Not recognized objects in Coiote

Last possible case scenario is when:

Coiote is missing proper object definition and has no translation for the key.

{
  "33605": {},
  "33606": {
    "0": {
      "0": "Dummy_OBU_ID",
      "1": "PL 473N0",
      "2": "01-345678-901234",
      "3": "26000007",
      "4": "8926000000073",
      "5": "60.0",
      "6": "26001.0",
      "7": "GMSK",
      "8": "GMSK",
      "9": "1950.0",
      "10": "2140.0",
      "11": "6069.0",
      "12": "11503.0",
      "13": "0.0",
      "14": "0.0",
      "15": "4.5218974"
    }
  },
}

What should happen when a resource with repeated name is trying to be converted to LwM2M format

About

Conflicts with name-keys objects

Description

Object input is LwM2M, however it is in an "Av System" way because id of resources is its name instead of its id.

So for Location resource, the input looks like this:

"Location": {
  "0": {
    "Altitude": "0.0",
    "Latitude": "0.0",
    "Longitude": "0.0",
    "Radius": "0.0",
    "Speed": "0.0",
    "Timestamp": "2022-10-07T13:33:22Z",
    "Velocity": ""
  }
}

Instead of this

"6": {
  "0": "0.0",
  "1": "0.0",
  "2": "0.0",
  "3": "0.0",
  "4": "",
  "5": "2022-10-07T13:33:22Z",
}

This is not conflict free because names on LwM2M are not unique.

For example, there is 2 resources with Location as the name:

What should happen in cases like this?

Using `names` as key to transform coiote json is not recommended

The input of the system is a Coiote json. It could looks like this:

"ECID-Signal Measurement Information": {
        "0": {
          "physCellId": "247",
          "ECGI": "0",
          "arfcnEUTRA": "6400",
          "rsrp-Result": "-96",
          "rsrq-Result": "-12",
          "ue-RxTxTimeDiff": "0"
        }
      }

The propouse is to transform in something like this:

"10256":  [
   { 
         "0": 247,
          "1": 0, 
          "2": 6400, 
          "3": -96, 
           "4": -12, 
           "5": 0 
     }
     
]

Right now, there is used the name of the prop in order to check in @nordicsemiconductor/lwm2m-types lib the data type and then, make the data casting.

However,

  • Names from LwM2M are not unique.
  • The way it is spelled can be 'tricky'

Recently I found an issue described here: c316b26

I think is not recommended to use names as the key for the transformation and I would prefer the ID of the resource and prop to do it.

This should be take in consideration at the moment of take the decision of the solution implementation.

Invalid LwM2M object definition received for `LwM2M Server` object

When trying to convert LwM2M Server object, the following error message appears:

Error: Invalid LwM2M object definition received: [{"instancePath":"/1:[email protected]/0/6","schemaPath":"#/properties/1%3A1.2%401.2/items/properties/6/type","keyword":"type","params":{"type":"integer"},"message":"must be integer"}]

The converted object (output) looks like this:

'1:[email protected]': [
    {
      '0': 101,
      '1': 43200,
      '2': 0,
      '3': 0,
      '5': 86400,
      '6': NaN,
      '7': 'U',
      '22': '',
      '23': NaN
    }
  ]

This is the input data (shadow) for the failing props:

"LwM2M Server": {
  "0": {
    "Mute Send": "false", // 23
    "Notification Storing When Disabled or Offline": "false", // 6
  }
}

This is the XML representation of LwM2M Server in the LwM2M registry

<Item ID="23"><Name>Mute Send</Name>
  <Operations>RW</Operations>
  <MultipleInstances>Single</MultipleInstances>
  <Mandatory>Optional</Mandatory>
  <Type>Boolean</Type>
  <RangeEnumeration></RangeEnumeration>
  <Units></Units>
  <Description><![CDATA[If true or the Resource is not present, the LwM2M Client Send command capability is de-activated. 
  If false, the LwM2M Client Send Command capability is activated.]]></Description>
</Item>
<Item ID="6">
  <Name>Notification Storing When Disabled or Offline</Name>
  <Operations>RW</Operations>
  <MultipleInstances>Single</MultipleInstances>
  <Mandatory>Mandatory</Mandatory>
  <Type>Boolean</Type>
  <RangeEnumeration></RangeEnumeration>
  <Units></Units>
  <Description><![CDATA[If true, the LwM2M Client stores "Notify" operations to the LwM2M Server while the LwM2M Server account is disabled or the LwM2M Client is offline. After the LwM2M Server account is enabled or the LwM2M Client is online, the LwM2M Client reports the stored "Notify" operations to the Server.
  If false, the LwM2M Client discards all the "Notify" operations or temporarily disables the Observe function while the LwM2M Server is disabled or the LwM2M Client is offline.
  The default value is true.
  The maximum number of storing Notifications per Server is up to the implementation.]]></Description>
</Item>

Unknown resource name: Location Assistance

When trying to convert Location Assistance, the following error message appears

Error: Unknown resource name: Location Assistance

Executed code:

import { convert } from '@nordicsemiconductor/coiote-aws-converter-js'
import shadow from "./docs/coiote-example.json"
const converted = convert(shadow.state.reported)
console.log(converted)

Location Assistance is a custom Av System object. It is not part of LwM2M registry

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Fallback to renovate.json file as a preset is deprecated, please use a default.json file instead.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/sync-issue-labels.yaml
  • actions/checkout v4
  • ubuntu 22.04
.github/workflows/test-and-release.yaml
  • actions/checkout v4
  • actions/setup-node v4
  • actions/cache v4
.github/workflows/update-repo-info.yaml
  • actions/checkout v4
  • ubuntu 22.04
npm
package.json
  • @nordicsemiconductor/lwm2m-types 2.7.0
  • ajv 8.12.0
  • @bifravst/prettier-config 1.0.0
  • @commitlint/config-conventional 18.6.2
  • @nordicsemiconductor/eslint-config-asset-tracker-cloud-typescript 17.0.0
  • @swc/cli 0.3.9
  • @typescript-eslint/eslint-plugin 7.0.1
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-unicorn 51.0.1
  • husky 9.0.11
  • prettier 3.2.5
  • tsx 4.7.1
  • typescript 5.3.3
  • node >=20.0.0
  • npm >=9

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.