Supergiovane / node-red-contrib-sonospollytts

Play speech TTS using Sonos.
https://www.facebook.com/supergiovaneDev
MIT License
12 stars 6 forks source link

Cannot edit sonospollytts node #35

Closed stevegroom closed 4 years ago

stevegroom commented 4 years ago

New NodeRed under docker installation.

Added sonospollytts node, but cannot open the edit configuration dialog within the node-red flow.

Double click on sonspollytts always results in message

PLEASE SAVE, DEPLOY AND RE-OPEN THIS WINDOW
EVEN IF NODE-RED TELLS YOU
THAT THE NODE ISN'T CORRECTLY CONFIGURED
TO ACCESS THE CONFIGURATION 

I did export the code, edit in notepad and created a new node. The flow I created is working correctly, but the lack of the edit box is not convenient.

regards Steve

Supergiovane commented 4 years ago

Hi Steve do you have deployed the node, as stated by the message?

Supergiovane commented 4 years ago

PS: the node must be saved and deployed, because the Sonos Discovery and the automatic IP Address discovery, need a server backend up and running. So you first have do deploy, to start the backend server.

stevegroom commented 4 years ago

Yes, it is deployed and working. I just cannot display the properties.

Supergiovane commented 4 years ago

Hmmmm.... very very strange. Sonospollytts tries to reach out his endpoint by using the node-red IP. Behind a docker, it can be that somethings doesn’t work. I’ll do a quickfix for you. Will benout in about 30 minutes or so.

Supergiovane commented 4 years ago

So, please paste these two files to your .node-red/node_modules/node-red-contrib-sonospollytts/sonospollytts folder and restart node-red. You should then please tell me, what error do you see, in the DEBUG panel of node-red. Thanks Archivio.zip

stevegroom commented 4 years ago

Hi, the modules were manually deployed and node-red restarted.

The debug window shows this message:

"SonosPollyTTS-config: undefined error starting webserver on port 1980 Error: listen EADDRINUSE: address already in use :::1980"

and a moment later:

"SonosPollyTTS-config: undefined error starting webserver on port 1980 Error: listen EADDRINUSE: address already in use :::1980"

The flows continue to work though. I have three SONOSPollyTTS nodes installed in this NodeRed instance. If I display the configuration nodes there are two entries called Config, one has a counter of 2 and the other a counter of 1. The content of these two config nodes are identical - both have port 1980.

regards Steve

Supergiovane commented 4 years ago

Hello You have for sure more than one config node. Each config node uses a port 1980 to start the webserver. Please set 1981 to the second config node or delete it. You should use only one config node. .

stevegroom commented 4 years ago

Hi, I removed the three SonosPolyTTS nodes and the two config nodes were removed automatically.

Now trying to re-add one at a time. The first is working, but the Main Sonos Player field is blank. Here is the exported node:

[
    {
        "id": "773be842.65bd48",
        "type": "sonospollytts",
        "z": "bc2cf70f.3d1b88",
        "name": "",
        "voice": "36",
        "ssml": false,
        "sonosipaddress": "192.168.86.191",
        "sonosvolume": "25",
        "sonoshailing": "Hailing_Hailing.mp3",
        "config": "e6b7a48f.7f7d1",
        "propertyType": {},
        "rules": [],
        "x": 740,
        "y": 720,
        "wires": [
            []
        ],
        "icon": "node-red/leveldb.png",
        "info": "# Hello there!"
    },
    {
        "id": "e6b7a48f.7f7d1",
        "type": "sonospollytts-config",
        "z": "",
        "name": "Config",
        "noderedipaddress": "192.168.86.51",
        "noderedport": "1980",
        "purgediratrestart": "purge"
    }
]

The debug shows the error

"SonosPollyTTS: Error in discovery Error: No device found"

As I said the flow is working though.

regards Steve

Supergiovane commented 4 years ago

Hello You must delete the config nodes by hand. If you delete the sonospollytts node, their config node remains. From the remainig sonospollytts node, select each config node from the dropdown list, click the pen icon to modify the config node, then push DELETE. Leave only one config node.

Discovery: you must assure that a multicast udp discovery packet can flow through the docker, otherwise the node will be unable to find sonos devices in your network. Please check the docker firewall and configuration. If the docker do nat, it’s impossible for node-red to broadcast and hear UDP packets. Cheers!

cannfoddr commented 4 years ago

Hi,

I am having a very similar issue here. With the patched files I am able to get he configuration screen up but there are no Sonos players listed.

I can see this error in the log:

"SonosPollyTTS: Error in discovery Error: No device found"

I am also getting an error on the node itself:

image

I can see the web service being started:

10 Apr 21:04:51 - [info] SonosPollyTTS-config: Node-Red node.js Endpoint will be created here: http://192.168.1.24:1980/tts

My docker config is from docker-compose where I run all my home assistant related containers. The node-red container connects to 3 networks:

I can access http://192.168.1.24:1980/tts from a machine and it downloads a tts.mp3 file.

I think discovery side is struggling to find my sonos devices.

Stop press I just found this in my log:

10 Apr 21:05:58 - [warn] SonosPollyTTS: Error in discovery Error: No device found
TypeError: Cannot read property 'address' of undefined
    at /data/node_modules/node-red-contrib-sonospollytts/sonospollytts/sonospollytts.js:525:41
    at Layer.handle [as handle_request] (/usr/src/node-red/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/src/node-red/node_modules/express/lib/router/route.js:137:13)
    at /usr/src/node-red/node_modules/@node-red/editor-api/lib/auth/index.js:68:28
    at complete (/usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:268:13)
    at /usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:275:15
    at pass (/usr/src/node-red/node_modules/passport/lib/authenticator.js:431:14)
    at Authenticator.transformAuthInfo (/usr/src/node-red/node_modules/passport/lib/authenticator.js:453:5)
    at /usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:272:22
    at IncomingMessage.req.login.req.logIn (/usr/src/node-red/node_modules/passport/lib/http/request.js:55:13)
