Created
February 18, 2021 08:07
-
-
Save Nekodigi/a398a1f95be2686957426b3eba092ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#based on this site http://thezanshow.com/electronics-tutorials/raspberry-pi/tutorial-30 | |
#Please run on your raspberry pi. | |
#This code is client side. | |
from time import sleep, time | |
from picamera import PiCamera | |
import socket | |
from io import BytesIO | |
PORT = 5560 | |
ADDRESS = "XXX.XXX.XXX.XXX"#server ip | |
#setup camera and socket | |
camera = PiCamera() | |
camera.resolution = (640, 480) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#take picture | |
startTime = time() | |
pic = BytesIO() | |
camera.capture(pic, format='jpeg') | |
pic.seek(0) | |
print("camera time:"+str(time()-startTime)) | |
#send picture | |
print("sending picture") | |
startTime = time() | |
s.connect((ADDRESS, PORT))#connect to server | |
print("connect done") | |
s.send(str.encode("STORE "))#send store signal | |
chunk = pic.read(1024)#split and send image | |
while chunk: | |
#print("Sending Picture") | |
s.sendall(chunk) | |
chunk = pic.read(1024) | |
pic.close() | |
s.close() | |
print("done sending"+str(time()-startTime)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment