Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. from flask import Flask, render_template, Response
  3.  
  4. from camera import Camera
  5.  
  6. import serial
  7. from flask import Flask, render_template, Response
  8.  
  9. from camera import Camera
  10.  
  11. import serial
  12.  
  13. import subprocess
  14.  
  15.  
  16.  
  17. arduino = serial.Serial('/dev/ttyACM0', 9600)
  18.  
  19. app = Flask(__name__)
  20.  
  21.  
  22.  
  23. @app.route('/')
  24.  
  25. def index():
  26.  
  27. return render_template('index.html')
  28.  
  29.  
  30. def gen(camera):
  31.  
  32. while True:
  33.  
  34. frame = camera.get_frame()
  35.  
  36. yield (b'--frame\r\n'
  37.  
  38. b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  39.  
  40.  
  41.  
  42. @app.route('/video_feed')
  43.  
  44. def video_feed():
  45.  
  46. return Response(gen(Camera()),
  47.  
  48. mimetype='multipart/x-mixed-replace; boundary=frame')
  49.  
  50.  
  51. @app.route("/feed")
  52.  
  53. def feed():
  54.  
  55. try:
  56.  
  57. arduino.write('a')
  58.  
  59. return "1"
  60.  
  61. except:
  62.  
  63. pass
  64.  
  65.  
  66. return "0"
  67.  
  68.  
  69. def sendAutostartMail():
  70.  
  71. import smtplib
  72.  
  73. import string
  74.  
  75.  
  76. PASS='pjkrud6839'
  77.  
  78.  
  79. SUBJECT='Feed!!!!'
  80.  
  81.  
  82. ip = subprocess.check_output("hostname -I", shell= True)
  83.  
  84. TEXT = 'your RPs IP addess is %s.\n Please connect here and click Feed' %ip
  85.  
  86.  
  87.  
  88. FROM = USER
  89.  
  90. HOST = 'smtp.gmail.com:587'
  91.  
  92. BODY = string.join((
  93.  
  94. 'From: %s' %FROM,
  95.  
  96. 'To: %s' %TO,
  97.  
  98. 'Subject: %s' %SUBJECT,
  99.  
  100. '\r\n',
  101.  
  102. TEXT,
  103.  
  104. ), '\r\n')
  105.  
  106.  
  107.  
  108. server=smtplib.SMTP(HOST)
  109.  
  110. server.starttls()
  111.  
  112. server.login(USER, PASS)
  113.  
  114. server.sendmail(FROM, TO, BODY)
  115.  
  116. server.quit()
  117.  
  118.  
  119. return null;
  120.  
  121.  
  122.  
  123.  
  124. if __name__ == '__main__':
  125.  
  126. app.run(host='0.0.0.0', debug=True, threaded=True)
  127.  
  128. sendAutostartMail()
  129.  
  130.  
  131. import subprocess
  132.  
  133.  
  134.  
  135. arduino = serial.Serial('/dev/ttyACM0', 9600)
  136.  
  137. app = Flask(__name__)
  138.  
  139.  
  140.  
  141. @app.route('/')
  142.  
  143. def index():
  144.  
  145. return render_template('index.html')
  146.  
  147.  
  148. def gen(camera):
  149.  
  150. while True:
  151.  
  152. frame = camera.get_frame()
  153.  
  154. yield (b'--frame\r\n'
  155.  
  156. b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  157.  
  158.  
  159.  
  160. @app.route('/video_feed')
  161.  
  162. def video_feed():
  163.  
  164. return Response(gen(Camera()),
  165.  
  166. mimetype='multipart/x-mixed-replace; boundary=frame')
  167.  
  168.  
  169. @app.route("/feed")
  170.  
  171. def feed():
  172.  
  173. try:
  174.  
  175. arduino.write('a')
  176.  
  177. return "1"
  178.  
  179. except:
  180.  
  181. pass
  182.  
  183.  
  184. return "0"
  185.  
  186.  
  187. def sendAutostartMail():
  188.  
  189. import smtplib
  190.  
  191. import string
  192.  
  193.  
  194. PASS='pjkrud6839'
  195.  
  196.  
  197. SUBJECT='Feed!!!!'
  198.  
  199.  
  200. ip = subprocess.check_output("hostname -I", shell= True)
  201.  
  202. TEXT = 'your RPs IP addess is %s.\n Please connect here and click Feed' %ip
  203.  
  204.  
  205.  
  206. FROM = USER
  207.  
  208. HOST = 'smtp.gmail.com:587'
  209.  
  210. BODY = string.join((
  211.  
  212. 'From: %s' %FROM,
  213.  
  214. 'To: %s' %TO,
  215.  
  216. 'Subject: %s' %SUBJECT,
  217.  
  218. '\r\n',
  219.  
  220. TEXT,
  221.  
  222. ), '\r\n')
  223.  
  224.  
  225.  
  226. server=smtplib.SMTP(HOST)
  227.  
  228. server.starttls()
  229.  
  230. server.login(USER, PASS)
  231.  
  232. server.sendmail(FROM, TO, BODY)
  233.  
  234. server.quit()
  235.  
  236.  
  237. return null;
  238.  
  239.  
  240.  
  241.  
  242. if __name__ == '__main__':
  243.  
  244. app.run(host='0.0.0.0', debug=True, threaded=True)
  245.  
  246. sendAutostartMail()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement