From dcb01752869456fecbee0ec0a5a0dcb8d3c39a4b Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Sun, 25 Dec 2016 21:38:27 +0800
Subject: [PATCH] bugfix
---
method.js | 83 ++++++++++++++++++++++++++++++++---------
1 files changed, 65 insertions(+), 18 deletions(-)
diff --git a/method.js b/method.js
index 6590e33..a215c48 100644
--- a/method.js
+++ b/method.js
@@ -167,15 +167,29 @@
var ddv = this.toDec(fields[62]) * 256 + this.toDec(fields[63]);
var mcu = this.toDec(fields[64]) + this.toDec(fields[65]) / 100;
+ var _config = global.configs[mac];
+ if(_config == null) {
+ _config = {
+ address: "���������������������������������",
+ location: {���
+ lat:31.430616,
+ lng:120.988327���
+ },
+ notice: {
+ tel: "15950198162",���
+ email: "it01@moral.org.cn",���
+ open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU"
+ }
+ }
+ }
+
var current = moment();
- queue.pushToScreen({
+ queue.pushToMQ('ex_data_screen', {
mac: mac,
- location: {
- lat: 31.430616,
- lng: 120.988327
- },
+ location: _config.location,
data: {
+ x0: ferval,
x1: x1, //PM2.5 - (������:ppm)
x2: x3, //PM2.5 - 0.1���0.3um���
x3: x9, //������
@@ -186,15 +200,19 @@
time: current.valueOf()
});
- if(x1 >= 500) {
- queue.pushToAlarm({
+ if(x1 > 250) {
+ var level = 1;
+ if(x1 > 750) {
+ level = 3;
+ } else if(x1 > 500) {
+ level = 2;
+ }
+ queue.pushToMQ('ex_data_alarm', {
mac: mac,
- address: "���������������������������������",
- location: {
- lat:31.430616,
- lng:120.988327
- },
+ address: _config.address,
+ location: _config.location,
data:{
+ x0: ferval,
x1: x1, //PM2.5
x2: x3, //PM2.5
x3: x9, //������
@@ -202,12 +220,8 @@
x5: x10, //������
x6: x14 //������������
},
- level: 1,
- notice: {
- tel: "15950198162",
- email: "it01@moral.org.cn",
- open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU"
- },
+ level: level,
+ notice: _config.notice,
time: moment.valueOf()
});
}
@@ -335,6 +349,39 @@
}
};
+module.exports.initConfigs = function(db) {
+ db.collection("devices").find().toArray(function(err, docs) {
+ docs.forEach(function(doc) {
+ var mac = doc.mac;
+ var address = doc.address;
+ var location = doc.location;
+ var notice = doc.notice;
+ if(notice == null) {
+ var userID = doc.userID;
+ db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
+ if(user) {
+ global.configs[mac] = {
+ address: address,
+ location: location,
+ notice: {
+ tel: user.username,
+ email: user.email,
+ open_id: user.open_id
+ }
+ }
+ }
+ });
+ } else {
+ global.configs[mac] = {
+ address: address,
+ location: location,
+ notice: notice
+ }
+ }
+ });
+ });
+};
+
/////////////////////////////////////////////////
module.exports.insertDocument2 = function(db, data, rank, callback) {
var fields = data.match(/.{2}/g);
--
Gitblit v1.8.0