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

ConnectAPI throws error when connecting device to ARM Pelion #593

Open
Antondj5 opened this issue Mar 5, 2020 · 4 comments
Open

ConnectAPI throws error when connecting device to ARM Pelion #593

Antondj5 opened this issue Mar 5, 2020 · 4 comments

Comments

@Antondj5
Copy link

Antondj5 commented Mar 5, 2020

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).

@Antondj5
Copy link
Author

Antondj5 commented Mar 5, 2020

When commenting out type: common_1.TlvDataType[from.ct], in /arm-connector/node_modules/mbed-cloud-sdk/lib/legacy/connect/models/deviceEventAdapter.js:30 my code works as expected.

 DeviceEventAdapter.mapResource = function (from, deviceId) {
        console.log('from', from)
        console.log('common_1', common_1)
        return {
            contentType: from.rt,
            observable: from.obs,
         //   type: common_1.TlvDataType[from.ct],
            path: from.path,
            deviceId: deviceId,
        };
    };

@alexl0gan
Copy link
Contributor

What environment are you running in? I just added a test to check the mapping and it worked fine. It looks like either something has gone wrong with the module resolution or your environment can't understand the enum.

@Antondj5
Copy link
Author

Antondj5 commented Mar 13, 2020

I'm running a node v10.19.0 environment on MacOS Mojave v10.14.6. Do I need a more recent version of node?
Edit:
I also use yarn v1.22.0 as a package manager.

@alexl0gan
Copy link
Contributor

I use 10.18.0 so that shouldn't be an issue. I will investigate further today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants