Skip to content

ConnectAPI throws error when connecting device to ARM Pelion #593

Description

@Antondj5

While trying to create a connector to subscribe to value changes of devices on the ARM Pelion platform I ran in to an issue. When connecting my device (a linux vm) to the Pelion platform (using this tutorial) while the following code is running I get the error you can see below.

const sdk = require('mbed-cloud-sdk')

const connect = new sdk.ConnectApi({
  apiKey: 'apikey',
  host: 'https://api.us-east-1.mbedcloud.com',
  autostartNotifications: true
})

const main = async () => {

  try {
    let observer = await connect.subscribe.resourceValues({ resourcePaths: ['*'] }, 'OnRegistration')
    observer.addListener((message) => {
      console.log(message)
    })
  } catch (e) {
    throw e
  }

}

main()
/arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/models/deviceEventAdapter.js:30
             type: common_1.TlvDataType[from.ct],
                                       ^

 TypeError: Cannot read property 'undefined' of undefined
     at Function.DeviceEventAdapter.mapResource (/arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/models/deviceEventAdapter.js:30:39)
     at /arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/models/deviceEventAdapter.js:39:43
     at Array.map (<anonymous>)
     at Function.DeviceEventAdapter.map (/arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/models/deviceEventAdapter.js:38:40)
     at /arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/actions/notifications.js:114:63
     at Array.forEach (<anonymous>)
     at Object.exports.notify (/arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/actions/notifications.js:113:28)
     at /arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/actions/notifications.js:214:37
     at NotificationsApi.ApiBase.complete (/arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/common/apiBase.js:262:13)
     at /arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/common/apiBase.js:219:19
 Waiting for the debugger to disconnect...
 error Command failed with exit code 1.

Am I doing something wrong or is this a problem with the SDK?

The code works fine when I start my application and my device is already registered.
The code fails when the code is running and I connect the device afterwards (execute the script -> see link to tutorial above).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions