Ngrok Tunnel: A more secure but simple to use alternative to port forwarding

That is interesting to hear, but later when a Print is finished, pushover works.

That sounds good :smiley:

@20pyro00, could you try installing the current development version via OctoPrint Settings -> Plugin Manager -> Get more -> ... from URL with the following url: https://github.com/fieldOfView/OctoPrint-ngrok/archive/devel.zip? It adds a retry after 20 seconds if the first attempt does not work.

Hi @fieldOfView , i got the dev-version installed and restarted my printer severel times new. Now everytime a tunnel is created. Thank you :slightly_smiling_face:

1 Like

Hi again. I have the same problem. Today i started the printer and later i wanted to see how far my print was. But there was no tunnel. I have no idea why. Could you programm it so we can change the delay-number? Thanks :smiley:

I would rather fix the problem. I need logs to see what the problem is.

I copied these lines out of the log. This happened after a restart from a Plugin-update.

2020-08-27 16:56:17,472 - octoprint.plugins.ngrok - INFO - Setting ngrok auth token & region...
2020-08-27 16:56:17,473 - octoprint.plugins.ngrok - INFO - Opening ngrok tunnel...
2020-08-27 16:56:17,515 - pyngrok.process - WARNING - t=2020-08-27T16:56:17+0100 lvl=warn msg="can't bind default web address, trying alternatives" obj=web addr=127.0.0.1:4040

2020-08-27 16:56:17,696 - pyngrok.process - ERROR - t=2020-08-27T16:56:17+0100 lvl=eror msg="failed to auth" obj=tunnels.session err="Your account '20pyro00@gmail.com' is limited to 1 simultaneous ngrok client session.\nActive ngrok client sessions in region 'eu':\n  - ts_1ggVVd2wHWt7Y8eArLEIoNHXEgI (91.65.178.35)\r\n\r\nERR_NGROK_108\r\n"

2020-08-27 16:56:17,697 - octoprint.plugins.ngrok - ERROR - Could not connect with the provided API key

That looks like the previous tunnel wasn't properly closed, and therefore still existed on the NGROK server side and wouldn't allow you to create a second one. You might have to log in to the NGROK dashboard and kill the tunnel manually.

Thanks for the partial logs. Thus tells me a little what happened. A more complete log might give me an indication of why or how it happened so I can try to reproduce the issue and fix it.

Well i thought this was enough information. But here you go.
octoprint.log (134.0 GB)
Does a function exists were you can terminate a tunnel?

You can always close the tunnel from the ngrok.io dashboard. However I will try to detect orphan tunnels in a future version.

Hey fieldOfView, I recently downloaded this plugin and I think its great! I am having one issue that i haven't been able to figure out.

The live stream of the webcam is inaccessible on WAN, but works on LAN.
I've used a few different URLs to try and get it to work.
http://127.0.0.1:8080/?action=stream
http://192.168.0.xxx:8080/?action=stream
http://ender3.local:8080/?action=stream

all work locally but not through the tunnel for some reason. Any tips?

Have you tried a relative URL, ie /webcam/?action=stream

Yup no luck

Yeah, I remembered this issue after writing that reply...

Ah thanks! I'm using raspian with octoprint so i dont have a proxy set for the cam. i'll give it a go and see what happens.

Setting up a proxy so that both OctoPrint and the webcam are accessible from the same port (which is not the native OctoPrint port) is indeed the way to go. This will allow you to have a single configuration that works both locally and through the ngrok tunnel. It is also how OctoPi comes by preconfigured.

So this is the exact config i'm using for my ha proxy.

global
        maxconn 4096
        user haproxy
        group haproxy
        daemon
        log 127.0.0.1 local0 debug

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        option http-server-close
        option forwardfor
        maxconn 2000
        timeout connect 5s
        timeout client  15min
        timeout server  15min

frontend public
        bind *:80
        use_backend webcam if { path_beg /webcam/ }
        default_backend octoprint

backend octoprint
        option forwardfor
        server octoprint1 127.0.0.1:5000

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8080

for the webcam URL setting i'm using

/webcam/?action=stream
1 Like

So @fieldOfView I have a standard octopi setup and I experience the same thing using haproxy and the relative URL to webcam address. Haven't really dug into it much since I personally connect differently.

The ngrok plugin looks at what publicPort is configured to use in the discovery section of the settings. For OctoPi, this is normally set to port 80. For manual installs, it is normally set to port 5000. Port 5000 skips the reverse proxy, so the webcam "redirect" is also requested from port 5000. Could you try setting the publicPort to 80? You may have to manually edit config.yaml for that.

Thanks for that information @fieldOfView. It seems that has to be manually set, even in default octopi instance, because the default setting within OctoPrint based on this is that it will use the port OctoPrint was started on, which by default is 5000.