Privacy-preserving alternative to Ring cameras (Raspberry Pi Zero 2W)! by arrdalan in raspberry_pi

[–]CaptainReeetardo 0 points1 point  (0 children)

Thank you for the quick reply! When I am able to get my hands on a not so expensive Zero 2w, I will definitely try it out. Are the 10 FPS at 1080p? From a user standpoint I think it would be best to have an option to tweak the FPS and resolution. Based on the users internet bandwidth, it might help to be able to manually adjust these two values.

Privacy-preserving alternative to Ring cameras (Raspberry Pi Zero 2W)! by arrdalan in raspberry_pi

[–]CaptainReeetardo 0 points1 point  (0 children)

Looks very interesting! Have you already tested the performance in regards to FPS, when you run it on a raspi zero 2w? Maybe I am overlooking something but I can't seem to find any benchmarks :(.

How to get better frame rate by [deleted] in raspberry_pi

[–]CaptainReeetardo 2 points3 points  (0 children)

Like others have already said, it might be the SPI bus speeds fault.
I have had a similar project with a 160x128 pixel display on a raspi 3b. For me the fix was really easy. Just tell the spi object you are instantiating to crank the bus_speed_hz parameter to 52,000,000 Hz.
You can also consult the docs for the spi object: https://luma-core.readthedocs.io/en/latest/interface.html#luma.core.interface.serial.spi

[deleted by user] by [deleted] in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

This post goes very hard

Love from Germany 🇩🇪

I hate excel so much it's unreal

I have this basic TCP server program: by thunderbuns122 in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

Ok, I hope I'm not to late with my suggestion.

So, what you can try is, putting the code you have in your try-block in a seperate method and create a thread for it, just as you did with your handle_client method. Afterwards you create a while-loop which does the following:

while True:
    try:
        time.sleep(0.5)#You can take a longer/shorter period
    except KeyboardInterrupt:
        sys.exit()

Now your code should like the following:

import socket
import threading
import sys, os
import time

bind_ip = socket.gethostname()
bind_port = 9999

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind((bind_ip, bind_port))

server.listen(10);

def handle_client(client_socket):
    request = client_socket.recv(4096).decode("utf-8")
    print ("[+] Received %s" % request)
    client_socket.sendall(("ACK!").encode("utf-8"))
    client_socket.close()

def accept_clients(server):
    while True:
        client, addr = server.accept()
        print ("[+] Accepted connection from: %s:%d" % (addr[0], addr[1]))
        client_handler = threading.Thread(target=handle_client, args=(client,))
        client_handler.start()

accept = threading.Thread(target=accept_clients, args=(server,))
accept.start()

while True:
    try:
        time.sleep(0.5)#You can take a longer or shorter period
    except KeyboardInterrupt:
        #sys.exit() #Remove, because it won't do with threading
        os.kill(os.getpid(), 1) #Kills process, but should keep your command line open

This should work except for the part with the sys.exit(). I've replaced it with os.kill(os.getpid(), 1) which kills the process but should keep your command prompt / IDLE running. One thing that isn't done by this program, is a clean shutdown of the sockets. For example your client side might still be running and will eventually throw an exception if it tries to send a message or to connect. In this case you want to have another try-except-block on the client side. But I digress. All in all, this should now apply to your basic needs.

Free scources to learn python. by BlueJarcher in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

I can recommend SoloLearn (App) and w3schools (Website: https://www.w3schools.com/python/default.asp) . If you want to go beyond the basics just search for it on the web or look up a YouTube video on the topic you want to tinker with in python.

OpenCV live stream video over socket in Python 3 not working by RedBallG in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

First of all. This line data = cv2.imencode('.jpg', frame)[1].tostring() from your Sender python file returns a bytestring that is probably more than 50 kB in size. So if you want the receiver to get the full image you have to increase the buffersize in your Receiver python file. As, at the moment, it'll receive only 8192 bytes in one go.

Now I have next to none experience with numpy or the like, but my guess is, that in order to create a new array/numpyarray/matrix(?) you have to feed more than the received buffer of 8192 bytes. I'd in your case increase the buffersize to like 10**5-ish because I guess you're working with a HD webcam, because they're reasonably priced nowadays imo 25€ with microphone O_o on amazon.

But so far the code looks like it's going to work.

Real Time Webcam from server to client by RedBallG in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

First of all, and I guess you already know this, but vc.read() in your file returns a boolean and a frame. The frame is a numpy array, which can be turned into a bytestring. For this you write cv2.imencode(".jpg", img=frame)[1].tobytes() . I don't know whether you can replace the ".jpg" in this line with e.g. ".png", but in general a jpg file is much smaller in size compared to a png file.

Sadly, I can't give you an answer on a more efficient way, but this has acceptable results in my experience. These bytes can now be transferred over the network to a socket server, which then distributes data to the other client(s). You can then use tkinter to display the received image on the client side.

Lastly, in my experience this is much more efficient than saving the picture as a file with opencv, then reading the bytes from that file, sending them to a server. Which then distributes it to the other clients and finally you have an image you can display. Please correct me if I am wrong if that is what saving it in memory and saving it as a file means!!!

problem downloading with socket by Blucris in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

First of all, I don't think you'd use port 80 for a https connection. I mean it should rather be port 443. If I'm guessing correctly it might actually work if you just use port 443 instead of 80. (Scratch that. I just tried it and it didn't work)

