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

TTN MQTT & device management (#8) #13

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open

TTN MQTT & device management (#8) #13

wants to merge 22 commits into from

Conversation

noerw
Copy link
Member

@noerw noerw commented Nov 6, 2017

implements the feature that was suggested in #8.
Also featuring a rewrite of error handling code

Things to consider (@ubergesundheit):

  • will the oSeM-frontend or -backend call the webhook to trigger the TTN registration?
    • (scalable) authentication mechanism! (currently token auth from env variable)

TODO

  • update docker build
  • update jsdoc
  • end to end tests with thethingsnetwork (ttnctl)
  • update README: document device registration & uplink flow
  • update osem db schema: add box.integrations.ttn.dev_eui, make app_id, dev_id, port tuple unique
  • add device registration call to GET ttnintegration/v1.1/ttndevice/:boxId at PUT & POST mainapi/boxes/:boxId handler
  • add new env vars to sensebox/OSeM-compose

noerw and others added 11 commits September 16, 2017 14:33
Now using Error subclasses to separate different response types
instead of a homebrew `err.code` check.
This allows to move the selection of errortype from the calling
promise chain to the throwing function, improving consistency and
readability.
TODO: authentication. right now theres an IP whitelist. proper
      authentication would allow queries directly from the
      oSeM frontend, which would provide a smoother integration
      in the end..
const p = box.integrations.ttn.port;

return (p === port || p === undefined);
})[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app_id and dev_id are not enforced to be unique on the model schema. You should add the requirement to the main project

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the app_id, dev_id, port tuple is assumed to be unique..

lib/ttn.js Outdated
const log = createLogger('ttn');

const onUplinkMessage = function onUplinkMessage (dev_id, message) {
const { app_id, port } = message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code to the httpIntegrationHandler ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the response handling is different & I wanted to have different loggers for each protocol, and I didn't consider 10 duplicated lines to be worth an additional abstraction

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok :)

@ubergesundheit
Copy link
Member

ubergesundheit commented Nov 29, 2017

Just pushed a docker image of this branch to sensebox/ttn-osem-integration:feature_mqtt

@ubergesundheit
Copy link
Member

Running the image results in a Cannot find module babel-runtime/regenerator error


> [email protected] start /usr/src/app
> node lib/index.js | bunyan -o short

module.js:471
    throw err;
    ^

Error: Cannot find module 'babel-runtime/regenerator'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/src/app/node_modules/ttn/dist/index.js:8:20)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/src/app/lib/ttn.js:6:36)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

@noerw
Copy link
Member Author

noerw commented Nov 29, 2017

I have this dependency in node_modules on my local installation.. sigh, shouldn't yarn.lock protect us from stuff like this?

See TheThingsArchive/node-app-sdk@e1eca3f, it seems the babel people (™) have messed with semver or something.
Instead of adding this dependency here, lets use the ttn beta release for now, it only contains changes from my PR anyway.

@noerw
Copy link
Member Author

noerw commented Nov 29, 2017

Also, I can finally test this with actual LoRa hardware in the next days. Will add end-to-end tests then

@ubergesundheit
Copy link
Member

Very good!
There is an additional error related to alpine/muslibc/glibc for the dependency grpc of the ttn package..

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/src/app/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64/grpc_node.node)
    at Error (native)
    at Object.Module._extensions..node (module.js:597:18)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/node/src/grpc_extension.js:30:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/node/src/client.js:38:12)

@noerw
Copy link
Member Author

noerw commented Feb 5, 2018

@ubergesundheit Hey, this is ready, implementation wise.
For these changes to be useful, they have to be integrated with the main API.
I cannot do that atm, due to lack of time and understanding of the new package architecture.

If required I can add comprehensive documentation on the required changes, a short list is in the TODO at the top of this PR already.

@ubergesundheit
Copy link
Member

Alright! Are there any changes to the angular app needed?

@noerw
Copy link
Member Author

noerw commented Feb 5, 2018

yeah. the user should be able to select between his own TTN device with http integration (current solution), or the auto-creation of a device with our application.
If he chooses the latter, he may provide an dev_eui, and gets the lora keys (otaa and abp?) back in the completed registration overview.

@noerw
Copy link
Member Author

noerw commented Feb 5, 2018

alternatively, a full integration with a Lora sketch containing the Lora keys comes to mind.
would this be feasible, or does the lora hardware require custom solutions anyway?

@ubergesundheit
Copy link
Member

With the new senseBox MCU in the pipeline, a LoRa Bee addon is planned. The generation of a full working sketch should be possible then.

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

Successfully merging this pull request may close these issues.

2 participants