-
Notifications
You must be signed in to change notification settings - Fork 3
TTN MQTT & device management (#8) #13
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
Open
noerw
wants to merge
22
commits into
develop
Choose a base branch
from
feature/mqtt
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
00b1379
use bunyan for logging
52c3a03
connect to ttn mqtt broker
11f8990
handle mqtt uplink messages
a53a30c
fix errorhandling (mostly)
8a80f20
fix errorhandling (for real!)
f98d39e
send response before logging, lint
5dbe568
update opensensemap API
be3d70f
add hook for registration of new devices.
44c17b2
Merge branch 'feature/mqtt' into develop
941f147
apply correct keys, comments
noerw fc9c445
change route auth to Authorization header token
noerw baeb09d
cleanup & fix for missing auth token
noerw 26351c9
update ttn to v2.3.0-alpha.3
noerw c8cec3f
fix docker build
noerw 9762ba5
improve error handling
noerw 26a7690
add tests for /v1.1/ttndevice/:boxId
noerw 3a4bce3
add mqtt end2end tests
noerw dfee586
mqtt: match box via boxID
noerw d34cd9f
update jsdoc
noerw 1605e5b
use standard HTTP codes
noerw f6c0911
minor readme fix
noerw b37c5a3
update deps
noerw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Box } = require('openSenseMapAPI').models; | ||
| const { BoxNotFoundError } = require('./errors'); | ||
|
|
||
| /** | ||
| * look up a Box in the database for a given ttn configuration | ||
| * @param {string} app_id | ||
| * @param {string} dev_id | ||
| * @param {string} [port] | ||
| */ | ||
| const boxFromDevId = function boxFromDevId (app_id, dev_id, port) { | ||
| return Box.find({ | ||
| 'integrations.ttn.app_id': app_id, | ||
| 'integrations.ttn.dev_id': dev_id | ||
| }) | ||
| .then(boxes => { | ||
| if (!boxes.length) { | ||
| throw new BoxNotFoundError(`for dev_id '${dev_id}' and app_id '${app_id}'`); | ||
| } | ||
|
|
||
| // filter the boxes by their configured port. | ||
| // also include boxes with undefined port. | ||
| const box = boxes.filter(box => { | ||
| const p = box.integrations.ttn.port; | ||
|
|
||
| return (p === port || p === undefined); | ||
| })[0]; | ||
|
|
||
| if (!box) { | ||
| throw new BoxNotFoundError(`for port ${port}`); | ||
| } | ||
|
|
||
| return box; | ||
| }); | ||
| }; | ||
|
|
||
| const boxFromBoxId = function boxFromBoxId (id) { | ||
| return Box.findBoxById(id, { populate: false }) | ||
| .catch(err => Promise.reject(new BoxNotFoundError(err.message))); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| boxFromBoxId, | ||
| boxFromDevId, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * All errors handled by the app must inherit from TTNError | ||
| * and should be defined here for easier discovery. | ||
| */ | ||
| class TTNError extends Error { } | ||
|
|
||
| class BoxNotFoundError extends TTNError { | ||
| constructor (message) { | ||
| super(`No box found ${message}`); | ||
| this.code = 404; | ||
| } | ||
| } | ||
|
|
||
| class PayloadError extends TTNError { | ||
| constructor (message) { | ||
| super(`Invalid payload: ${message}`); | ||
| this.code = 422; | ||
| } | ||
| } | ||
|
|
||
| class DecodingError extends PayloadError { | ||
| constructor (message, decoder = 'generic') { | ||
| super(`${message} (${decoder} decoder)`); | ||
| this.component = decoder; | ||
| } | ||
| } | ||
|
|
||
| class LoraError extends DecodingError { | ||
| constructor (message) { | ||
| super(message, 'lora-serialization'); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| module.exports = { | ||
| TTNError, | ||
| BoxNotFoundError, | ||
| PayloadError, | ||
| DecodingError, | ||
| LoraError, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
app_idanddev_idare not enforced to be unique on the model schema. You should add the requirement to the main projectThere was a problem hiding this comment.
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, porttuple is assumed to be unique..