Commit a328920c by zCaesar

add broker count and fixed onoff

parent daabfd9d
...@@ -106,7 +106,7 @@ module.exports = function (options = {}) { ...@@ -106,7 +106,7 @@ module.exports = function (options = {}) {
cache.set(cachekey, result); cache.set(cachekey, result);
console.log(client_id) console.log(client_id)
console.log(client_id.indexOf('-')) console.log(client_id.indexOf('-'))
if (client_id.indexOf('mqttjs_') !== -1) { if (client_id.indexOf('mqttjs') !== -1) {
res.send({ res.send({
"result": result ? "ok" : "no" "result": result ? "ok" : "no"
}); });
...@@ -124,7 +124,7 @@ module.exports = function (options = {}) { ...@@ -124,7 +124,7 @@ module.exports = function (options = {}) {
}); });
} }
else { else {
if (client_id.indexOf('mqttjs_') !== -1) { if (client_id.indexOf('mqttjs') !== -1) {
res.send({ res.send({
"result": authstatus ? "ok" : "no" "result": authstatus ? "ok" : "no"
}); });
......
...@@ -7,7 +7,7 @@ module.exports = function(options = {}) { ...@@ -7,7 +7,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 => {
console.log('redis:status: ' + status) console.log('redis:status: ' + status)
}) })
......
...@@ -7,6 +7,11 @@ function on_message_redis(deviceid, payload) { // first time to access on authho ...@@ -7,6 +7,11 @@ function on_message_redis(deviceid, payload) { // first time to access on authho
redis.hincrby(information.keys, 'actual_message_count', 1) redis.hincrby(information.keys, 'actual_message_count', 1)
redis.hincrby(information.keys, 'charged_message_count', information.charged_message_count) redis.hincrby(information.keys, 'charged_message_count', information.charged_message_count)
redis.hincrby(information.keys, 'total_message_size', information.total_message_size) redis.hincrby(information.keys, 'total_message_size', information.total_message_size)
redis.hincrby(setBrokerValue().keys, 'actual_message_count', 1)
redis.hincrby(setBrokerValue().keys, 'charged_message_count', information.charged_message_count)
redis.hincrby(setBrokerValue().keys, 'total_message_size', information.total_message_size)
redis.hset(information.keys, 'last_publish', information.last_publish, function (err, res) { redis.hset(information.keys, 'last_publish', information.last_publish, 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
}) })
...@@ -31,4 +36,11 @@ function setValue(deviceid, payload) { ...@@ -31,4 +36,11 @@ function setValue(deviceid, payload) {
charged_message_count: charged_message_count, charged_message_count: charged_message_count,
total_message_size: total_message_size total_message_size: total_message_size
} }
}
function setBrokerValue() {
var keys = '_broker:1'
return {
keys: keys
}
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ var redis = new Redis() ...@@ -4,6 +4,7 @@ var redis = new Redis()
function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hincrby(setBrokerValue().keys, 'device_usage_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
}) })
...@@ -21,4 +22,11 @@ function setValue(deviceid) { ...@@ -21,4 +22,11 @@ function setValue(deviceid) {
status: status, status: status,
offline_on: offline_on offline_on: offline_on
} }
}
function setBrokerValue() {
var keys = '_broker:1'
return {
keys: keys
}
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_ ...@@ -5,6 +5,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hdel(information.keys, 'offline_on') redis.hdel(information.keys, 'offline_on')
redis.hincrby(setBrokerValue().keys, 'device_usage_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
}) })
...@@ -24,4 +25,11 @@ function setValue(deviceid) { ...@@ -24,4 +25,11 @@ function setValue(deviceid) {
register_on: register_on, register_on: register_on,
last_check: last_check last_check: last_check
} }
}
function setBrokerValue() {
var keys = '_broker:1'
return {
keys: keys
}
} }
\ 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