basic working
This commit is contained in:
@@ -26,6 +26,7 @@ module.exports = {
|
||||
username: process.env.MQTT_USERNAME || 'meshdev',
|
||||
password: process.env.MQTT_PASSWORD || 'large4cats',
|
||||
topic: process.env.MQTT_TOPIC || 'msh/US/#',
|
||||
pubTopic: process.env.MQTT_PUB_TOPIC || 'msh/US/2/json/mqtt/', // The ending / is apparently critical
|
||||
options: {
|
||||
clientId: `meshtastic-dashboard-${Math.random().toString(16).substr(2, 8)}`,
|
||||
clean: true,
|
||||
|
||||
+7
-9
@@ -88,8 +88,8 @@ class MeshtasticMQTTClient {
|
||||
try {
|
||||
const { from, to, channel, id, sender } = payload;
|
||||
|
||||
// Extract node ID (convert to hex string if it's a number)
|
||||
const fromNode = sender || (from ? `!${from.toString(16).padStart(8, '0')}` : null);
|
||||
// Extract node ID (convert to hex string if it's a number, fallback to sender if none
|
||||
const fromNode = from ? `!${from.toString(16).padStart(8, '0')}` : sender;
|
||||
const toNode = to ? `!${to.toString(16).padStart(8, '0')}` : null;
|
||||
|
||||
// Handle different message types based on actual JSON structure
|
||||
@@ -344,18 +344,16 @@ class MeshtasticMQTTClient {
|
||||
}
|
||||
|
||||
// Send a text message
|
||||
async sendTextMessage(text, channel = 0) {
|
||||
async sendTextMessage(from, text) {
|
||||
try {
|
||||
const message = JSON.stringify({
|
||||
type: 'text',
|
||||
text,
|
||||
channel,
|
||||
timestamp: Date.now()
|
||||
from: from,
|
||||
type: 'sendtext',
|
||||
payload: text
|
||||
});
|
||||
|
||||
// Publish to the appropriate topic
|
||||
const baseTopic = config.mqtt.topic.replace('/#', '');
|
||||
await this.publish(`${baseTopic}/2/json/mqtt`, message);
|
||||
await this.publish(config.mqtt.pubTopic, message);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
||||
+2
-2
@@ -169,13 +169,13 @@ router.get('/messages/node/:nodeId', requireAuth, (req, res) => {
|
||||
// Send a message
|
||||
router.post('/messages/send', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const { text, channel } = req.body;
|
||||
const { text, from } = req.body;
|
||||
|
||||
if (!text) {
|
||||
return res.status(400).json({ error: 'Message text required' });
|
||||
}
|
||||
|
||||
await mqttClient.sendTextMessage(text, channel || 0);
|
||||
await mqttClient.sendTextMessage(text, from || 0);
|
||||
|
||||
// Log activity
|
||||
logActivity(req.session.userId, 'send_message', text, req.ip);
|
||||
|
||||
Reference in New Issue
Block a user