Commit a328920c by zCaesar

add broker count and fixed onoff

parent daabfd9d
......@@ -106,7 +106,7 @@ module.exports = function (options = {}) {
cache.set(cachekey, result);
console.log(client_id)
console.log(client_id.indexOf('-'))
if (client_id.indexOf('mqttjs_') !== -1) {
if (client_id.indexOf('mqttjs') !== -1) {
res.send({
"result": result ? "ok" : "no"
});
......@@ -124,7 +124,7 @@ module.exports = function (options = {}) {
});
}
else {
if (client_id.indexOf('mqttjs_') !== -1) {
if (client_id.indexOf('mqttjs') !== -1) {
res.send({
"result": authstatus ? "ok" : "no"
});
......
......@@ -7,7 +7,7 @@ module.exports = function(options = {}) {
}
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 => {
console.log('redis:status: ' + status)
})
......
......@@ -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, 'charged_message_count', information.charged_message_count)
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) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
......@@ -32,3 +37,10 @@ function setValue(deviceid, payload) {
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()
function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => {
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) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
......@@ -22,3 +23,10 @@ function setValue(deviceid) {
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_
return new Promise((resolve, reject) => {
var information = setValue(deviceid)
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) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
......@@ -25,3 +26,10 @@ function setValue(deviceid) {
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