UPnP Node

560 views
Skip to first unread message

Glenn

unread,
Mar 28, 2017, 7:23:06 PM3/28/17
to Node-RED
I was wondering if anyone made or is willing to make a UPnP node which is already available in Node.js format.

What I am currently doing which I would imagine is the wrong way to do it is using the Exec node.

I have a node.js script using (node-upnp-utils) which passes all the UPnP devices on the network to a text file.

I then use that information which I store as JSON to do further processing.

It means I can do dynamic nodes for example every device that is MusicCast.

Any help would be great. 

PS: My JS file is very similar to the sample one, but if it helps I can post it here as well.

Sebastian Barwe

unread,
Mar 29, 2017, 2:48:44 AM3/29/17
to Node-RED

cin...@gmail.com

unread,
Mar 29, 2017, 5:14:39 AM3/29/17
to Node-RED
Hi,

funny, I thought of this last week, too :-)

I think it would be a very nice feature to have upnp nodes in node-red. The question is, however, how to design it properly. For the discovery process, node-ssdp (https://www.npmjs.com/package/node-ssdp) is a good node package  which is maintained and works well!

Given that you have discovered the device, the package https://www.npmjs.com/package/upnp-device-client also works well.


However, I think we should discuss how we would like to implement such things.
- a separate discovery node which allows to find devices and return their adress
- some node which fetches the description of the services the device can provide.
- an event node listening to the events of a given device
- a action call node based on the description.

Should the adress of a device then be configured in the other nodes? Or should there only be a friendlyname or so and then the discovery process is invoked every time node-red restarts?




Glenn

unread,
Mar 29, 2017, 6:38:09 AM3/29/17
to Node-RED
SSDP crashes Node-Red for me. Maybe I'm doing it wrong and the other one you suggest floods my MQTT with info that isn't required. I just want something basic and straightforward

cin...@gmail.com

unread,
Mar 29, 2017, 6:43:06 AM3/29/17
to Node-RED
node-ssdp crashes node-red? How are you using this, or do you mean the node-red-contrib-ssdp-discover? The last one says on its github that it is not working.

UPNP is not straightforward in my opinion. However, I tried to start a discussion how we could make it straightforward within node-red. In a few weeks I will start putting a node together, but I cannot promise anything... If someone likes to discuss the design or contribute, I would appreciate it

Given the adress of a device, you could in principle use node-reds http nodes I think...


Am Mittwoch, 29. März 2017 12:38:09 UTC+2 schrieb Glenn:

Glenn

unread,
Mar 29, 2017, 4:42:22 PM3/29/17
to Node-RED
The contrib one. Given the one i posted in the first post if the output is JSON how can I get it in node-red?

Dave C-J

unread,
Mar 29, 2017, 6:51:08 PM3/29/17
to node...@googlegroups.com
You'll need to wrap it into a node... See http://nodered.org/docs/creating-nodes/

sent from phone

Glenn

unread,
Mar 29, 2017, 9:15:21 PM3/29/17
to Node-RED
Thanks for that. Guess I am just confused how to get console.log to a payload.

Dave C-J

unread,
Mar 30, 2017, 4:43:07 AM3/30/17
to node...@googlegroups.com
Page 2 of the docs...
you don't use console.log...

Glenn

unread,
Mar 30, 2017, 5:50:11 AM3/30/17
to Node-RED
Thanks will look into it over the weekend.

This is what I have so far, it's crude but it works. Obviously once I get it done correctly I won't have to use an exec and file node.

So I inject the script name that I want I run on Node.Js which produces output in a file the file is converted to javascript objects which is then split into topics and published to MQTT

Auto Generated Inline Image 1

cin...@gmail.com

unread,
Mar 30, 2017, 5:59:16 AM3/30/17
to Node-RED
just for your info, I am starting to create an upnp node in a little more than a week (busy at the moment). If you could describe what you are trying to do more precisely I could see if it fits to my idea of an upnp node...

(of course if you are faster than me to create such a node, I could think of contributing....)

Dave C-J

unread,
Mar 30, 2017, 6:46:10 AM3/30/17
to node...@googlegroups.com
in your exec node... - if the code you called just output to the screen/console/stdout - then the exec node top output should give you that... (Not sure why you are using the 2nd stderr output ???)  - that would save you writing to a file and so on.  You may need to use spawn rather than exec if the output comes back over multiple lines and times - but have a play and see...

But yes a proper node would be a better way to go - so yes please chat about it here and describe the functions it should have so you can come up with a good general purpose approach. 

Sebastian Barwe

unread,
Mar 30, 2017, 9:19:13 AM3/30/17
to Node-RED
Hi Glenn, hi "cin...",

upnp is on my work item list as well.

I am looking more into events and control of UPNP additonally to discover them (like getting notified on phone call, restart internet connection or get notified when someone is entering the network).
Additionally I wanted to include a sercice description into node-red as well so I can "misuse" the A/V Features and impl. remote ui service.
This was not a high priority task for me but getting discovery feature from upnp utils  into a node shall bew easy and done fast.

my requirements in priority order:

- discovery and description (configuration: discovery timeout, subnet (indirectly defines network interface), upnp MX/ST (like upnp:all ) parameters,  auto-get-device-description)  --> output: JS-Object per Device, containing SSDP result + Baseurl + uuid etc.
- discovery will start on input, settings can be overriden by msg-properties

- control and eventing (first general node with specific settings of e.g. state variables for a specific uuid which need filled by hand, next presets / common upnp profiles (e.g. remote ui, media control etc. ))

- then defined presets / profile support shall be implemented by needs and contributions (e,g, TR-064 (common for fritz.box in germany: https://avm.de/service/schnittstellen/) or Media Renderer Client)  which could lead to new nodes specific for the use cases. (e.g. https://github.com/thibauts/node-upnp-mediarenderer-client could be used)

- UPnp control points (e.g. to play a wakeup song or create a program reminder and switch TV to webcam stream etc.automated by node-red / dashboard)

The main Idea is to limit necessary UPnp knowledge and SOAP stuff handling


Has somebody a project up already on github ?

cin...@gmail.com

unread,
Mar 30, 2017, 9:41:58 AM3/30/17
to Node-RED
cool that others are also interested :-)

(just short since I have no time this week)

with respect ot existing packages, I think
- https://www.npmjs.com/package/node-ssdp for the discovery stuff seems very good
- https://www.npmjs.com/package/upnp-device-client for actions/events seems good (tried both and was able to control various devices within minutes)

I think three nodes to begin with are a good start:
- Discovery as you describe  here
- discovery and description (configuration: discovery timeout, subnet (indirectly defines network interface), upnp MX/ST (like upnp:all ) parameters,  auto-get-device-description)  --> output: JS-Object per Device, containing SSDP result + Baseurl + uuid etc.
- discovery will start on input, settings can be overriden by msg-properties
Should be managable with node-ssdp

- Actions with input and output. Here the main goal should be to hide away the xml/soap stuff by accepting and returing JS objects. Here I think, as you said, the user should just specify the serviceId url by hand in the beginning. Question is how this can be combined reasonably with the discovery process. Should the action calling test if the device provides action at all each time?

- Eventing node.

Action and event nodes could be handled by upnp-device-client package. However, maybe writing this part from scratch could also be an alternative...

The main Idea is to limit necessary UPnp knowledge and SOAP stuff handling
 +1 +1 +1 :-) Should be our main goal, I would say...

Sebastian Barwe

unread,
Mar 30, 2017, 3:55:00 PM3/30/17
to Node-RED
ok, let's start ... do we have a repository already? If not, shall I create "node-red-contrib-upnp" ?

Glenn

unread,
Mar 30, 2017, 5:59:32 PM3/30/17
to Node-RED
Go ahead. I was thinking of using the node ja script I mentioned in my first post as it does discovery and actions. Rather than two separate node apps.

I still agree on separate flows but since I already have discovery working I just need to package it

Glenn

unread,
Mar 31, 2017, 4:14:00 AM3/31/17
to Node-RED
Hi Sebastian,

This is my code. Works great for local discovery can be more in-depth if needed.

Not sure why I can't get the strout to show on node-red though

var upnp = require('node-upnp-utils');

  console
.log ("[");
// Set an event listener for 'added' event
upnp
.on('added', (device) => {
 
// This callback function will be called whenever an device is found.
   
 
var address = device['address'];
 
var name = device['description']['device']['friendlyName'];
 
var modelName = device['description']['device']['modelName'];
 
var manufacturer = device['description']['device']['manufacturer'];
 
var modelDescription = device['description']['device']['modelDescription'];
 
var location = device['headers']['LOCATION'];  
 
var USN = device['headers']['USN'];

  name
= "\"name\":\"" + name + "\","
  manufacturer
= "\"manufacturer\":\"" + manufacturer + "\","  
  modelName
= "\"modelName\":\"" + modelName + "\","
  modelDescription
= "\"modelDescription\":\"" + modelDescription + "\","
  location
= "\"location \":\"" + location + "\","
  USN
= "\"USN \":\"" + USN + "\","
  address
= "\"address\":\"" + address + "\""  
 
 
var data = "{" +name + manufacturer + modelName + modelDescription + location + USN + address + "},"
 
  console
.log (data);
});
 
// Start the discovery process
upnp
.startDiscovery();
 
// Stop the discovery process in 15 seconds
setTimeout
(() => {
  upnp
.stopDiscovery(() => {    
    console
.log ("{}]");
    process
.exit();
 
});
}, 15000);



Glenn

unread,
Mar 31, 2017, 4:55:22 AM3/31/17
to Node-RED
Hi Dave C-J

I figured out what was wrong which is a silly mistake. I was meant to connect the flow to the top output. Connecting it to the top one means it sends each result as a separate message, Which in turn means the code I posted is wrong.

But it's good not to have the file node there as it was a bit redundant.

Sebastian Barwe

unread,
Mar 31, 2017, 6:13:23 AM3/31/17
to Node-RED
Hi Glenn,

I started node-red-contrib-upnp - will let you know when prototype is (think I will have time for it on this weekend)

Sebastian Barwe

unread,
Mar 31, 2017, 6:15:11 AM3/31/17
to Node-RED
Hi cin...
If you like I can add you as a contributor just drop me a private message with your github email


Am Donnerstag, 30. März 2017 15:41:58 UTC+2 schrieb cin...@gmail.com:

cin...@gmail.com

unread,
Mar 31, 2017, 7:23:11 PM3/31/17
to Node-RED
Hi!

Just for fun, I put together a little upnp action node, see
(not master branch)
The example.flow shows a very quick example to start playing a mediarenderer (or something that implements the AVTransport service). You have to specify the device description url first in order to get this working. 
(nothing to be used in production, but it is working :-)))

