Commit af9c7f40 by zCaesar

fix status

parent 276abdc1
...@@ -107,10 +107,15 @@ module.exports = function (options = {}) { ...@@ -107,10 +107,15 @@ module.exports = function (options = {}) {
if (result) { if (result) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => { require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status) console.log('redis:status: ' + status)
require('./redis/on_register').deviceUsageCount() if (status) {
res.send({ res.send({
"result": status ? "ok" : "no" "result": "ok"
}); });
} else {
res.send({
"result": "no"
});
}
}) })
} else { } else {
res.send({ res.send({
...@@ -125,10 +130,15 @@ module.exports = function (options = {}) { ...@@ -125,10 +130,15 @@ module.exports = function (options = {}) {
if (authstatus) { if (authstatus) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => { require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status) console.log('redis:status: ' + status)
require('./redis/on_register').deviceUsageCount() if (status) {
res.send({ res.send({
"result": status ? "ok" : "no" "result": "ok"
}); });
} else {
res.send({
"result": "no"
});
}
}) })
} else { } else {
res.send({ res.send({
......
module.exports = function(options = {}) { module.exports = function (options = {}) {
debug = options.debug || false; debug = options.debug || false;
...@@ -10,7 +10,6 @@ module.exports = function(options = {}) { ...@@ -10,7 +10,6 @@ module.exports = function(options = {}) {
function doRedis(client_id) { function doRedis(client_id) {
if (client_id.indexOf('mqttjs') === -1) { if (client_id.indexOf('mqttjs') === -1) {
require('./redis/on_offline').on_offline_redis(client_id).then(status => { require('./redis/on_offline').on_offline_redis(client_id).then(status => {
require('./redis/on_offline').deviceUsageCount()
console.log('redis:status: ' + status) console.log('redis:status: ' + status)
}) })
} }
......
...@@ -9,7 +9,11 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o ...@@ -9,7 +9,11 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
else { else {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hset(information.keys, 'status', information.status, 'offline_on', information.offline_on, function (err, res) { redis.hset(information.keys, 'status', information.status, 'offline_on', information.offline_on, function (err, res) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1 console.log(res)
if (res) {
deviceUsageCount()
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
} else resolve(!res)
}) })
} }
}) })
...@@ -31,5 +35,4 @@ function setValue(deviceid) { ...@@ -31,5 +35,4 @@ function setValue(deviceid) {
function deviceUsageCount() { function deviceUsageCount() {
console.log('device_usage_offline') console.log('device_usage_offline')
redis.hincrby('_broker:1', 'device_online', -1) redis.hincrby('_broker:1', 'device_online', -1)
} }
module.exports.deviceUsageCount = deviceUsageCount \ No newline at end of file
\ No newline at end of file
...@@ -10,7 +10,10 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_ ...@@ -10,7 +10,10 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hdel(information.keys, 'offline_on') redis.hdel(information.keys, 'offline_on')
redis.hset(information.keys, 'status', information.status, 'register_on', information.register_on, 'last_check', information.last_check, function (err, res) { redis.hset(information.keys, 'status', information.status, 'register_on', information.register_on, 'last_check', information.last_check, function (err, res) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1 if (!res) {
deviceUsageCount()
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
} else resolve(!res)
}) })
} }
}) })
...@@ -34,5 +37,4 @@ function setValue(deviceid) { ...@@ -34,5 +37,4 @@ function setValue(deviceid) {
function deviceUsageCount() { function deviceUsageCount() {
console.log('device_usage_online') console.log('device_usage_online')
redis.hincrby('_broker:1', 'device_online', 1) redis.hincrby('_broker:1', 'device_online', 1)
} }
module.exports.deviceUsageCount = deviceUsageCount \ No newline at end of file
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment