def capture(): if is_raspberry_pi(): non_frex_shot("capture.jpg") with open("capture.jpg", "rb") as f: b64 = base64.b64encode(f.read()) return "data:image/jpeg;base64," + b64
def get_hw_id(): if not is_raspberry_pi(): return str(hex(get_mac())) if os.path.exists('/home/pi/serial.txt'): with open('/home/pi/serial.txt', 'r') as f: return f.read().strip() r = requests.get("https://www.uuidgenerator.net/api/version4") uid = str(r.content) with open('/home/pi/serial.txt', 'w') as f: f.write(uid) return uid.strip()
def init_video_stream(self): LOG.info(f"Video stream resolution: {self.resolution}") import imutils.video if utils.is_raspberry_pi(): LOG.info("Running Raspberry Pi") self.capture = imutils.video.VideoStream( usePiCamera=True, resolution=self.resolution) else: LOG.info("Running regular x86") # self.capture = cv2.VideoCapture(0) self.capture = imutils.video.VideoStream( resolution=self.resolution) # start video capture thread self.capture.start() # Warmup time time.sleep(1)
from utils import is_raspberry_pi PORT = '5556' SERVER_ADDRESS = 'localhost' CAMERA_PORT = 0 IS_RASPBERRY_PI = is_raspberry_pi() RESOLUTION_H = 320 RESOLUTION_W = 320 GPIO_SWITCH = 24
cv2.resizeWindow("ctrl", 300, 100) cv2.moveWindow("ctrl", 500, 35) cv2.moveWindow("Security Feed", 0, 0) # TODO: @afel # 1. Rewrite to use imutils.videostream.VideoStream() # 2. Track FPS / utilization # 3. Figure out GUI for creating mask / bounding box # 4. CircularBuffer to keep X-seconds of video in memory to-be dumped to disk # 5. Write to a date based folder structure fps = imutils.video.FPS() print("Creating videostream") # Start videostream is_raspberry_pi = utils.is_raspberry_pi() vs = imutils.video.VideoStream(usePiCamera=is_raspberry_pi, resolution=resolution) print(f"Starting videostream.. is_raspberry_pi={is_raspberry_pi}") vs.start() # Start timing frames fps.start() # capture frames from the camera while True: frame = vs.read() if frame is None: print("NO frame - re-trying..") for i in range(50): frame = vs.read()
urllib.request.urlopen(req, payload_bytes) return make_response({"File saved successfully with id: ": file_id}) """ Datanode - Download file data Endpoint: GET /read/[fileID] Request body: Empty Response: Binary file contents """ @app.route('/read/<int:file_id>', methods=['GET']) def read_file(file_id): filename = "{}/file-{}.bin".format(data_folder, file_id) file_contents = None with open(filename, "rb") as f: file_contents = f.read() return send_file(io.BytesIO(file_contents), mimetype='application/octet-stream') # Start the Flask app (must be after the endpoint functions) host_local_computer = "localhost" # Listen for connections on the local computer host_local_network = "0.0.0.0" # Listen for connections on the local network port = 9000 if utils.is_raspberry_pi() else random.randint(9000, 9500) print("Starting Datanode on port %d\n\n" % port) app.run(host=host_local_network if utils.is_raspberry_pi() else host_local_computer, port=port)
def close_shutter_route(): if is_raspberry_pi(): close_shutter() return "OK"
def open_shutter_route(): if is_raspberry_pi(): open_shutter() return "OK"
import socket import dweepy import time import threading import argparse import requests import base64 import os import random from utils import get_thing, is_raspberry_pi from uuid import getnode as get_mac from flask import Flask, jsonify, send_file if is_raspberry_pi(): from pishot import non_frex_shot, open_shutter, close_shutter app = Flask(__name__) def get_ip(): """Gets the IP address as a string. ty https://stackoverflow.com/a/1267524 """ return (([ ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.") ] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]])