Tidy up logging
This commit is contained in:
parent
1ee184d82d
commit
8d822c33c0
4 changed files with 21 additions and 11 deletions
|
@ -17,9 +17,10 @@ class RSSIRepo {
|
||||||
:rssi, :snr,
|
:rssi, :snr,
|
||||||
:channel
|
:channel
|
||||||
)`);
|
)`);
|
||||||
|
for(let rssi of rssis) {
|
||||||
for(let rssi of rssis)
|
// console.log(`Storing`, rssi);
|
||||||
statement.run(rssi);
|
statement.run(rssi);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iterate() {
|
iterate() {
|
||||||
|
|
|
@ -52,3 +52,7 @@ devices = [
|
||||||
# The format the date displayed when logging things should take.
|
# The format the date displayed when logging things should take.
|
||||||
# Allowed values: relative (e.g like when a Linux machine boots), absolute (e.g. like Nginx server logs)
|
# Allowed values: relative (e.g like when a Linux machine boots), absolute (e.g. like Nginx server logs)
|
||||||
date_display_mode = "relative"
|
date_display_mode = "relative"
|
||||||
|
|
||||||
|
# Whether we should be verbose and log a bunch of stuff to the console.
|
||||||
|
# Disabled by default, but useful for debugging.
|
||||||
|
verbose = false
|
||||||
|
|
|
@ -4,19 +4,24 @@ import { decode_payload } from './DecodePayload.mjs';
|
||||||
import { get_id_number } from '../Helpers/IdGenerator.mjs';
|
import { get_id_number } from '../Helpers/IdGenerator.mjs';
|
||||||
|
|
||||||
class MessageHandler {
|
class MessageHandler {
|
||||||
constructor({ ReadingRepo, GatewayRepo }) {
|
get debug() {
|
||||||
|
return this.settings.logging.debug;
|
||||||
|
}
|
||||||
|
constructor({ settings, ReadingRepo, GatewayRepo }) {
|
||||||
|
this.settings = settings;
|
||||||
this.repo_reading = ReadingRepo;
|
this.repo_reading = ReadingRepo;
|
||||||
this.repo_gateway = GatewayRepo;
|
this.repo_gateway = GatewayRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handle(message) {
|
async handle(message) {
|
||||||
console.log(message);
|
if(this.debug) console.log(message);
|
||||||
|
|
||||||
let decoded_payload = decode_payload(message.payload_raw);
|
let decoded_payload = decode_payload(message.payload_raw);
|
||||||
console.log(decoded_payload);
|
if(this.debug) console.log(decoded_payload);
|
||||||
|
|
||||||
let rssis = [];
|
let rssis = [];
|
||||||
for(let gw in message.metadata.gateways) {
|
for(let gw of message.metadata.gateways) {
|
||||||
|
if(this.debug) console.log("gateway ", gw);
|
||||||
// Insert the gateway info into the database if it doesn't exist already
|
// Insert the gateway info into the database if it doesn't exist already
|
||||||
if(!this.repo_gateway.exists(gw.gtw_id)) {
|
if(!this.repo_gateway.exists(gw.gtw_id)) {
|
||||||
this.repo_gateway.add({
|
this.repo_gateway.add({
|
||||||
|
@ -28,8 +33,8 @@ class MessageHandler {
|
||||||
|
|
||||||
// Generate an RSSI object
|
// Generate an RSSI object
|
||||||
rssis.push({
|
rssis.push({
|
||||||
id: get_id_number,
|
id: await get_id_number(),
|
||||||
gateway_id: this.repo_gateway,
|
gateway_id: gw.gtw_id,
|
||||||
rssi: gw.rssi,
|
rssi: gw.rssi,
|
||||||
snr: gw.snr,
|
snr: gw.snr,
|
||||||
channel: gw.channel
|
channel: gw.channel
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TTNAppServer {
|
||||||
// 2: Connect
|
// 2: Connect
|
||||||
this.ttn_client = await this.connect();
|
this.ttn_client = await this.connect();
|
||||||
this.ttn_client.on("message", this.handle_message.bind(this));
|
this.ttn_client.on("message", this.handle_message.bind(this));
|
||||||
this.log.log(`Connected to ${this.connection_string}`);
|
this.log.log(`[mqtt] Connected to ${this.connection_string}`);
|
||||||
|
|
||||||
|
|
||||||
// 3: Subscribe
|
// 3: Subscribe
|
||||||
|
@ -42,7 +42,7 @@ class TTNAppServer {
|
||||||
(device_name) => `${this.settings.ttn.app_id}/devices/${device_name}/up`
|
(device_name) => `${this.settings.ttn.app_id}/devices/${device_name}/up`
|
||||||
));
|
));
|
||||||
|
|
||||||
this.log.log(`Subscribed to ${result.map((el) => el.topic).join(", ")}`);
|
this.log.log(`[mqtt] Subscribed to ${result.map((el) => el.topic).join(", ")}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
|
@ -65,7 +65,7 @@ class TTNAppServer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log.log(`[mqtt/handler] ${topic}: `, message_object);
|
this.log.log(`[mqtt/handler] Got message from ${topic}`);
|
||||||
await this.message_handler.handle(message_object);
|
await this.message_handler.handle(message_object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue