Skip to content

Commit

Permalink
web view
Browse files Browse the repository at this point in the history
  • Loading branch information
superchenney committed Aug 19, 2015
1 parent 858c792 commit 0ac8788
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 45 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,53 @@ ngrok -config ngrok.cfg -subdomain 481b4659.ngrok.com 3000
26 53 52 53 00 00 00 00 00 00 00 00 00 00 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2A、
//离家模式(关继电器1,2,步进逆)
26 53 52 53 00 00 00 00 00 00 00 00 00 00 5A 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2A




// var item = <%= item %>;
// console.log(item);

var title = <%= title%>
console.log(title);

var wsddata = [];
var wendu = [];
var shidu = [];

var wsddata = ['1号','2号','3号','4号','5号','6号','7号'];
var wendu = [23, 24, 30, 33, 25, 26.5, 30.6];
var shidu = [43, 59, 90, 26, 28, 70, 76];
for(var i=0; i<15;i++) {
wsddata[i] = item[i].date.toLocaleString();
wendu[i] = Number(item[i].temperature);
shidu[i] = Number(item[i].humidity);
}
console.log(wsddata);
console.log(wendu);
console.log(shidu);



// var wendu[i] = '<%=item[i].temperature%>'
// var shidu[i] = '<%=item[i].humidity%>'













var wsddata = [];


<% for(var i = 0; i < 10 ;i++) {%>
<% wsddata[i]= item[i].date.toLocaleString() %>
<% } %>
console.log(wsddata);
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ app.use(session({

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine("html",require("ejs").__express); // or app.engine("html",require("ejs").renderFile);
app.engine("html",require("ejs").__express); // or
// app.engine("html",require("ejs").renderFile);
//app.set("view engine","ejs");
app.set('view engine', 'html');

Expand Down
8 changes: 4 additions & 4 deletions database/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ module.exports = {
default:Date.now()
},
temperature:{
type:String
type:Number
},
humidity:{
type:String
type:Number
},
}, //温湿度

guangZhao:{
guangzhao:{
date:{
type:Date,
default:Date.now()
},
illumination:{
type:Number
type:String
},
}

Expand Down
56 changes: 40 additions & 16 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ function saveWSInfo(wendu,shidu){
temperature: wendu,
humidity:shidu
});
console.log('\n' + '***** 温湿度数据采集保存 ******');
var dates = new Date();
console.log('\n' + '***** '+ dates.toLocaleTimeString() +'温湿度数据采集保存 ******' +'\n');
}

function saveGZInfo(guangzhao){
var GuangZhao = global.dbHandel.getModel('guangzhao');
GuangZhao.create({
date: Date.now(),
illumination: guangzhao
});
var dates = new Date();
console.log('\n' + '***** '+ dates.toLocaleTimeString() +'光照数据采集保存 ******' +'\n');
}


Expand All @@ -64,25 +75,26 @@ clientPro.on('data', function(data) {
console.log('收到数据: ' + recivedata);

if(recivedata[0]=='W'){

var wendu = recivedata.substring(6,9);
var shidu = recivedata.substring(12,15);
saveWSInfo(wendu,shidu);
console.log('温度数据为: ' + wendu);
console.log('湿度数据为: ' + shidu);
var wendu = recivedata.substring(6,8);
var shidu = recivedata.substring(12,14);
saveWSInfo(wendu,shidu);
console.log('温度数据为: ' + wendu);
console.log('湿度数据为: ' + shidu);
}


// 完全关闭连接
// clientPro.destroy();
});

// 为客户端添加“close”事件处理函数
clientPro.on('close', function() {
console.log('Connection closed');
console.log('Socket Connection closed');
});

//错误回调
clientPro.on('error', function (exception) {
console.log('socket error:' + exception);
console.log('Socket error:' + exception);
clientPro.end();
});

Expand Down Expand Up @@ -130,8 +142,9 @@ router.route("/login").get(function(req,res){ // 到达此路径则渲染logi
// res.redirect("/login");
}else{ //信息匹配成功,则将此对象(匹配到的user) 赋给session.user 并返回成功
req.session.user = doc;
res.send(200);
// res.redirect("/home");
res.sendStatus(200);
// res.send(200);
// res.redirect("/home");
}
}
});
Expand Down Expand Up @@ -196,13 +209,13 @@ router.get("/home",function(req,res){
});
router.route('/shenghuo').post(function(req,res){
clientPro.write(shenghuo);
saveInfo(req,'系统','生活');
saveInfo(req,'系统','生活模式');
console.log('\n' + '***** ' + req.session.user.name + '生活 ******' + '\n');
res.status(200).send("生活ok"); //AJAX请求返回成功
});
router.route('/xiuxi').post(function(req,res){
clientPro.write(shenghuo);
saveInfo(req,'系统','休息');
saveInfo(req,'系统','休息模式');
console.log('\n' + '***** ' + req.session.user.name + '休息 ******' + '\n');
res.status(200).send("休息ok"); //AJAX请求返回成功
});
Expand Down Expand Up @@ -251,12 +264,23 @@ router.route('/guandeng').post(function(req,res){


router.get('/wenshidu', function(req, res) {
res.render('wenshidu', { title: "温湿度" }); // 到达此路径则渲染index文件,并传出title值供 index.html使用
});
var Wenshidu = global.dbHandel.getModel('wenshidu');
Wenshidu.find({}).sort('-date').exec(function(err,doc){
if(err){
console.log(err);
}else{
console.log('记录 item : ' + doc);
res.render('wenshidu', { title: "温湿度数据返回", item: doc });
}; //else
}); //Wenshidu
})





