Commit fd970823 by zCaesar

add device usage count

parent 72c065c7
......@@ -124,6 +124,7 @@ module.exports = function (options = {}) {
if (authstatus) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
require('./redis/on_register').deviceUsageCount()
res.send({
"result": status ? "ok" : "no"
});
......
......@@ -9,6 +9,7 @@ module.exports = function(options = {}) {
function doRedis(client_id) {
if (client_id.indexOf('mqttjs') === -1) {
require('./redis/on_offline').on_offline_redis(client_id).then(status => {
require('./redis/on_offline').deviceUsageCount()
console.log('redis:status: ' + status)
})
}
......
......@@ -8,7 +8,6 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
else {
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) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
......@@ -28,3 +27,8 @@ function setValue(deviceid) {
offline_on: offline_on
}
}
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_
else {
var information = setValue(deviceid)
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) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
......@@ -31,3 +30,8 @@ function setValue(deviceid) {
last_check: last_check
}
}
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