| | |
| | | |
| | | var current = moment(); |
| | | |
| | | queue.pushToScreen({ |
| | | queue.pushToMQ('ex_data_screen', { |
| | | mac: mac, |
| | | location: { |
| | | lat: 31.430616, |
| | | lng: 120.988327 |
| | | }, |
| | | data: { |
| | | x0: ferval, |
| | | x1: x1, //PM2.5 - (单位:ppm) |
| | | x2: x3, //PM2.5 - 0.1升0.3um量 |
| | | x3: x9, //甲醛 |
| | |
| | | time: current.valueOf() |
| | | }); |
| | | |
| | | if(x1 >= 500) { |
| | | queue.pushToAlarm({ |
| | | if(x1 > 250) { |
| | | var level = 1; |
| | | if(x1 > 500) { |
| | | level = 2; |
| | | } else if(x1 > 750) { |
| | | level = 3; |
| | | } |
| | | queue.pushToMQ('ex_data_alarm', { |
| | | mac: mac, |
| | | address: "江苏省昆山市摩瑞尔电器", |
| | | location: { |
| | |
| | | lng:120.988327 |
| | | }, |
| | | data:{ |
| | | x0: ferval, |
| | | x1: x1, //PM2.5 |
| | | x2: x3, //PM2.5 |
| | | x3: x9, //甲醛 |
| | |
| | | x5: x10, //湿度 |
| | | x6: x14 //光照强度 |
| | | }, |
| | | level: 1, |
| | | level: level, |
| | | notice: { |
| | | tel: "15950198162", |
| | | email: "it01@moral.org.cn", |
| | |
| | | }); |
| | | }; |
| | | |
| | | module.exports.pushToScreen = function(data) { |
| | | module.exports.pushToMQ = function(ex, data) { |
| | | amqp.connect(uri, function(err, conn) { |
| | | conn.createChannel(function(err, ch) { |
| | | var _ex = 'ex_data_screen'; |
| | | ch.assertExchange(_ex, 'fanout', { durable: false }); |
| | | ch.publish(_ex, '', new Buffer(JSON.stringify(data))); |
| | | }); |
| | | setTimeout(function() { |
| | | 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))); |
| | | ch.assertExchange(ex, 'fanout', { durable: false }); |
| | | ch.publish(ex, '', new Buffer(JSON.stringify(data))); |
| | | }); |
| | | setTimeout(function() { |
| | | conn.close(); |