58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
// Test script to capture nodeinfo messages
|
|
const mqtt = require('mqtt');
|
|
|
|
const client = mqtt.connect('mqtt://mqtt.meshtastic.org', {
|
|
username: 'meshdev',
|
|
password: 'large4cats',
|
|
clientId: `test-${Math.random().toString(16).substr(2, 8)}`
|
|
});
|
|
|
|
client.on('connect', () => {
|
|
console.log('Connected! Subscribing to JSON topics...');
|
|
client.subscribe('msh/US/+/2/json/#', (err) => {
|
|
if (err) {
|
|
console.error('Subscribe error:', err);
|
|
} else {
|
|
console.log('Subscribed! Waiting for nodeinfo messages...\n');
|
|
}
|
|
});
|
|
});
|
|
|
|
let nodeinfoCount = 0;
|
|
const seenTypes = new Set();
|
|
|
|
client.on('message', (topic, message) => {
|
|
try {
|
|
const data = JSON.parse(message.toString());
|
|
|
|
if (!seenTypes.has(data.type)) {
|
|
seenTypes.add(data.type);
|
|
console.log(`\n=== New Message Type: ${data.type} ===`);
|
|
console.log(`Topic: ${topic}`);
|
|
console.log(`Data:`, JSON.stringify(data, null, 2));
|
|
console.log('\n');
|
|
}
|
|
|
|
if (data.type === 'nodeinfo' && nodeinfoCount < 3) {
|
|
nodeinfoCount++;
|
|
console.log(`\n=== NodeInfo Message #${nodeinfoCount} ===`);
|
|
console.log(`Topic: ${topic}`);
|
|
console.log(`Data:`, JSON.stringify(data, null, 2));
|
|
console.log('\n');
|
|
}
|
|
|
|
if (nodeinfoCount >= 3 && seenTypes.size >= 5) {
|
|
console.log('Captured enough samples, exiting...');
|
|
client.end();
|
|
process.exit(0);
|
|
}
|
|
} catch (e) {
|
|
// Not JSON, skip
|
|
}
|
|
});
|
|
|
|
setTimeout(() => {
|
|
console.log('Timeout - captured types:', Array.from(seenTypes));
|
|
process.exit(1);
|
|
}, 60000);
|