CAMERA CONTROL
-D 0 U+ -L 0 R+ CONTACT INFORMATION var xmlhttp; xmlhttp = new XMLHttpRequest(); function lighton() { xmlhttp.open("GET","cgi-bin/llighton.cgi",true); xmlhttp.send(); } function lightoff() { xmlhttp.open("GET","cgi-bin/llightoff.cgi",true); xmlhttp.send(); } function forward() { xmlhttp.open("GET","cgi-bin/forward.cgi",true); xmlhttp.send(); } function stop() { xmlhttp.open("GET","cgi-bin/stop.cgi",true); xmlhttp.send(); } function left() { xmlhttp.open("GET","cgi-bin/left.cgi",true); xmlhttp.send(); } function right() { xmlhttp.open("GET","cgi-bin/right.cgi",true); xmlhttp.send(); } function reverse() { xmlhttp.open("GET","cgi-bin/reverse.cgi",true); xmlhttp.send(); } function downtilt() { xmlhttp.open("GET","cgi-bin/downtilt.cgi",true); xmlhttp.send(); } function centertilt() { xmlhttp.open("GET","cgi-bin/centertilt.cgi",true); BỘ MÔN ĐIỆN TỬ CÔNG NGHIỆP- Y SINH 70 PHỤ LỤC xmlhttp.send(); } function uptilt() { xmlhttp.open("GET","cgi-bin/uptilt.cgi",true); xmlhttp.send(); } function leftpan() { xmlhttp.open("GET","cgi-bin/leftpan.cgi",true); xmlhttp.send(); } function centerpan() { xmlhttp.open("GET","cgi-bin/centerpan.cgi",true); xmlhttp.send(); } function rightpan() { xmlhttp.open("GET","cgi-bin/rightpan.cgi",true); xmlhttp.send(); } function audio() { xmlhttp.open("GET","cgi-bin/audio.cgi",true); xmlhttp.send(); } function audiooff() { xmlhttp.open("GET","cgi-bin/audiooff.cgi",true); xmlhttp.send(); } Code HTML THONG TIN LIEN HE SAN PHAM Do An Tot Nghiep MO HINH XE ROBOT GIAM SAT AN NINH HO GIA DINH GVHD: Th.s Nguyen Dinh Phu SVTH: Ngo Duc Huy && Ho Hoai LinhSDT lien he: 0372658952 Gmail: duchuyblues@gmail.com
Code Camera import cv2 from imutils.video.pivideostream import PiVideoStream import imutils import time import numpy as np BỘ MÔN ĐIỆN TỬ CÔNG NGHIỆP- Y SINH 71 PHỤ LỤC class VideoCamera(object): def init (self, flip = False): self.vs = PiVideoStream().start() self.flip = flip time.sleep(2.0) def del (self): self.vs.stop() def flip_if_needed(self, frame): if self.flip: return np.flip(frame, 0) return frame def get_frame(self): frame = self.flip_if_needed(self.vs.read()) ret, jpeg = cv2.imencode('.jpg', frame) return jpeg.tobytes() def get_object(self, classifier): found_objects = False frame = self.flip_if_needed(self.vs.read()).copy() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) objects = classifier.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE ) if len(objects) > 0: found_objects = True # Vẽ khung hình chữ nhật nhận dạng for (x, y, w, h) in objects: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) ret, jpeg = cv2.imencode('.jpg', frame) return (jpeg.tobytes(), found_objects) Code gửi mail import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText from email.MIMEImage import MIMEImage # Email dùng để gửi ảnh fromEmail = 'duchuyblues@gmail.com' fromEmailPassword = 'password' # Email dùng để nhận mail toEmail = 'smarthomecontrol6@gmail.com' def sendEmail(image): msgRoot = MIMEMultipart('related') msgRoot['Subject'] = 'Security Update' msgRoot['From'] = fromEmail msgRoot['To'] = toEmail BỘ MÔN ĐIỆN TỬ CÔNG NGHIỆP- Y SINH 72 PHỤ LỤC msgRoot.preamble = 'Raspberry pi security camera update' msgAlternative = MIMEMultipart('alternative') msgRoot.attach(msgAlternative) msgText = MIMEText('Smart security cam found object') msgAlternative.attach(msgText) msgText = MIMEText('', 'html') msgAlternative.attach(msgText) msgImage = MIMEImage(image) msgImage.add_header('Content-ID', '') msgRoot.attach(msgImage) smtp = smtplib.SMTP('smtp.gmail.com', 587) smtp.starttls() smtp.login(fromEmail, fromEmailPassword) smtp.sendmail(fromEmail, toEmail, msgRoot.as_string()) smtp.quit() Code điều khiển xe, led, buzzer, servo forward #!/bin/bash gpio -g write gpio -g write gpio -g write 13 gpio -g write 19 reverse #!/bin/bash gpio -g write gpio -g write gpio -g write 13 gpio -g write 19 left #!/bin/bash gpio -g write gpio -g write gpio -g write 13 gpio -g write 19 right #!/bin/bash gpio -g write gpio -g write gpio -g write 13 gpio -g write 19 stop #!/bin/bash gpio -g write gpio -g write gpio -g write 13 gpio -g write 19 lighton BỘ MÔN ĐIỆN TỬ CÔNG NGHIỆP- Y SINH 73 PHỤ LỤC #!/bin/bash gpio -g write 10 lightoff #!/bin/bash gpio -g write 10 audio #!/bin/bash gpio -g write audio off #!/bin/bash gpio -g write centerpan #!/bin/bash echo 1=60% > /dev/servoblaster leftpan #!/bin/bash echo 1=90% > /dev/servoblaster rightpan #!/bin/bash echo 1=30% > /dev/servoblaster centertilt #!/bin/bash echo 0=60% > /dev/servoblaster uptilt #!/bin/bash echo 0=20% > /dev/servoblaster downtilt #!/bin/bash echo 0=90% > /dev/servoblaster Code lập trình Esp8266 với cảm biến: #include #include #include "DHT.h" #define FIREBASE_HOST "onoffled-99ed9.firebaseio.com" #define FIREBASE_AUTH "cBYHp5u3Zya3pXRVpoDSLPsLlmXa47foab1EZ81G" #define WIFI_SSID "Redmi" #define WIFI_PASSWORD "88888888" #define DHTPIN D1 //DHT11 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); int smokeA0 = A0; int buzzer = D5 ; //MQ2 BỘ MÔN ĐIỆN TỬ CÔNG NGHIỆP- Y SINH 74 PHỤ LỤC int inputPin = D4; int val = 0; //PIR void setup() { Serial.begin(115200); dht.begin(); pinMode(inputPin, INPUT); pinMode(smokeA0, INPUT); pinMode (buzzer, OUTPUT) ; WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting to "); Serial.print(WIFI_SSID); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("Connected"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); } void loop() { int analogSensor = analogRead(smokeA0); float h = dht.readHumidity(); // Đọc giá trị DHT11 float t = dht.readTemperature(); if(analogSensor>950){ digitalWrite (buzzer, LOW) ; // bật buzzer delay (1) ;} if(analogSensor