forked from Temmermans/iot-device-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to stream data to REST endpoint
- Loading branch information
1 parent
ce6f1f6
commit db72e29
Showing
9 changed files
with
325 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
var Data = require('../models/data'); | ||
|
||
exports.all = function(req, res) { | ||
// route handlers go here | ||
Data.find({}, function(err, docs) { | ||
if(err) throw err; | ||
|
||
res.json(docs); | ||
}); | ||
} | ||
|
||
exports.write = function(req, res, next) { | ||
|
||
req.body.forEach(function(r, i){ | ||
|
||
const newData = new Data({ | ||
ESP_OPS: req.body[i]['ESP_OPS'], | ||
attributeName: req.body[i]['attributeName'], | ||
categories: req.body[i]['categories'] || [''], | ||
dataType: req.body[i]['dataType'], | ||
deviceName: req.body[i]['deviceName'], | ||
timestamp: req.body[i]['timestamp'], | ||
value: req.body[i]['value'], | ||
fixedValue: req.body[i]['fixedValue'] || '', | ||
min: req.body[i]['min'] || '', | ||
max: req.body[i]['max'] || '' | ||
}); | ||
|
||
newData.save(function(err) { | ||
if(err) throw err; | ||
res.end("Post succesfull"); | ||
}); | ||
}) | ||
} | ||
|
||
exports.delete = function(req, res, next) { | ||
|
||
Data.find({}).remove(function(err) { | ||
if (err) throw err; | ||
|
||
res.end('data deleted') | ||
}); | ||
|
||
} |
This file contains 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,25 @@ | ||
//here goes everything that interacts with the database, starting by creating or requiring the db | ||
var mongo = require('mongodb'); | ||
var mongoose = require('mongoose'); | ||
var mongoUrl = require('../../shared/config').credentials.mongodb.url; | ||
|
||
// set up our mongodb database | ||
mongoose.connect(mongoUrl); | ||
|
||
//set a variable to hold this connection | ||
var db = mongoose.connection; | ||
|
||
var dataSchema = mongoose.Schema({ | ||
ESP_OPS: {type: String}, | ||
attributeName: {type: String}, | ||
categories: [String], | ||
dataType: {type: String}, | ||
deviceName: {type: String}, | ||
timestamp: {type: String}, | ||
value: {type: String}, | ||
fixedValue: {type: String}, | ||
min: {type: String}, | ||
max: {type: String} | ||
}); | ||
|
||
var Data = module.exports = mongoose.model('Data', dataSchema); |
This file contains 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 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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.