Hello Rui I have a question concerning making ngrok boot automatically and forward my esp32 password protect webserver so its accessible from anywhere using the raspberry pi. Following the pc instructions that are contained in the esp32 password protect websever tutorial, I am able to create a tunnel and it runs the webserver without a problem. But I want to use raspberry pi as the engine for ngrok. I installed ngrok on raspberry pi no problem and using the instructions for creating a pc tunnel with raspberry pi Im able to create a tunnel no problem. But when I try to make the raspberry pi boot ngrok automatically the tunnel is not created and I cant access my esp32 webserver using the tunnel id created when I use the pc instruction that creates a successful tunnel to the esp32 webserver.
Below I have listed the instructions that I followed from questions asked in the forum on this subject to try an make the raspberry pi boot ngrok automatically. If you could kindly follow along my instructions and possibly lead me in the right direction to create a raspberry pi automatic boot of ngrok, and ngrok run in background tunnel for my esp32 webserver I would greatly appreciate it.
Thanks In Advance for any help you can offer.
Steps I Followed:
- Install Ngrok on Raspberry pi
SSH into your Raspberry Pi or open terminal on your Raspberry pi and execute following commands one by one.
cd /home/pi
sudo wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
unzip ngrok-stable-linux-arm.zip
sudo chmod +x ./ngrok
./ngrok help
If everything goes fine, you should see ngrok help instruction printed on your terminal.
((NO PROBLEM WITH THIS STEP))
- Make ngrok run on boot in background
sudo apt install screen
Then, if you would run the ngrok software with:
screen -d -m ./ngrok http -auth=”user name:password” 8888
You wouldnt see anything in the Terminal, but your tunnel would be running in the background.
((Im confused with this step because how does ngrok know what the ip address is of the webserver to forward with just my ngrok account user name and password))
In order to start ngrok in the boot, you need to edit the file .bashrc:
sudo nano /home/pi/.bashrc
Scroll to the end of that file and add this next line:
screen -d -m /home/pi/./ngrok http -auth=”user name:password” 8888
((Again how does raspberry pi and ngrok create a successful tunnel with just the user name and password for my ngrok account))
((I also change the Port Number from 1880 to 8888 since 8888 is the Port Number the Esp32 protected webserver uses from the tutorial. Im not sure if that was a correct change to make either.))
If i open up a terminal in raspberry pi desktop, and enter the following instructions the tunnel is created successful but it doesnt start automatically if I reboot the raspberry pi.
sudo ./ngrok authtoken 4LiBSnzZLnE7jF92GxQoq_6k77pDYmMw9U3uDtwUBCN
sudo ngrok tcp 192.168.1.73:8888 –authtoken 4LiBSnzZLnE7jF92GxQoq_6k77pDYmMw9U3uDtwUBCN
Any Help will be appreciated.
Hello Michael,
I hope you are doing well and sorry for taking so long to get back to you, but I could only properly test and give you a solution today.
What’s your ESP32 IP address? is it?
192.168.1.73:8888
Basically, you need to use the screen software, so that your command can be executed in the background. Install it with:
sudo apt install screen
I’ve had few weird issues with other methods to auto start on ngrok on boot.
t’s not ideal method, but you probably won’t be opening multiple SSH connections… So you can use the .bashrc method:
sudo nano /home/pi/.bashrc
Scroll to the end of that file and add this next line:
screen -d -m /home/pi/./ngrok tcp 192.168.1.73:8888 –authtoken 4LiBSnzZLnE7jF92GxQoq_6k77pDYmMw9U3uDtwUBCN
Control+X, then Enter and Y. Reboot your Pi and your tunnel should start automatically.
Does it work?
Hello Rui, Thank you for the response to my question, I changed the bash file using the information you gave me and it is now working like a charm. Thank you again for the response to my question and the great ESP32 course.
Hello Rui, one last question on ngrok and raspberry pi. Is it possible to ave 2 tunnels running on ngrok and raspberry pi on boot in the back ground. After reading the ngrok documentation it says you are allow up to 4 tunnels using the free application.
Hello, I’m glad the bash file change made it work! Unfortunately I don’t have any instructions on how to run multiple tunnels, I definitely need to work on something like that. You can do something like this:
- Open/Scroll down to the “Example Configuration Files” heading: https://ngrok.com/docs#config-examples
authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p tunnels: app-foo: addr: 8888 proto: tcp remote_addr: 192.168.1.73 app-bar: addr: 8888 proto: tcp remote_addr: 192.168.1.74
Create a config file, it would be something like this above (it might be missing some parameters), there’s a dedicated table here under “Tunnel definitions”: https://ngrok.com/docs#tunnel-definitions
Then, in the bash, you would run a command that calls that configuration file