Connect RaspberryPi to Localhost(127.0.0.1) - python

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!

Related

How to connect Rpi via websockets python

I am trying to connect my raspberry pi to my computer via websockets python. The server is running on the computer and the client on the Rpi. The two of them are connected to the same Wifi network.
When I run the client side on the Rpi I can't connect it to the server.
I am running the server on 0.0.0.0:8000 and I get this Error:
Errno111 Connect call failed ('0.0.0.0', 8000)
Do you know if there is a thing I need to do to be able to connect them? For info, the server and the client can connect when they are running on the same computer but different terminals.
Thanks in advance

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

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.

I can make HTTP Post requests through my laptop put not through Raspberry Pi connected to my laptop

I am using a Raspberry Pi connected to my laptop through an Ethernet cable.
I am using Python Requests to make HTTP POST requests to my server which is on the same network.
The Request works using both postman and the python requests module, when I use it on my laptop.
For some reason the same doesn't work when trying to post the request using my Raspberry pi which I have connected to my laptop through an Ethernet cable and have SSH'd into.
Could there be a firewall issue here, I get an error saying:
requests.exceptions.ConnectionError: ('Connection aborted.', error(113, 'No route to host'))
I have tried both the URLlib and request libraries, both give me this error.
This is a network configuration issue. Your Raspberry PI needs a default gateway setting in the routing table. Take a look at the network configuration of your laptop and check the gateway setting, use the same for the Raspberry PI and make sure you can ping the gateway form the Raspberry PI.

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.

Client server communication over hosted network

Okay I'm a bit new to network programming. We have a site running over a hosted network with a static IP. We want to send some information to the client's PC who connects or logs into the website. Normal sockets are not working as we're getting an error 'refusing connections'. The sockets work in the same subnet but not over internet. How do we connect to the client's computer via server. Are there any libraries for that? Plus the server needs to serve multiple clients who are connected.

Categories

Resources