From e4f5a1dbc596492c8181234f00ef45b875ebc07f Mon Sep 17 00:00:00 2001 From: 沈斌 <bluelazysb@hotmail.com> Date: Fri, 23 Dec 2016 21:47:35 +0800 Subject: [PATCH] 服务端判断pm2.5>500发送警报指令 --- queue.js | 13 +++++++++++++ method.js | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/method.js b/method.js index a085477..6590e33 100644 --- a/method.js +++ b/method.js @@ -186,6 +186,32 @@ time: current.valueOf() }); + if(x1 >= 500) { + queue.pushToAlarm({ + mac: mac, + address: "���������������������������������", + location: { + lat:31.430616, + lng:120.988327 + }, + data:{ + x1: x1, //PM2.5 + x2: x3, //PM2.5 + x3: x9, //������ + x4: x11, //������ + x5: x10, //������ + x6: x14 //������������ + }, + level: 1, + notice: { + tel: "15950198162", + email: "it01@moral.org.cn", + open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU" + }, + time: moment.valueOf() + }); + } + var rank = 0; if(s > 0) { rank = this.random(1000, 99999);//this.random(1000, 99999999); diff --git a/queue.js b/queue.js index 9ebd5ab..b136fbb 100644 --- a/queue.js +++ b/queue.js @@ -33,4 +33,17 @@ conn.close(); }, 500); }); +}; + +module.exports.pushToAlarm = function(data) { + amqp.connect(uri, function(err, conn) { + conn.createChannel(function(err, ch) { + var _ex = 'ex_data_alarm'; + ch.assertExchange(_ex, 'fanout', { durable: false }); + ch.publish(_ex, '', new Buffer(JSON.stringify(data))); + }); + setTimeout(function() { + conn.close(); + }, 500); + }); }; \ No newline at end of file -- Gitblit v1.8.0