Commit fd970823 by zCaesar

add device usage count

parent 72c065c7
...@@ -124,6 +124,7 @@ module.exports = function (options = {}) { ...@@ -124,6 +124,7 @@ 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()
res.send({ res.send({
"result": status ? "ok" : "no" "result": status ? "ok" : "no"
}); });
......
...@@ -9,6 +9,7 @@ module.exports = function(options = {}) { ...@@ -9,6 +9,7 @@ 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)
}) })
} }
......
...@@ -8,7 +8,6 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o ...@@ -8,7 +8,6 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
} }
else { else {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hincrby('_broker:1', 'count', -1)
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 resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
}) })
...@@ -27,4 +26,9 @@ function setValue(deviceid) { ...@@ -27,4 +26,9 @@ function setValue(deviceid) {
status: status, status: status,
offline_on: offline_on offline_on: offline_on
} }
} }
\ No newline at end of file
function deviceUsageCount() {
redis.hincrby('_broker:1', 'device_usage', -1)
}
module.exports.deviceUsageCount = deviceUsageCount
\ No newline at end of file
...@@ -9,7 +9,6 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_ ...@@ -9,7 +9,6 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
else { else {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hdel(information.keys, 'offline_on') redis.hdel(information.keys, 'offline_on')
redis.hincrby('_broker:1', 'count', 1)
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 resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
}) })
...@@ -30,4 +29,9 @@ function setValue(deviceid) { ...@@ -30,4 +29,9 @@ function setValue(deviceid) {
register_on: register_on, register_on: register_on,
last_check: last_check last_check: last_check
} }
} }
\ No newline at end of file
function deviceUsageCount() {
redis.hincrby('_broker:1', 'device_usage', 1)
}
module.exports.deviceUsageCount = deviceUsageCount
\ 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