Search code examples
pythonflaskraspberry-pi3ip-address

Accessing IOT raspberry pi outside of network using flask with Gunicorn


I’ve looked through this forum and couldn’t find a clear answer to helping my situation.

To explain: I’m currently trying to develop an IOT device that mainly consists of a raspberry pi 3. As it’s for a start up business idea I want to reduce costs and not have a server on the cloud.

I thought it would be a good idea to have flask run with gunicorn on the pi and this would be accessed by a desktop app or mobile app that would know the IP address of the pi as well as it’s flask endpoints.

I wanted the pi to be accessible from any other network (not just its local one). I have host on “0.0.0.0” and port 5000 for development but can’t access it through my mobile network.

I have seen similar posts mentioning ngrok (which might make data less secure?). I’ve seen that I might have to forward the port of the pi to the router. But I think this might involve accessing the router set up. And I don’t want to have to do this for every new client.

I have checked other posts on the forum but can’t seem to find what I’m looking for.

Can I ask this forum if my understanding is correct? Can anyone help me out?

Any advice would be greatly appreciated!


Solution

  • If I understood the problem correctly,

    If you want to connect to your raspberry pi remotely you should know the IP address of your raspberry pi and need port forwarding. After that, you can connect to your raspberry pi with a public ip address. For example publicraspberrypiaddress:5555 (which port are you using)

    Ngrok gives a random subdomain for connection so I don't know how you recognize the ngrok url when device is not near of you.

    Alternatively, you can use cotunnel. It gives static url and the device appears on the cotunnel dashboard so you can manage your raspberry pi remotely with ssh terminal too.

    Or you should develop your own tunnel-like service, or change your project structure. I don't know another way.