Wip/mqtt/init - tracking mqtt experiments #190
Merged
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
4f195dd
introduce mqtt
bewest cc0cd36
lint records first
bewest 8759cb9
Merge remote-tracking branch 'origin/develop' into wip/mqtt/init
bewest e16328c
Merge branch 'dev' into wip/mqtt/init
bewest b9e8a5f
make mqtt experiments suitable for hacking
bewest c8be1de
get mqtt basically working, very rough
bewest 756e9e8
forgot long
bewest 9ad7bf1
test coverage
bewest 33e1a36
Quick hack to get things working
ktind 1f1bc4d
blarg, attempt to debug mqtt
bewest f70a031
store each record according to own timestamp
bewest bf2f623
tweak times and protobuf model with @ktind
bewest 70877f7
Adding experimental time calculation algorithm
ktind de51d22
Merge branch 'wip/mqtt/init' of github.com:ktind/cgm-remote-monitor i…
bewest 650bcd1
First pass at adding MGB, Sensor, Calibration, and Device Status reco…
ktind b37069e
allow multiple instances of mqtt to multiplex
bewest e59adfc
Merge remote-tracking branch 'origin/wip/mqtt/init' into wip/mqtt/ini…
ktind 76b9a15
Store the download object in the entries for debugging purposes
ktind 11a7d9d
Updating model and removing dead code
ktind e4d6675
Merge remote-tracking branch 'origin/dev' into wip/mqtt/init
ktind 6b4041a
fix mbg undefined
bewest ddc9bf2
only need one stream factory
bewest de7cb78
force strict zero check
bewest 1b5fc82
Merge branch 'release/0.6.3'
jasoncalabrese 48bdd80
Merge pull request #413 from nightscout/release/0.6.4
jasoncalabrese d529801
merged master into mqtt/init
jasoncalabrese abbd231
Merge branch 'dev' into wip/mqtt/init
jasoncalabrese f21c317
updated with dev
jasoncalabrese 98417ae
Merge branch 'dev' into wip/mqtt/init
jasoncalabrese a291a0e
Merge pull request #496 from nightscout/wip/context-range-fix
jasoncalabrese 469d868
rebasing, it seems to run
bewest 1a38f4e
fix broken test
bewest 6705b62
bring back ensureIndexes
bewest 82032f4
Merge branch 'wip/mqtt/rebased' into wip/mqtt/init
bewest 0cdd3c0
rm spurious tmp file
bewest 7578c1a
make mqtt listener more unique
bewest d185010
remove spurious, unused code
bewest
Jump to file
No files found.
+59
−0
app.js
app.js
+4
−1
env.js
env.js
+39
−0
bootevent.js
lib/bootevent.js
+37
−37
devicestatus.js
lib/devicestatus.js
+6
−13
entries.js
lib/entries.js
+185
−0
mqtt.js
lib/mqtt.js
+18
−0
poller.js
lib/poller.js
+4
−13
treatments.js
lib/treatments.js
+16
−2
package.json
package.json
+21
−75
server.js
server.js
| @@ -0,0 +1,59 @@ | ||
| + | ||
| +var express = require('express'); | ||
| +var compression = require('compression'); | ||
| +function create (env, ctx) { | ||
| + /////////////////////////////////////////////////// | ||
| + // api and json object variables | ||
| + /////////////////////////////////////////////////// | ||
| + var api = require('./lib/api/')(env, ctx.entries, ctx.settings, ctx.treatments, ctx.profiles, ctx.devicestatus); | ||
| + var pebble = ctx.pebble; | ||
| + | ||
| + var app = express(); | ||
| + app.entries = ctx.entries; | ||
| + app.treatments = ctx.treatments; | ||
| + app.profiles = ctx.profiles; | ||
| + app.devicestatus = ctx.devicestatus; | ||
| + var appInfo = env.name + ' ' + env.version; | ||
| + app.set('title', appInfo); | ||
| + app.enable('trust proxy'); // Allows req.secure test on heroku https connections. | ||
| + | ||
| + app.use(compression({filter: shouldCompress})); | ||
| + | ||
| + function shouldCompress(req, res) { | ||
| + //TODO: return false here if we find a condition where we don't want to compress | ||
| + // fallback to standard filter function | ||
| + return compression.filter(req, res); | ||
| + } | ||
| + | ||
| + //if (env.api_secret) { | ||
| + // console.log("API_SECRET", env.api_secret); | ||
| + //} | ||
| + app.use('/api/v1', api); | ||
| + | ||
| + | ||
| + // pebble data | ||
| + app.get('/pebble', pebble(ctx.entries, ctx.treatments, ctx.profiles, ctx.devicestatus)); | ||
| + | ||
| + //app.get('/package.json', software); | ||
| + | ||
| + // define static server | ||
| + //TODO: JC - changed cache to 1 hour from 30d ays to bypass cache hell until we have a real solution | ||
| + var staticFiles = express.static(env.static_files, {maxAge: 60 * 60 * 1000}); | ||
| + | ||
| + // serve the static content | ||
| + app.use(staticFiles); | ||
| + | ||
| + var bundle = require('./bundle')(); | ||
| + app.use(bundle); | ||
| + | ||
| +// Handle errors with express's errorhandler, to display more readable error messages. | ||
| + | ||
| + // Handle errors with express's errorhandler, to display more readable error messages. | ||
| + var errorhandler = require('errorhandler'); | ||
| + //if (process.env.NODE_ENV === 'development') { | ||
| + app.use(errorhandler()); | ||
| + //} | ||
| + return app; | ||
| +} | ||
| +module.exports = create; | ||
| + |
| @@ -0,0 +1,39 @@ | ||
| + | ||
| +var bootevent = require('bootevent'); | ||
| + | ||
| +function boot (env) { | ||
| + var store = require('./storage')(env); | ||
| + var proc = bootevent( ) | ||
| + .acquire(function db (ctx, next) { | ||
| + // initialize db connections | ||
| + store( function ready ( ) { | ||
| + console.log('storage system ready'); | ||
| + ctx.store = store; | ||
| + next( ); | ||
| + }); | ||
| + }) | ||
| + .acquire(function data (ctx, next) { | ||
| + /////////////////////////////////////////////////// | ||
| + // api and json object variables | ||
| + /////////////////////////////////////////////////// | ||
| + ctx.pushover = require('./pushover')(env); | ||
| + ctx.entries = require('./entries')(env.mongo_collection, ctx.store, ctx.pushover); | ||
| + ctx.settings = require('./settings')(env.settings_collection, ctx.store); | ||
| + ctx.treatments = require('./treatments')(env.treatments_collection, ctx.store, ctx.pushover); | ||
| + ctx.devicestatus = require('./devicestatus')(env.devicestatus_collection, ctx.store); | ||
| + ctx.profiles = require('./profile')(env.profile_collection, ctx.store); | ||
| + ctx.pebble = require('./pebble'); | ||
| + console.info("Ensuring indexes"); | ||
| + | ||
| + console.log(ctx.entries, ctx.entries.indexedFields); | ||
| + store.ensureIndexes(ctx.entries( ), ctx.entries.indexedFields); | ||
| + store.ensureIndexes(ctx.treatments( ), ctx.treatments.indexedFields); | ||
| + store.ensureIndexes(ctx.devicestatus( ), ctx.devicestatus.indexedFields); | ||
| + | ||
| + next( ); | ||
| + }) | ||
| + ; | ||
| + return proc; | ||
| + | ||
| +} | ||
| +module.exports = boot; |
Oops, something went wrong.