Approaches to automatic Plug and Play Raspberry PI WebSockets - python

This question is more about advice on how to approach the best solution and possible frameworks to look at.
Desired Result
I am currently attempting to create a very basic plug and play raspberry-pi which can be controlled via an API to perform various tasks such as stream a webcam or turn an led on. The device should connect to anyway wifi and automatically be able to be controlled by the API.
Current Problem
The goal of the app is to create a very easy to use plug and play solution. However I am running to to problem when trying to create a WebSocket on the PI as I cannot seem to be able to access it from an external network. I have looked into automatic port forwarding solutions such as UPnP however all of the results are extremely old. I have also thought about creating the Python WebSocket on a cloud server and use the PI as the client to connect and pass data. Please correct me if I am wrong, however this method does not seem very scalable when there are 10s/100s/1000s of pi's connecting to the same socket.
Any advice would be greatly appreciated.

Related

How to create a chat room over internet with raspberry pi and python

I have a bit of an open ended questions for you all. I wish to create a simple chat-room such as this example here: https://www.geeksforgeeks.org/simple-chat-room-using-python/ but I am lost as how to do it over the internet rather than just local network.
Any pointers/help would be appricated!
Thanks :)
There are multiple ways about this. You can either:
Run locally and expose your Python chat system to the internet.
Run your Python chat system in some online server provider (Heroku, AWS, etc.).
The first method requires you to do some port-forwarding on your local network, essentially mapping your 127.0.0.1:8081 local server to your public IP (so you would connect via the internet as myip:8081). This method, however, comes with its limitations; when you turn off your computer you are also effectively turning off your server to the rest of the internet. The second method will ensure the server stays on at all times, and is likely what you are looking for. Heroku is a great starting point as they provide a free tier that you can test everything out.

Communication Between Processes and Machines Python

I'm struggling to design an efficient way to exchange information between processes in my LAN.
Till now, I've been working with one single RPi, and I had a bunch of python scripts running as services. The services communicated using sockets (multprocessing.connection Client and Listener), and it was kind of ok.
I recently installed another RPi with some further services, and I realized that as the number of services grows, the problem scales pretty badly. In general, I don't need all the services to communicate with any other, but I'm looking for an elegant solution to enable me to scale quickly in case I need to add other services.
So essentially I though I first need a map of where each service is, like
Service 1 -> RPi 1
Service 2 -> RPi 2
...
The first approach I came up with was the following:
I thought I could add an additional "gateway" service so that any application running in RPx would send its data/request to the gateway, and the gateway would then forward it to the proper service or the gateway running on the other device.
Later I also realized that I could actually just give the map to each service and let all the services manage their own connection. This would mean to open many listeners to the external address, though, and I'm not sure it's the best option.
Do you have any suggestions? I'm also interested in exploring different options to implement the actual connection, might the Client / Listener one not be efficient.
Thank you for your help. I'm learning so much with this project!

How to communicate between client device and webserver?

I've build a little device based on the raspberry pi. Now I want to configure it using my web server. The idea is that I enter all the details on my django web page and then the device just pulls that off the server.
But there are two problems I'm not sure how to solve:
I have multiple devices for multiple users so some kind of Login must be provided.
The device also sends pictures from time to time. Right now it's using FTP with a general login, but I want to personalize that too for every device. The uploads will need a resume function so http is out!
So the basic question is: Should I get started with sockets or is there a better and safer way to do it? Maybe there is some kind of open source library that's been tested a lot?
Instead of hand coding sockets, I would suggest using HTTP with BASIC authentication to communicate between the device and the web server. You can uniquely assign an id/pwd to each device, and BASIC authentication is well supported by all web servers and client side libraries.
There are some security concerns with BASIC authentication even if you use HTTPS, but it maybe acceptable in your particular case here.
Maybe you could use SSH, with Fabric for instance. Here an example.

How to send wireless sensor data through a firewall bidirectionally without opening a port using Python?

I'm new to this forum and relatively new to python but have been playing around with sockets/google app engine/django etc… I'm at a loss on how to best design this app and what tools to use for it. Any people with more exp
Hardware: I have a Raspberry Pi behind a firewall that collects wireless sensor data. I would like to access that data from an outside web server (aka google app engine or ec2 server).
Goal: The goal is to have users in different homes (like my mom, grandpa etc living separately with their own pi's) be able to check their data on the web on a centralized server. I should also be able to initiate actions on the Pi's so the data should be sent bi-directionally. Ideally without having to open up firewall ports (dummy proof).
What I did so far:
I was able to create sockets on the PI to send data to a django server (ec2) but I had to open ports for that.
Questions:
I'd like to do this with python, no open ports, bidirectional data.
How do you deal with failsafes such as:
The internet going down.
Missing server readings.
Power outages.
Could this be solved just by syncing a database between the Pi and web server?
I realize this is a very broad question but perhaps it's less about the exact tools and more about the techniques one would use for this particular type of project? Tools, techniques, paradigms or general experiences are all welcome.
Thanks everyone,
David

making IM program - am novice - how to connect to individual computer, not on LAN- using Python 3.2?

I was wondering if you could help me with some programming. I'm trying to write a chat program but i'm stuck. I can use LAN easily enough, but I cant do it over WAN / the Internet as an external IP-address only refers to the Lan/router. how can you connect to one computer in particular?
I'm trying to write in Python, but ive ran into a problem. i'm using a very basic client-server system using the socket module for both (so far).
The problem i'm having is that, while connecting over LAN is easy enough, i need to connect over the internet to one computer. This is because the external IP is only referring to the router. I know i could use probably port-forwarding but i was wondering if there was a way to reach the individual computer without the user manipulating router settings.
There's something called NAT Traversal. But it's not standard at all and there are may ways to do it, depending on the router vendor and other things. So it's a very complex thing to implement in a generic manner.

Categories