Many things can be improved, but I think we have a start now :-) I just put this together in half an hour...
Should we switch to another communication platform and use this mailing list for collecting features and reporting status?
I have little time until next week (just for info)

Glenn

unread,
Mar 31, 2017, 10:17:20 PM3/31/17
to Node-RED
Good job.

Maybe you and Cin should do this on Slack or something?

I believe I have done what I needed for the moment.

It searches for all MusicCast devices on the network and then converts all the state items to MQTT which can then be recalled dynamically without having to know the host IP name





And this is what my dashboard looks like. Everything is vector except for album art and everything is dynamically based on the room name. It's looking amazing considering I have never used Angular before

Auto Generated Inline Image 1
Auto Generated Inline Image 2

Mark Setrem

unread,
Apr 1, 2017, 2:51:20 AM4/1/17
to Node-RED
Rather than sharing an image of your flow, why not add the flow to flows.nodered.org?

Glenn

unread,
Apr 1, 2017, 4:02:51 AM4/1/17
to Node-RED
It's not a dynamic flow for use for others.

I guess that is the point of this thread to turn my solution into something that will work for everyone.

Julian Knight

unread,
Apr 1, 2017, 10:38:43 AM4/1/17
to Node-RED
Not everything in flows has to be generic, as long as it shows people how they could progress something for themselves. Just ensure that you don't reveal something secret.
Reply all
Reply to author
Forward
0 new messages