Http SUBSCRIBE / NOTIFY (Session Initiation Protocol) - how?

I would like to implement a listener to an UPNP service. For that I need to subscribe (simple http request with some specific headers items - see code) and create an http instance for incoming notification.

Is there anything available in Node-RED what I can reuse?
I could not find "SUBSCRIBE" - only POST, GET, ... in the http nodes.
Any node.on for this kind of subscription, port 4000

> async function (baseUrl, path) {
>     const response = await request({
>       method: 'SUBSCRIBE',
>       baseURL: baseUrl,
>       url: path,
>       headers: {
>         CALLBACK: '<>',
>         NT: 'upnp:event',
>         TIMEOUT: 'Second-1800'
>       },
>       resolveWithFullResponse: true
>     })

You can have whatever method you desire.

HTTP Request node...

1 Like

some while ago I created a upnp node
Lately I fixed some bugs which have not been published yet, but the basic functionality should work.

Looks interesting.
Is there any documentation for "receive event"?

UUID might be RINCON_5CAAFD00223601400 but also RINCON_5CAAFD00223601400_MR. Both show green.
Service type is what? I tried upnp:event but an error occurs.
Where do I have to enter the service endpoint -for instance "MediaRenderer/RenderingControl/Event"

Service type depends on what you want to receive events from.
I read sonos in your first post, so I guess you maybe want urn:schemas-upnp-org:service:AVTransport:1

You can also pull in the mediaRenderer node, which receives events from urn:schemas-upnp-org:service:AVTransport:1 and you can play, pause, stop, set media etc.

If you explain me what you want to do, I might can help. I went through the rabbit hole and have read a lot of the UPnP specifications.

About the UUID, you get it from discovery. Send the payload ssdp:all to the discovery node and it will shout out a lot of messages (put a debug node behind it). Then find the service you want to have and then also the associated UUID from that. But if it shows the green status, then it is already good :slight_smile: So you might already found the right one.

What error occurs?

I have just read in your post that you want to do rendering control,
then urn:schemas-upnp-org:service:RenderingControl:3 should be the service type.
However, rendering control is not really useful for a loudspeaker, except for changing the volume.

I would like to get notified about changes regarding playback state but also about volume changes.

The output from ssdp:all / node Discovery is for the relevant player:

USN: "uuid:RINCON_5CAAFD00223601400_MR::urn:schemas-upnp-org:service:AVTransport:1"
address: ""

For node receive event, field Service Type:
and in the configuration node, field uuid

The node status turns green and the debug node provide the error:
Error: Service urn:schemas-upnp-org:service:AVTransport:1 not available

playback state is something you get from AVTransport, volume from renderingControl.

Can you post the complete output from the discovery for the relevant player? I might already have an idea why it might not work

can you maybe also post the device description xml file? During discovery, you should find the device description url somewhere in the message (headers.LOCATION), open that in the browser and post the content here.

UPnP is a complex topic, the little code you have shown above would definitively not do the right thing (or I misinterpret it), because the CALLBACK should not be the device you want to receive the state from, but an http endpoint the device will report its state to. Furthermore, you have to resubscribe after the timeout etc.

I googled myself for the device description xml of a sonos device (could be that it is a different one to yours) and it appears that sonos devices make use of so-called embedded upnp devices (just another unnecessary feature of the upnp spec)
I have not implement this, since I don't own a device that has this feature.

If you are willing to test things, I can try to implement this, which should be pretty easy, however, it is hard to do for me since I cannot test it.

1 Like

Testing: Yes - sure I will do the tests. One restriction: from 16 to 25 of June I am not at home and don't have access to the SONOS devices.

Little Code: Yes, I know. The "little" code only does the "subscribe" but we need an event receiver, unsubscribe, renew subscription, ... - that's why your package is needed.

Additional info: There are 4 player endpoints I would like to subscribe to:
MediaRenderer/AVTransport/Event, MediaRenderer/RenderingControl/Event, MediaRenderer/GroupRenderingControl/Event, MediaRenderer/Queue/Event

and 2 global endpoints but so far I dont need them:
AlarmClock/Event, ZoneGroupTopology/Event

Before being able to subscribe, the event receiver must be up an running - otherwise the subscription will return error 412.

There are already packages providing the events node sonos and notify but they crash to often on my system.

Here is the requested output:
event - output.txt (14.2 KB)

Thanks for your help.

I just pushed a new version to github
Best is to uninstall the old one first, since it depends on a package I updated which is installed from git as well ( this is the actual control point) and I don't know if npm is smart enough to update dependencies from github as well.

This is now untested code, since I don't own a device with embedded devices.

Let me know what you got. If it doesn't work, then you need to add some debugging output, I will tell you how.

The content of would also be great

you are lightning fast :slight_smile:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<root xmlns="urn:schemas-upnp-org:device-1-0">
<friendlyName> - Sonos Play:5</friendlyName>
<manufacturer>Sonos, Inc.</manufacturer>
<modelDescription>Sonos Play:5</modelDescription>
<modelName>Sonos Play:5</modelName>
<friendlyName> - Sonos Play:5 Media Server</friendlyName>
<manufacturer>Sonos, Inc.</manufacturer>
<modelDescription>Sonos Play:5 Media Server</modelDescription>
<modelName>Sonos Play:5</modelName>
<friendlyName>KĆ¼che - Sonos Play:5 Media Renderer</friendlyName>
<manufacturer>Sonos, Inc.</manufacturer>
<modelDescription>Sonos Play:5 Media Renderer</modelDescription>
<modelName>Sonos Play:5</modelName>
<X_Rhapsody-Extension xmlns="">
<interactionPattern type="real-rhapsody-upnp-1-0"/>
<qq:X_QPlay_SoftwareCapability xmlns:qq="">QPlay:2</qq:X_QPlay_SoftwareCapability>

What input is required in the config node?

With that data I get a red status: Device RIN... lost.

What is service type in event node? upnp:event does not work

In the event node urn:schemas-upnp-org:service:AVTransport:1 as I said before.
And don't use "use hardcoded device description URL" and don't put something into "device description url" and especially not an event URL.
The option "use hardcoded device description URL" is for avoiding discovery, which in some networks is unreliable.

Edit: If you want to use the hardcoded description URL, you have to put into it, but this would assume that the device always has the same IP. If you use discovery, it can deal with changing IPs etc.

amazing - well done! :grinning: :clap:
Discovery works and a lot of events come in.
I will now make a list, what I do receive and what is missing.

When I use hardcoded (with static ip address) the discovery is omitted what means faster and more reliable?

great :slight_smile:

If you also want rendering control, you need a second event node with urn:schemas-upnp-org:service:RenderingControl:1 as the service type.

Yes, the discovery sometimes makes problems, so if you go with the hardcoded device description url and a static IP, it is more reliable and also a tiny bit faster.

One disclaimer though: UPnP is really a complex topic, mainly because I think there is not a single implementation out there that adheres to the spec (libupnp for linux does not completely, and my one also not). Therefore, I do not promise that it does not crash, ok?
That is also the reason why I never published that node on npm (also due to lack of documentation).
Still, for my UPnP devices, that node runs stable for over a year without any problems and is used every day.

Report any problems and I can see what I can do.

1 Like

@Steve-Mcl: Thanks - that's a good trick. It works fine and I receive the subscription id from the server.

Do you have a similar "trick" for the http-in node. I need a "NOTIFY" method as the server expects a http response with confirmation 200 OK.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.