Is it possible to somehow add debug messages manually from outside Node-RED to the Debug side panel, where debug nodes also log their messages? I was trying to do something like this.
function connectToNodeREDWebSocket() {
console.log('Attempting to connect to Node-RED WebSocket...');
ws = new WebSocket('ws://127.0.0.1:1880/comms');
ws.on('open', () => {
console.log('WebSocket connection established with Node-RED');
const message = {
topic: "debug",
data: {
msg: "Hello from WebSocket client!",
timestamp: Date.now(),
level: 20
}
};
ws.send(JSON.stringify(message));
});
}
I manage to establish a connection but Node-RED doesn't seem to display any messages in the Debug panel.
Certainly. Set up a websocket-in node as a listener. Connect to it from the browser. Anything you send over that link will appear in Node-RED as a msg so just attach a downstream debug node and you are good to go.
Is it also possible to directly send a message to this Debug side panel? Without the use of a websocket-in node or debug node? I thought Node-RED itself also used a websocket connection internally where nodes can publish messages too for it to be displayed inside the Debug panel. I basically want a way to notify the Node-RED user without setting up any nodes beforehand. You think this is possible? For your information, i'm not building an application in Node-RED i'm building an extension of Node-RED.
There is an internal API that lets you send to debug from the runtime. But you still need a way to accept a websocket connection and call the api.
Not a native feature but you could probably create a plugin to do it.
Oh okay, I'm not familiar with these plugins. Is there some documentation on how to create/add these plugins to Node-RED?
The Node-RED docs have some info.
Yes, if you want to do this in the frontend, i.e. in the editor, then this is an implementation of the debug node that runs in the frontend - the core is: RED.comms.emit([{ "topic": "debug", "data": debugData }])
From the server side this is a little more tricky but checkout the debug node for the answer - the core is RED.comms.publish("debug",msg);
- msg
isn't the object we think of it being!
Serverside example code is also the msg debugger inside the introspection package which does better describe what the msg
object in this case looks like.
For that you want to create a endpoint inside of node red, for example, HTTP-in node that accepts connections to /notify/node/red/user/about/something
then from outside of node-red, you send a HTTP POST to that endpoint. The http-in node is connected to a debug node and bobs your uncle.
The NodeRED flow would be something like this:
[{"id":"830ea901315f9180","type":"http in","z":"5f23149bb8dc98d4","name":"","url":"/notify/node/red/user/about/something","method":"post","upload":false,"swaggerDoc":"","x":571,"y":258,"wires":[["e169270b39512330"]]},{"id":"e169270b39512330","type":"debug","z":"5f23149bb8dc98d4","name":"debug 118","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":902,"y":259,"wires":[]}]