Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import pygame, sys
- import RPi.GPIO as GPIO
- import time
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(4, GPIO.IN)
- from pygame.locals import *
- import pygame.camera
- import certifi
- import slack
- import ssl
- width = 640
- height = 480
- #initialise pygame
- pygame.init()
- pygame.camera.init()
- cam = pygame.camera.Camera("/dev/video0",(width,height))
- cam.start()
- def send_image(image_path_name):
- ssl_context = ssl.create_default_context(cafile=certifi.where())
- client = slack.WebClient(token='xoxb-834259584215-832409614400-4ui12uPAbKLRo5yWcbjnI8GE', ssl=ssl_context)
- #response = client.chat_postMessage(channel='#camera', text="Hello world!")
- response = client.files_upload(channels='#camera', file=image_path_name)
- return response
- #take a picture
- while True:
- time.sleep(2)
- i=GPIO.input(4)
- if i==0: #When output from motion sensor is LOW
- print("No intruders")
- image = cam.get_image()
- pygame.image.save(image, 'pic.jpg')
- print(send_image("/home/pi/sense/pic.jpg"))
- else:
- print("Intruders!!!")
- image = cam.get_image()
- pygame.image.save(image, 'pic.jpg')
- print(send_image("/home/pi/sense/pic.jpg"))
- time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement