A question here,
Gateway(mikrotik) and sensor(rak7200) side by side.
When trying to get some data via node.js…(see code)
const mqtt = require("mqtt");
const Datastore = require("nedb");
const db = new Datastore({ filename: "./tracker.db", autoload: true });
const opts = {
auth: {
username: "AAAAAA",
password: "ttn-account-v2.BBBBBB",
clean: true,
port: 1883,
},
topic: "CCCCCC/devices/DDDDDD/up",
host: "mqtt://eu.thethings.network",
};
const client = mqtt.connect(opts.host, opts.auth);
client.on("connect", () => {
client.subscribe(opts.topic);
});
client.on("message", (topic, msg) => {
const stringBuf = msg && msg.toString("utf-8");
const jsonMsg = JSON.parse(stringBuf);
db.insert(jsonMsg, (err, doc) => {
if (err) console.log("error: " + err);
else console.log(`inserted [${doc.dev_id}] with counter [${doc.counter}.${doc.confirmed?"confirmed":"unconfirmed"}] `)
});
//console.log(jsonMsg);
});
everything is working properly, however I got plenty of entrys with same counter number!
The application was created asking for confirmation!
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1662.confirmed]
inserted [tracker01] with counter [1663.confirmed]
inserted [tracker01] with counter [1663.confirmed]
inserted [tracker01] with counter [1663.confirmed]
inserted [tracker01] with counter [1663.confirmed]
inserted [tracker01] with counter [1663.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1664.confirmed]
inserted [tracker01] with counter [1665.confirmed]
inserted [tracker01] with counter [1665.confirmed]
inserted [tracker01] with counter [1665.confirmed]
inserted [tracker01] with counter [1665.confirmed]
inserted [tracker01] with counter [1665.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
inserted [tracker01] with counter [1666.confirmed]
its supposed to be like this?
I need to keep (db write) only one of those (with the same counter)?
Anyway to minimize those connections?
regards,
full package example (using default RAK7200 decoder)
{
app_id: 'test_gps_tracXXXX',
dev_id: 'trackXXX',
hardware_serial: 'AC1F09FFFXXXXXX',
port: 8,
counter: 1650,
confirmed: true,
payload_raw: 'CAIBeANxAAgAGAO2BYYAPABl/7CgXXXXXXXXXXX=',
payload_fields: {
acceleration_x: '0.008g',
acceleration_y: '0.024g',
acceleration_z: '0.95g',
battery: '3.76V',
gyroscope_x: '0.6°/s',
gyroscope_y: '1.01°/s',
gyroscope_z: '-0.67°/s',
magnetometer_x: '43.5μT',
magnetometer_y: '66.75μT',
magnetometer_z: '-9.3μT'
},
metadata: {
time: '2020-10-20T17:32:29.276946973Z',
frequency: 918.2,
modulation: 'LORA',
data_rate: 'SF7BW125',
airtime: 97536000,
coding_rate: '4/5',
gateways: [ [Object] ]
}
}