Raspberry Pi - Access remote IP address from external website / python app - python

I have an app running on my Raspberry Pi 3b+ on an internal IP address of http://192.168.1.8/app/
http://192.168.1.8:8080/app/
I would like to be able to access this from a remotely hosted python script on Heroku.
Currently I have the script running locally on my laptop, but only works when Im on the same internal network. I would like to have the python script running remotely so I can be away from the Pi and it still runs.
I ran all the usual whatsmyIP.com tools, and have the remote IP, but its the external IP of my router, not the Pi.
Does anyone have any suggestions of how I could make this work?
Thanking you in advance of any advice you can provide.
All the best,
Simon

You should look at Port Forwarding. Which port you forward depends on the settings of your RPi and your application. Enabling port forwarding is different for all routers, but you can normally access the routersettings by navigating to 192.168.0.1 or 192.168.0.0 on your computer.
Doing so allows a connection directly from your Pi to the outworld internet.
You should also take into account that your public IP is prone to change. That's because Internet Providers typically use dynamic IP addresses rather than static IP addresses. Some do provide them when specifically asking for one, often you have to pay a small monthly fee. You should therefore include a script where your raspberry pi updates you about any public IP changes, or use a DDNS service provider.

Related

Connect RaspberryPi to Localhost(127.0.0.1)

I am trying to connect Pi to my local server, but it doesn't work when I type 127.0.0.1 on pi's browser.
I have created a flask web server at 127.0.0.1:5000 on my PC, and several websites are attached. (I have to set up the web server outside the Pi since I run multiple OpenCV applications on the server, and Pi is too slow to run it.) Pi connected to the Ethernet, and I knew its IP address (ex:123.456.789.0). I run a python script with socketio on Pi, and I want the python script to communicate with the flask web server. How can I do that? Be simple, how to control(communicate) raspberry (CAM, GPIO) from an outside network with a web server.
Now the Pi and PC are NOT under the same network. Their IP addresses are totally different, but I can make them under the same network (ex. Pi:192.168.0.1, PC:192.168.0.2) if it is needed.
Thank you!

Make python Flask application accessible from the Internet with gunicorn

what I have:
I made a simple web application using Flask, which woks great on the localhost.
what I want to achieve:
I want to deploy it so it is visible in the internet.
Because Flask says that the production server should not be used for deployment I installed gunicorn.
I managed to get it working on localhost (running gunicorn server:app).
Then I tried to make it public using the -b 0.0.0.0:5000 option. it said it is running on 192.168....:5000 Now I could access the website using that ip address from my computer and also from my phone connected to the same wifi. however I was unable to connect to the website when I didn't use this wifi.
when I searched about this, I found out that the 192.168.... ip address range is reserved to the local network and cannot be accessed from anywhere else.
how do I need to run the script so it is accessible from everywhere? Do I need to modify the firewall settings? Maybe there is a better way to deploy such an app on the local machine using a different framework?
Just some additional information:
python version: 3.9
I am using a venv (and installed flask and gunicorn into it)
os: macos 11.6.1 (I could run it on an Ubuntu machine if that is easier)
This question isn't anything related with Python or Gunicorn but to networking (so maybe StackOverflow isn't the correct place to ask but other community like ServerFault)
Currently your application is already exposed on your machine in the defined port, so next step would be to forward all the traffic that comes to your router to there.
In order to do that, you will have to configure the firewall of your router to accept incoming traffic through a desired port and finally forward the traffic which comes from that port to your machine in the port 5000.
Also, in the case that you have everything already configured, it will only work if your ISP is providing you a single IPv4, what currently doesn't happen anymore but you actually are sharing that with few more people. Other option would be that you configure IPv6 incoming traffic.
As you can see, this isn't a simple task neither one that should be done without proper care, since you would be literally opening your network to possible attackers.
So, in order to simplify it at the most for you, since you already have Gunicorn, I would recommend you to use any of the resources exposed by other users as Heroku or Netlify which are free for a single application and will fulfill your expectations without requiring high amount of networking knowledge.
You would need to do the following steps:
read up and learn a lot about security for Web servers, then read some more, it is fraught with risks
find your Mac's IP address on your local network and make sure it is fixed, i.e. set as static on your Mac (under "System Preferences->Network") or reserved in your router's DHCP tables (by putting your Mac's MAC address in its allocation tables) so that it always gets the same local address on your internal network when it boots
log into your router and set up "Port Forwarding" to forward external requests (coming from the Internet) for port 5000 (or some other port) to your Mac's fixed IP address and the port 5000 where Gunicorn is serving
log into your router and find your WAN IP address, or go to http://whatsmyip.com to get the address you need to put in your browser, or your friends need to put in their browsers to see your shiny new website
as it stands, this will work until the next time your router reboots when your ISP will likely allocate it a new IP address. If you want it permanent, you need to either 1) ask your ISP for a static IP address, or 2) subscribe a DDNS service (e.g. noip.com or dyndns.com) or 3) tell your friends your new IP address every time you reboot your router
I do not know anything about gunicorn. But what I used to use when needing to deploy a flask app was pythonanywhere. They have a great and totally free hosting service. It's really fast in deploying, needs no resources from your computer and is just great. Also you would have to forward the port 5000 for your computer to enable other devices not in the same network to access your computer/flask app. That comes with security issues. However, you do not need any of that when using pythonanywhere.
There are also other great hosting services like that one. It's just the only one I know and used yet but you'll find others for sure if you don't like that one.

How can I acces to my database in localhost from android - Kivy/Python

I'm working on a project using Kivy/Python and PostgreSql so I faced a problem I don't know how can I access to my database from android, (localhost) in laptop it works good but on android phone I don't know how can I access to localhost, I tried to deploy my app to my phone using USB cable. what I should please can someone give me an idea about it. Thanks
Localhost is used to access the network services that are running on the host via the loopback network interface. So no other devices can connect to it.
One solution for you to be able to access your database from your phone is by enabling the database to listen on all interfaces. This can be enabled by changing postgresql.conf listen_addresses in postgresql.conf which allows incoming connections on all available IP interfaces.
listen_addresses = '*'
Make sure you restart the postgres process after changing the configuration.
If your phone is on the same network then you can set the project setting to the computer IP address that is running postgres.

Forward a FTP port via UPnP in Python

I am making a Python application that requires the server to have an FTP port forwarded to his computer(a Rasberry PI3) in order to communicate with client. The current implementation works quite great, yet the only thing is that the person who's running the file must forward the port to the local IP manually. I want to automate this. I have serached a lot but i didnt find anything.

How to host a flask web app on my own pc?

Im developing an app using flask framework in python, i wanted to host it on my pc for a few people to be able to visit it, similar to wamps put online feature but for flask instead, i dont want to deploy it to the cloud just yet. how can i do it.
Enable port forwarding on your router, start flask on the 0.0.0.0 address of your computer, set the forwarded port to be the one started on your laptop. This will now allow your LAN and calls to your ISP provided address to be directed to your laptop.
To clarify, LAN can do it without port forwarding in my experience.

Categories

Resources