router.get('/guangzhao', function(req, res) {
res.render('guangzhao', { title: '光照' }); // 到达此路径则渲染index文件,并传出title值供 index.html使用
res.render('guangzhao', { title: '光照' });
});


Expand Down
4 changes: 2 additions & 2 deletions views/guangzhao.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ <h1>230 Lux</h1>

<script type="text/javascript">
$(function(){
var gzDate = ['01时','02时','03时','04时','05时','06时','07时','08时','09时','10时','11时','12时','13时','14时','15时','16时','17时','18时'];
var gzData = [11, 11, 15, 13, 12, 13, 10,11, 11, 15, 13, 12, 13, 10,11, 11, 15, 13];
var gzDate = ['10:11','10:12','10:13','10:14','10:15','10:16','10:17','10:18','10:19','10:20','10:21','10:22','10:23','10:24','10:25','10:26','10:27','10:28'];
var gzData = [101, 101, 150, 130, 120, 130, 100,110, 110, 150, 130, 120, 130, 100,110, 110, 150, 130];


// 路径配置
Expand Down
8 changes: 2 additions & 6 deletions views/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ <h1 class="am-header-title">
<td><%=item[i].operate%></td>
<td><%=item[i].username%></td>
<td><%=item[i].date.toLocaleString()%></td>
<!-- <td><%=item[i].date.toDateString()%></td> -->
<!-- <td>客厅</td>
<td>关窗</td>
<td >chenney</td>
<td>2012-10-01</td> -->
<% } %>
</tr>
</tbody>
Expand Down Expand Up @@ -117,7 +112,8 @@ <h1 class="am-header-title">
<script type="text/javascript" src="javascripts/openlink.js"></script>

<script>
var item = {};
// var item = {};
// console.log(item);
</script>
</body>
</html>
33 changes: 17 additions & 16 deletions views/wenshidu.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
</div></div></div>
<div class="inspired">
<p>温度</p>
<h1>23 &#8451</h1>
<h1><%=item[0].temperature%> &#8451</h1>
</div>


Expand Down Expand Up @@ -244,7 +244,7 @@ <h1>23 &#8451</h1>
<script src="javascripts/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
<!-- <script src="/javascripts/jquery.min.js"></script> -->
<script src="/javascripts/jquery.min.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!--<![endif]-->
<!-- <script src="/javascripts/amazeui.min.js"></script> -->
Expand All @@ -257,22 +257,28 @@ <h1>23 &#8451</h1>
<!-- ECharts单文件引入 -->
<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>

<script type="text/javascript">
$(function(){
<script>
// $(function(){
var title = '<%=title%>';
console.log(title);


var wsddate = ['1号','2号','3号','4号','5号','6号','7号'];


var wsddata = ['9:15:24','9:16','9:17','9:18','9:19','9:20','9:21'];
var wendu = [23, 24, 30, 33, 25, 26.5, 30.6];
var shidu = [43, 59, 90, 26, 28, 70, 76];



// 路径配置
require.config({
paths: {
echarts: 'http://echarts.baidu.com/build/dist'
}
});



// 使用
require(
[
Expand All @@ -281,11 +287,12 @@ <h1>23 &#8451</h1>
],
function (ec) {
// 基于准备好的dom,初始化echarts图表

var myChart = ec.init(document.getElementById('main'));
var option = {
title : {
// text: '温湿度情况',
subtext: '最近一周'
subtext: '最近10条记录'
},
tooltip : {
trigger: 'axis'
Expand All @@ -301,7 +308,7 @@ <h1>23 &#8451</h1>
{
type : 'category',
// data : ['1号','2号','3号','4号','5号','6号','7号']
data : wsddate
data : wsddata
}
],
yAxis : [
Expand Down Expand Up @@ -332,12 +339,6 @@ <h1>23 &#8451</h1>
type:'bar',
// data:[43, 59, 90, 26, 28, 70, 76],
data: shidu,
// markPoint : {
// data : [
// {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183, symbolSize:18},
// {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
// ]
// },
markPoint : {
data : [
{type : 'max', name: '最大值'},
Expand All @@ -350,14 +351,14 @@ <h1>23 &#8451</h1>
]
}
}
]
] //series
};
// 为echarts对象加载数据
myChart.setOption(option);
}
);

});
// });
</script>


Expand Down
Binary file added 效果图/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/app1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/app2
Binary file not shown.
Binary file added 效果图/guangzhao.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 效果图/home3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed 效果图/wenshidu.gif
Binary file not shown.
Binary file added 效果图/wenshidu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ac8788

Please sign in to comment.