#!/usr/bin/python # -*- coding: utf-8 -*- import io import socket import struct import time import picamera import gzip import fcntl import sys import threading from Motor import * from servo import * from Led import * from Buzzer import * from ADC import * from Thread import * from Light import * from Ultrasonic import * from Infrared_Obstacle_Avoidance import * from threading import Timer from threading import Thread from Command import COMMAND as cmd class video: def __init__(self): self.PWM=Motor() self.servo=Servo() self.led=Led() self.ultrasonic=Ultrasonic() self.buzzer=Buzzer() self.adc=Adc() self.light=Light() self.infrared=Infrared_Obstacle_Avoidance() self.Mode = 'one' self.sonic=False self.Light=False self.Power=False def get_interface_ip(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', "wlan0"[:15]))[20:24]) def StartTcpServer(self): HOST=str(self.get_interface_ip()) self.server_socket1 = socket.socket() self.server_socket1.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1) self.server_socket1.bind((HOST, 5000)) self.server_socket1.listen(1) self.server_socket = socket.socket() self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1) self.server_socket.bind((HOST, 8000)) self.server_socket.listen(1) print('Server address: '+HOST) def StopTcpServer(self): try: self.connection.close() self.connection1.close() except Exception , e: print "No client connection" def Reset(self): self.StopTcpServer() self.StartTcpServer() self.SendVideo=Thread(target=self.sendvideo) self.ReadData=Thread(target=self.readdata) self.SendVideo.start() self.ReadData.start() def SocketAccept(self): self.connection1,self.client_address1 = self.server_socket1.accept() self.connection,self.client_address = self.server_socket.accept() self.connection=self.connection.makefile('rb') def sendvideo(self): try: self.connection,self.client_address = self.server_socket.accept() self.connection=self.connection.makefile('rb') except: pass try: with picamera.PiCamera() as camera: camera.resolution = (400,300) # pi camera resolution camera.framerate = 15 # 15 frames/sec time.sleep(2) # give 2 secs for camera to initilize start = time.time() stream = io.BytesIO() # send jpeg format video stream for foo in camera.capture_continuous(stream, 'jpeg', use_video_port = True): try: self.connection.write(struct.pack(' 600: break stream.seek(0) stream.truncate() except: break self.connection.write(struct.pack('