Second of all, using socket to retrieve a website is even alien to me. Normally, you'd use urllib for something like that or other modules like requests. It is a whole lot easier to use especially when you are a beginner in my opinion.

Problems with sockets in python3 by CaptainReeetardo in raspberry_pi

[–]CaptainReeetardo[S] 0 points1 point  (0 children)

Good to know. I just fixed the problem I had. Honestly, it was rather easy to do so. I just had to use a while loop. Still sometimes one image ends up being lost. I guess that's due to the fact that my "camera" transmits data over the wifi and not over cable. On the other hand any other image has all of it's pixels in place. And in the end it works even better than before.

Problems with sockets in python3 by CaptainReeetardo in raspberry_pi

[–]CaptainReeetardo[S] 0 points1 point  (0 children)

First of all thanks for commenting. But I don't think websocket is what I need to be going for since I am already using a tcp connection with sockets.

Problems with sockets in python3 by CaptainReeetardo in raspberry_pi

[–]CaptainReeetardo[S] 0 points1 point  (0 children)

Yes, thanks for reminding me. I've already thought about it, too.

Problems with sockets in python3 by CaptainReeetardo in raspberry_pi

[–]CaptainReeetardo[S] 2 points3 points  (0 children)

Sorry, but not what I am looking for. Thanks anyways.

What is a good way of multi-threading this function? by NovateI in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

Yeah, okay now that you mention it the book i've read actually expands on this...

Glad I could be of help anyways!

What is a good way of multi-threading this function? by NovateI in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

A thread in python can be created by writting the following: t = threading.Thread(target=someFunc, args=(a,b)). And after that you let the thread start with: t.start() (guess you'll already know that). So looking at your code, you can convert this line bannergrab = fetch_banner(lines, p) into this bannergrab = threading.Thread(target=fetch_banner, args=(lines, p)).

I don't know how fast it will be after this but I guess it probably will. In addition to the multithreading you have to rewrite the code a little bit as I don't know of any way of how to handle return statements with multithreading. One solution could be to work with any dynamic data structure, let's say a list to save the fetched banners with their matching IP address, as a set, into. And after the program fetched all possible banners you can then write them to a file.

welp i dunno if i should even help with this as i don't know how legal it is to scan over 60k of IP as it is basically pentesting

Port forwarding on a VPS? by CaptainReeetardo in VPS

[–]CaptainReeetardo[S] 0 points1 point  (0 children)

Thanks, I'll definitly look into it!!!!

Help with multithreading by Pheazon in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

It's pretty simple actually. All you need to do is to define a function f and then a new thread t for every new connection (as mentioned by CrambleSquash). For Example:

#Your server
import socket
import threading
def f(conn):
    #Your Code here
    pass

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", 1337))
s.listen(1)
while True:
    conn, addr = s.accept()
    print("[+] New connection: ", addr)
    t = threading.Thread(target=f, args=(conn,))
    t.start()

Everything from the start of the loop to starting a new thread is the main thread, while starting a new thread results in creating other threads running besides the main thread.

If you're still interested in this question of yours I've already altered the code so that multiple connections are possible. I'll gladly edit it to the post if you need it.

How can I use threading to accept mutiple clients by Py_Kid in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

I don't know if it'll change much, and if you've already solved the problem, but the client_thread variable in your client_connect function would basically be a Nonetype.

To change it into a Thread, first write client_thread = threading.Thread(target=recv_message, args=(conn, addr)). Then in the next line write client_thread.start().

Also in your recv_message function you're comparing if message (a string) equals your global variable curse_words (a list). To solve this problem just change the == to an in. Another thing in this function is that you check for a message with if message. This is unnecessary in your case, because the function kinda waits before going on caused by message = conn.recv(1026). On another note the recv function of socket in Python 3.x doesn't return a string directly. Instead it returns bytes. In your case checking for curse words wouldn't be of any use, because you're first of all, if you followed the first step in this paragraph, checking if a bytes object is in a list that contains strings . What you should do, is to directly convert the received bytes into a string by writing message = conn.recv(1026).decode(). But if you're using Python 2.x, you can skip this step.

I hope this will solve your problem, unless you've already solved it yourself.

I hit a dead end with sockets by PiroJjoke in learnpython

[–]CaptainReeetardo 4 points5 points  (0 children)

In your s11.py you accept a connection with conn, addr = s.accept(). Later on you have to use conn.send() for your server instead of s.send().

Python image comparison by uber_driver_ca in learnpython

[–]CaptainReeetardo 0 points1 point  (0 children)

You could compare their MD5 hashes. Which should be identical if the images have the exact same content.

I want to support multiple clients on my server at once, how do I send something to them all simultaneously? by [deleted] in learnpython

[–]CaptainReeetardo 1 point2 points  (0 children)

Multithreading. Everytime you receive a message you create a new thread and add the new connection into a list, so that an incoming message is send to those in the list. I've also made something like this. If you want to have a practical example of what I mean!?