Advertisement
Guest User

hermansindreåse

a guest
Nov 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/usr/bin/python
  2. import os
  3. import pygame, sys
  4. import RPi.GPIO as GPIO
  5. import time
  6. GPIO.setwarnings(False)
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setup(4, GPIO.IN)
  9. from pygame.locals import *
  10. import pygame.camera
  11. import certifi
  12. import slack
  13. import ssl
  14.  
  15.  
  16. width = 640
  17. height = 480
  18.  
  19. #initialise pygame
  20. pygame.init()
  21. pygame.camera.init()
  22. cam = pygame.camera.Camera("/dev/video0",(width,height))
  23. cam.start()
  24.  
  25.  
  26. def send_image(image_path_name):
  27. ssl_context = ssl.create_default_context(cafile=certifi.where())
  28. client = slack.WebClient(token='xoxb-834259584215-832409614400-4ui12uPAbKLRo5yWcbjnI8GE', ssl=ssl_context)
  29.  
  30. #response = client.chat_postMessage(channel='#camera', text="Hello world!")
  31.  
  32. response = client.files_upload(channels='#camera', file=image_path_name)
  33. return response
  34.  
  35. #take a picture
  36.  
  37. while True:
  38. time.sleep(2)
  39. i=GPIO.input(4)
  40. if i==0: #When output from motion sensor is LOW
  41. print("No intruders")
  42. image = cam.get_image()
  43. pygame.image.save(image, 'pic.jpg')
  44. print(send_image("/home/pi/sense/pic.jpg"))
  45.  
  46.  
  47. else:
  48. print("Intruders!!!")
  49. image = cam.get_image()
  50. pygame.image.save(image, 'pic.jpg')
  51. print(send_image("/home/pi/sense/pic.jpg"))
  52.  
  53.  
  54. time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement