Trying to get MusicBox working with ssh tunnel pagekite

Hey yall - I am trying to get musicbox accessible via anywhere. I am using v 0.5.2

I am using a cool python services called pagekite: https://pagekite.net/support/quickstart/

I run a command pagekite.py 6680 boombox.pagekite.me

I can see my webclient frontend now however, I get the spinning “Tryingf to reach MusicBox: Please wait” UI. I noticed that @kingosticks said this happens when trying to run via ssh port: https://github.com/woutervanwijk/Pi-MusicBox/issues/117#issuecomment-49266231

And recommends commenting out code in the config file. Since then the code on that config file has changed.

I’ve tried changing the default port to 80 in the /boot/config/settings.ini but this seems to have permission problems.

I’m a bit lost - could anyone suggest how to achieve what I’m aiming for:

Have musicbox available on boombox.local (as it is)
also available on boombox.pagekite.me (which it almost is)

Any ideas? Thanks

This is probably related to that in so far as the websocket connection to your Mopidy server is failing. The code was changed to better support using an arbitrary port but this isn’t what you are doing here. Most browsers have a console where you can view errors when loading the page, in my version of Chrome I can goto “More Tools” -> “JavaScript console” from the main menu. It might just be something to do with the websocket connection security, you probably need to use http://boombox.pagekite.me rather than https://boombox.pagekite.me.

I gave it a try (using pagekite.py 6680 kingosticks.pagekite.me and was getting the following JS console errors when browsing to http://kingosticks.pagekite.me/.

WebSocket connection to 'ws://kingosticks.pagekite.me:6680/mopidy/ws/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Since I wasn’t specifying a port in my browser, the webclient was trying to open a websocket connection (using the default port 6680) to kingosticks.pagekite.me:6680. But since the pagekite relays don’t listen on that port by default (maybe you can change that?) the connections were refused. If I instead go to http://kingosticks.pagekite.me:8080 then the websocket connection uses kingosticks.pagekite.me:8080 which is correctly relayed and then translated to localhost:6680 by pagekite running on pi musicbox.

So it turns out I was wrong - the arbitrary port support is exactly what you want!

Hey there - thanks for diving in. It seems like a really cool application that will have all sorts of uses ( @woutervanwijk may want to look into it for Pimusicbox - including the remote ssh tunnel access if needed…)

Anyways - so I also tried a few modificatiions. I changed my mopidy web port from 6680 (which is not open on pagekite) to 8000.

So here is the pagekite code to start the service:

pi@BoomBox ~ $ pagekite.py 8000 boombox.pagekite.me:80
>>> Hello! This is pagekite.py v0.5.6d.                         [CTRL+C = Stop]
    Connecting to front-end 88.198.198.93:443 ...                              
     - Protocols: http http2 http3 https websocket irc finger httpfinger raw   
     - Protocols: minecraft                                                    
     - Ports: 79 80 443 843 2222 3000 4545 5222 5223 5269 5670 6667 8000 8080  
     - Ports: 8081 9292 25565                                                  
     - Raw ports: 22 virtual                                                   
    Quota: You have 2556.81 MB, 30 days and 5 connections left.                
    Connecting to front-end 178.79.140.143:443 ...                             
~<> Flying localhost:8000 as https://boombox.pagekite.me:80/                   
    41.220.141.5 < http://boombox.pagekite.me:80 (localhost:8000)              
^C< pagekite.py [flying]   Kites are flying and all is well.  

And here is the error I’m now getting in my chrome browser when browsing to http://boombox.pagekite.me:

WebSocket connection to 'ws://boombox.pagekite.me:8000/mopidy/ws/' failed: Error during WebSocket handshake: Unexpected response code: 503
mopidy.min.js:5 WebSocket error: Event {clipboardData: undefined, path: NodeList[0], cancelBubble: false, returnValue: true, srcElement: WebSocket…}bubbles: falsecancelBubble: falsecancelable: falseclipboardData: undefinedcurrentTarget: WebSocketdefaultPrevented: falseeventPhase: 0path: NodeList[0]returnValue: truesrcElement: WebSockettarget: WebSockettimeStamp: 1420371200329type: "error"__proto__: Event

Don’t want to take you too off course - but I thought I’d keep you posted on the developments…

Hmmm - when I try and run the mopidy on the local network it plays for about 30 seconds then… I eventually get this error and the music stops (using webclient).

WebSocket connection to 'ws://192.168.0.138:8000/mopidy/ws/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Did you try what I described in my post (with a default musicbox config)?

  1. Run pagekite.py 6680 boombox.pagekite.me
  2. Goto http://boombox.pagekite.me:8080 in your web browser
1 Like

Yup - finally got around to it and it works like a charm!

Initially I got this error in my chrome browser console:

Uncaught SyntaxError: Failed to construct 'WebSocket': The URL 'ws://boombox.pagekite.me:8080:6680/mopidy/ws/' is invalid.

However I changed around the commented out lines below in /opt/webclient/index.html which seemed to do the trick. It still loads locally (although I’m confused why I can’t local http://localhost when I’m ssh’d into the raspberry pi - I thought wouter had configured an iptables rule to point requests on port 80 to 6680)

  //var wsLocation = location.host + ':6680';  //for normal operation of mopidy http
  var wsLocation = location.host;   //for running on port 80

Anyways - I also configured the ssh tunnel so I can also ssh into my musicbox remotely :smile:

Hmmm - one strange behaviour is that when I access the ip address directly 192.168.0.138 it loads as expected… however http://boombox.local gives me the following console error:

WebSocket connection to 'ws://boombox.local:6680/mopidy/ws/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

I have found that the .local mDNS address resolving is a bit flaky - but any thoughts on why this might be?
anything todo with the webclient index.html setting?