沈斌
2016-12-23 e4f5a1dbc596492c8181234f00ef45b875ebc07f
服务端判断pm2.5>500发送警报指令
2 files modified
39 ■■■■■ changed files
method.js 26 ●●●●● patch | view | raw | blame | history
queue.js 13 ●●●●● patch | view | raw | blame | history
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);
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);
    });
};