diff --git a/app.js b/app.js index c9d6832..adb9ced 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,7 @@ var bodyParser = require('body-parser'); var index = require('./routes/index'); var success = require('./routes/success'); +var temperature = require('./routes/temperature'); var mongoose = require('mongoose'); var mainLoop = require('./main'); @@ -35,6 +36,7 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use('/success', success); +app.use('/temperature', temperature); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/models/temperature.js b/models/temperature.js new file mode 100644 index 0000000..9277961 --- /dev/null +++ b/models/temperature.js @@ -0,0 +1,11 @@ +var mongoose = require('mongoose'); + +var temperatureSchema = new mongoose.Schema({ + temperature: String, + humidity: String, + location: String, + updated: {type: Date, default: Date.now} +}); + + +mongoose.model('temperature', temperatureSchema); \ No newline at end of file diff --git a/mongoui/npm-debug.log b/mongoui/npm-debug.log new file mode 100644 index 0000000..399a9f5 --- /dev/null +++ b/mongoui/npm-debug.log @@ -0,0 +1,37 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'C:\\Program Files (x86)\\nodejs\\\\node.exe', +1 verbose cli 'C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', +1 verbose cli 'start' ] +2 info using npm@2.11.2 +3 info using node@v0.12.5 +4 verbose run-script [ 'prestart', 'start', 'poststart' ] +5 info prestart myapp@0.0.0 +6 info start myapp@0.0.0 +7 verbose unsafe-perm in lifecycle true +8 info myapp@0.0.0 Failed to exec start script +9 verbose stack Error: myapp@0.0.0 start: `node ./bin/www` +9 verbose stack Exit status 1 +9 verbose stack at EventEmitter. (C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16) +9 verbose stack at EventEmitter.emit (events.js:110:17) +9 verbose stack at ChildProcess. (C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\spawn.js:24:14) +9 verbose stack at ChildProcess.emit (events.js:110:17) +9 verbose stack at maybeClose (child_process.js:1015:16) +9 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5) +10 verbose pkgid myapp@0.0.0 +11 verbose cwd C:\Users\Mitchell\Desktop\mywebsite\mongoui +12 error Windows_NT 6.1.7601 +13 error argv "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" +14 error node v0.12.5 +15 error npm v2.11.2 +16 error code ELIFECYCLE +17 error myapp@0.0.0 start: `node ./bin/www` +17 error Exit status 1 +18 error Failed at the myapp@0.0.0 start script 'node ./bin/www'. +18 error This is most likely a problem with the myapp package, +18 error not with npm itself. +18 error Tell the author that this fails on your system: +18 error node ./bin/www +18 error You can get their info via: +18 error npm owner ls myapp +18 error There is likely additional logging output above. +19 verbose exit [ 1, true ] diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..807d49b --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,37 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'C:\\Program Files (x86)\\nodejs\\\\node.exe', +1 verbose cli 'C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', +1 verbose cli 'start' ] +2 info using npm@2.11.2 +3 info using node@v0.12.5 +4 verbose run-script [ 'prestart', 'start', 'poststart' ] +5 info prestart myapp@0.0.0 +6 info start myapp@0.0.0 +7 verbose unsafe-perm in lifecycle true +8 info myapp@0.0.0 Failed to exec start script +9 verbose stack Error: myapp@0.0.0 start: `node ./bin/www` +9 verbose stack Exit status 1 +9 verbose stack at EventEmitter. (C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16) +9 verbose stack at EventEmitter.emit (events.js:110:17) +9 verbose stack at ChildProcess. (C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\spawn.js:24:14) +9 verbose stack at ChildProcess.emit (events.js:110:17) +9 verbose stack at maybeClose (child_process.js:1015:16) +9 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5) +10 verbose pkgid myapp@0.0.0 +11 verbose cwd C:\Users\Mitchell\Desktop\mywebsite +12 error Windows_NT 6.1.7601 +13 error argv "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" +14 error node v0.12.5 +15 error npm v2.11.2 +16 error code ELIFECYCLE +17 error myapp@0.0.0 start: `node ./bin/www` +17 error Exit status 1 +18 error Failed at the myapp@0.0.0 start script 'node ./bin/www'. +18 error This is most likely a problem with the myapp package, +18 error not with npm itself. +18 error Tell the author that this fails on your system: +18 error node ./bin/www +18 error You can get their info via: +18 error npm owner ls myapp +18 error There is likely additional logging output above. +19 verbose exit [ 1, true ] diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 0b66560..fa7e11f 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -210,4 +210,16 @@ a { } .blog-footer p:last-child { margin-bottom: 0; +} + + +.lowerLeft{ + display: table-cell; + vertical-align: bottom; + height: 400px; + width: 300px; +} + +.colorWhite{ + color: white; } \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 9a9e97f..edf5ad0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,21 +1,19 @@ var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); + require('../models/currentdata'); var info = mongoose.model('currentdata'); +require("../models/temperature"); +var temperature = mongoose.model("temperature"); + /* GET home page. */ router.get('/', function(req, res, next) { - var post = req.query.blogpost; - if (post != 'undefined'){ - post = 'blogposts/' + post; - } - else { - post = 'blogposts/frontpage'; - } - res.render('index', {content : post}); + renderIndex(res,{test: 1234}); + }); router.post('/', function(req, res,next) { @@ -61,8 +59,9 @@ router.post('/', function(req, res,next) { } if (validInputs == false){ - res.render('index', invalid); + renderIndex(res, invalid); } + else { number = number.replace("-", ""); number = number.replace("-", ""); @@ -153,4 +152,16 @@ function timeValidator(time){ //var re = /^\d{1,2}\:\d{2}am$|^\d{1,2}\:\d{2}pm$/; var re = /^[0-9]\:[0-5][0-9]am$|^[0-9]\:[0-5][0-9]pm$|^1[0-2]\:[0-5][0-9]am$|^1[0-2]\:[0-5][0-9]pm$/; return re.test(time); +} + + +function renderIndex(res, json){ + + temperature.findOne().sort('-updated').exec(function(err,query) { + console.log(query); + + console.log(query.temperature); + res.render('index',{validation : json, query : query}); + }); + } \ No newline at end of file diff --git a/routes/temperature.js b/routes/temperature.js new file mode 100644 index 0000000..b7152dd --- /dev/null +++ b/routes/temperature.js @@ -0,0 +1,42 @@ +var express = require('express'); +var router = express.Router(); +var mongoose = require('mongoose'); +require('../models/temperature'); +var info = mongoose.model('temperature'); + +/* GET home page. */ +router.post('/', function(req, res, next) { + var temperature = req.body.temperature; + var humidity = req.body.humidity; + var location = req.body.location; + var key = req.body.key; + + if(key == "esp1234"){ + + + var insert = new info({ + temperature: temperature, + humidity: humidity, + location: location + }); + + insert.save(function (err) { + if (err) return handleError(err); + + }); + + + res.send("Information Logged"); + + } + + else{ + + res.send("Invalid Authentication"); + } + + + +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/users.js b/routes/users.js deleted file mode 100644 index 623e430..0000000 --- a/routes/users.js +++ /dev/null @@ -1,9 +0,0 @@ -var express = require('express'); -var router = express.Router(); - -/* GET users listing. */ -router.get('/', function(req, res, next) { - res.send('respond with a resource'); -}); - -module.exports = router; diff --git a/views/index.ejs b/views/index.ejs index 3f72d56..8c8237b 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -3,7 +3,20 @@
-
+ +
+
+ ESP8266 With DHT11 Sensor +
+ Location: <%=query.location%> +
+ Temperature: <%=query.temperature%>°F +
+ Humidity: <%=query.humidity%>% +
+
+ +
@@ -12,6 +25,7 @@

mitchellG.me

A "blog" about computer related projects that I find interesting.

+
@@ -53,8 +67,8 @@