10 Apr 21:06:04 - [warn] SonosPollyTTS: Error in discovery Error: No device found
stevegroom commented 4 years ago

OK, started over. Deleted the nodes, deleted the config node too. Created first SonosPollyTTS node, clicked on the config link and setup the config node too.

Deploy failed with "SonosPollyTTS: Error in discovery Error: No device found" and EConn State refused message under the node. The SONOS Player IP address could not be selected.

I exported the node, added the Sonos IP setting manually and imported and used that node. This is working again.

So as you suggested there is perhaps some issue the UDP between the docker containers and querying the local network for the SONOS players.

regards Steve

Supergiovane commented 4 years ago

Hi Yes for both you two, there are problems in discovery. Running node-red behind docker, redmatic, homeassistant and similar, if not correctly configured, can be very challenging. I can maybe do a fallback if the discovery does not work, to be able to manually enter the sonos IP address, but if the container is set to do NAT and you do not forward the appropriate ports (at least the 1980), the sonos device will be unable to reach node-red. I will put my hands on that tomorrow.

Supergiovane commented 4 years ago

Hi all! Please paste these 4 files to your .node-red/node_modules/node-red-contrib-sonospollytts/sonospollytts folder and restart node-red. Archivio.zip

If the auto discover fails, it reverts after some seconds to manual sonos ip input. Check and let me know if it works. Thanks

stevegroom commented 4 years ago

Hi everyone, from Gio's comments, I am starting to understand the issue. I did some googling on accessing UDP host net services from within a docker container. There were some complex discussions, but I did find one setup that is working without needing a special build!

docker-compose.yml

################################################################################
# Node-RED Stack on Docker-Compose
################################################################################

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Zurich
    command:
      - "--log.level=DEBUG"
    ports:
      - "1880:1880"
    network_mode: "host"
    volumes:
      - ./data:/data

I did not try the latest files yet though.

Ciao!

Supergiovane commented 4 years ago

Hi Steve, good. I'll release a new version today with fallback to manual IP input, if autodiscovery doesn't work. It should solve the issue for noobs users, not able to do any modification on docker.

stevegroom commented 4 years ago

Hi Gio, excellent! My light bulb checker is now fully working without manual editing.

Light bulb checker ? - I have some zigbee smart lights that are not reliable. I use node red with HueMagic and SonosPollyTTS to announce when a bulb becomes reachable or unreachable - which is a great help when up a ladder :-)

I'll continue to refine my dockerised version to share that when it's done.

Steve

cannfoddr commented 4 years ago

All,

Thanks for all the updates. I am running my HomeAssistant docker container using the same macvlan16: network using 192.168.1.22. It is happily discovering my Sonos devices and pretty much everything else on my network, my assertion is that it seems more than capable of doing network discovery using this network mode.

I figured putting node-red container into the same network mode would enable this to happen too. I am wondering if your integration is selecting the correct network to do discovery on or is making an assumption that there is just a single network?

Having an alternative to discovery would simplify things for me - I can fix the IPs of the Sonos players if needed via a router assignment

Is this log fragment at all relevant:

10 Apr 21:08:04 - [warn] SonosPollyTTS: Error in discovery Error: No device found
10 Apr 21:09:42 - [info] [sun events:Time of day] Injecting event nauticalDusk for Fri Apr 10 2020 21:09:42 GMT+0100 (British Summer Time)
10 Apr 21:10:24 - [error] SonosPollyTTS-config: Playsonos RED.httpAdmin file not found: undefined
TypeError: Cannot read property 'address' of undefined
    at /data/node_modules/node-red-contrib-sonospollytts/sonospollytts/sonospollytts.js:525:41
    at Layer.handle [as handle_request] (/usr/src/node-red/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/src/node-red/node_modules/express/lib/router/route.js:137:13)
    at /usr/src/node-red/node_modules/@node-red/editor-api/lib/auth/index.js:68:28
    at complete (/usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:268:13)
    at /usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:275:15
    at pass (/usr/src/node-red/node_modules/passport/lib/authenticator.js:431:14)
    at Authenticator.transformAuthInfo (/usr/src/node-red/node_modules/passport/lib/authenticator.js:453:5)
    at /usr/src/node-red/node_modules/passport/lib/middleware/authenticate.js:272:22
    at IncomingMessage.req.login.req.logIn (/usr/src/node-red/node_modules/passport/lib/http/request.js:55:13)
10 Apr 21:16:40 - [warn] SonosPollyTTS: Error in discovery Error: No device found
10 Apr 21:16:41 - [audit] {"event":"credentials.get","type":"sonospollytts-config","id":"a9893895.e66cb","level":98,"timestamp":1586549801386}
Supergiovane commented 4 years ago

Hi, Please upgrade to the latest v1.1.24 of sonospollytts.

cannfoddr commented 4 years ago

Hi, I've upgraded and the manual entry is working fine for me. I am going to live without discovery for now and have reverted my docker to using the docker-compose network and the proxy network and removed the 'real' IP. I am using a port forward for port 1980 to the docker host and am using the docker host address for the config node.

Everything is still working very well so thanks for your excellent support.

Now off to figure out what I can get away with announcing on the Sono from HomeAssistant :-)

Supergiovane commented 4 years ago

It’s a pleasure. You’re wellcome.