TheThingsArchive / node-app-sdk

The Things Network Application SDK for Node.JS
https://www.thethingsnetwork.org/docs/node-js/
MIT License
41 stars 28 forks source link

install node.js sdk with npm on centos 6 #92

Closed paultanner closed 6 years ago

paultanner commented 6 years ago

I originally did this install many months ago and want to reinstall the latest version. Is there a better way to install? this is what I get:

npm install --save ttn
npm WARN package.json bcrypt-pbkdf@1.0.1 No repository field.
npm WARN package.json mongo@0.1.0 No repository field.
npm http GET https://registry.npmjs.org/ttn
npm http GET https://registry.npmjs.org/ttn
npm http GET https://registry.npmjs.org/ttn
npm ERR! Error: CERT_UNTRUSTED
npm ERR!     at SecurePair.<anonymous> (tls.js:1346:32)
npm ERR!     at SecurePair.EventEmitter.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:959:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:463:15)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:320:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:366:25)
npm ERR!     at doWrite (_stream_writable.js:219:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:209:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:180:11)
npm ERR!     at write (_stream_readable.js:573:24)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 2.6.32-220.el6.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "--save" "ttn"
npm ERR! cwd /root/ttn
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.3.5
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /root/ttn/npm-debug.log
npm ERR! not ok code 0
paultanner commented 6 years ago

This is not what it appears to be. The problem is caused by trying to use old versions of git, npm and node. As the code uses import, it seems that babel is also required. Still trying to get the server up to the latest versions of these. It would be useful to mention this in the readme and also link to the necessary update procedure.

paultanner commented 6 years ago

ok. got a babel installation with advice from here https://www.codementor.io/iykyvic/writing-your-nodejs-apps-using-es6-6dh0edw2o now trying to get a fresh copy of the ttn library

npm install ttn + ttn@2.3.1 updated 1 package and audited 2686 packages in 9.384s found 2 moderate severity vulnerabilities runnpm audit fixto fix them, ornpm auditfor details up to date in 3.9s fixed 0 of 2 vulnerabilities in 2686 scanned packages 2 vulnerabilities required manual review and could not be updated

then ran npm audit fix same message returned no log file generated in this directory.

any suggestions?

Thx. Paul

noerw commented 6 years ago

These issues do not seem related to the ttn package. You are using an ancient version of node and NPM, I guess your issues are related to that. There are current packages available.

Your last comments seems to indicate that ttn was installed successfully:

updated 1 package

paultanner commented 6 years ago

Sadly I don't know how I fixed it as I got interrupted. Certainly I ran npm audit fix multiple times.

The I hit this Error: 7 PERMISSION_DENIED: permission denied: No "settings" rights to Application but this only applies when I use application(appID, accessKey) which I don't need at the moment. Looking at this https://www.thethingsnetwork.org/docs/network/account/authentication.html I see that my server does not have permission to access the application that I set up in the TTN console. OK. But it's not clear how to fix that. The accessKeys are the same for my device and its application. Pasted straight from the TTN console.

code:


const appID = 'test_with_ti_shield2';
const accessKey = 'ttn-account-v2.etcetcetc';

// discover handler and open mqtt connection
data(appID, accessKey)
  .then(function (client) {
    client.on("uplink", function (devID, payload) {
      console.log("Received uplink from ", devID)
      console.log(payload)
    })
  })
  .catch(function (err) {
    console.error(err)
    process.exit(1)
  })

// discover handler and open application manager client
application(appID, accessKey)
  .then(function (client) {
    return client.get()
  })
  .then(function (app) {
    console.log("Got app", app)
  })
  .catch(function (err) {
    console.error(err)
    process.exit(1)
  })

console.log("starting ttn server");
johanstokking commented 6 years ago

Does the access key have the settings right, as the error message indicates?

paultanner commented 6 years ago

Presumably not. I checked the settings tabs for device and application and can see nothing relating to "permissions". Can you point me to the relevant setting that may be causing the issue pls?

BTW. As mentioned before, I can access the device OK but not the application. This implies that I have correctly pasted the accessKey from the TTN console.

johanstokking commented 6 years ago

Right, please check that the key you use has the settings right too, not just devices. You can manage keys under Settings.

screen shot 2018-07-20 at 09 50 20
paultanner commented 6 years ago

I do not get a screen like that. Here's mine.

screen shot 2018-07-20 at 09 53 57
johanstokking commented 6 years ago

Click generate new access key and tick the right boxes.

The screenshot comes from the bottom of the application page by the way.

paultanner commented 6 years ago

Ok Thx @johanstokking So the issue was that I did not know that another access key could be needed. I think the error message could be better:

No "settings" rights to Application

.. could instead say:

The accessKey you are using does not have rights to access the Application. You may need to generate another accessKey.