Things used in this project

Code

Initialize two major objects at firstPython
 
camera = picamera.PiCamera()
notificationHandler = NotificationHandler(PUSHBULLET_KEY,didReceiveCommand)
 
def main():
	global isMotionDetected
	global notificationHandler
	logging.info("### Initialize Camera")
	cameraInitialize()
	pushData = {'type': 'TEXT_MESSAGE', 'text': 'PiCameraNotifier app starts !'}
	notificationHandler.pushToMobile(pushData)
 
Camera InitializePython
 
def cameraInitialize():
	logging.info("cameraInitialize: for (1) motion detection, and (2) circularIO recording")
	global camera
	# for motion detection 
	motionAnalysisPort=2
	camera.start_recording(
				'/dev/null', 
				splitter_port=motionAnalysisPort,
				resize=(640,480),
				format='h264',
				motion_output=DetectMotion(camera, size=(640,480))
				)
	# for circularIO recording
	HDVideoRecordPort=1
	global stream
	camera.start_recording(
				stream,
				format="h264", 
				resize=(640,480),
				splitter_port=HDVideoRecordPort)
 
Detect MotionPython
 
class DetectMotion(picamera.array.PiMotionAnalysis):
	def analyse(self,a):
		global isMotionDetected
		a = np.sqrt(np.square(a['x'].astype(np.float)) + np.square(a['y'].astype(np.float))).clip(0, 255).astype(np.uint8)
		if(a > 60).sum() > 10:
			logging.info("motion just detected")
			isMotionDetected = True
			didDetectMotion() 
		else: 
			isMotionDetected = False
 
def didDetectMotion():
		global isRecordingMotion
		if isRecordingMotion:
			print("is Recording Motion ...")
		else: 
			isRecordingMotion = True
			print("start Recording Motion ...")
			global notificationHandler
			global camera
			pushData = {'type': 'TEXT_MESSAGE', 'text': 'Hey! someone sneak into your room. Check it out!'}
			notificationHandler.pushToMobile(pushData)
			fileName=time.strftime("%Y%m%d_%I:%M:%S%p")  # '20170424_12:53:15AM'
			logging.info("push image...")
			captureImage(fileName)
			camera.wait_recording(7)
			writeVideo(fileName)
			isRecordingMotion = False
 
At command receivedPython
 
def didReceiveCommand(command):
	global notificationHandler
	if command == "@check":
		logging.info("get system info")
		process = subprocess.Popen([ WORKING_DIR + 'systemInfo.sh'], stdout=subprocess.PIPE)
		out, err = process.communicate()
		pushData = {'type': 'TEXT_MESSAGE', 'text': out}
		notificationHandler.pushToMobile(pushData)
	if command == "@snap"	:
		fileName=time.strftime("%Y%m%d_%I:%M:%S%p")  # '20170424_12:53:15AM'
		captureImage(fileName)
	else: 
		logging.info("Command not supported: " + command)
		logging.info("send notification to response")
 
init push managerPython
 
	def __init__(self, pushBulletAPIKey,didReceiveCommand):
		# Setup pushBullet manager	
		self.pushBulletAPIKey = pushBulletAPIKey
		self.didReceiveCommand = didReceiveCommand
		self.pushBulletManager = Pushbullet(self.pushBulletAPIKey)
		thread = Thread(target = self.__createListener)
		thread.start()
		# Setup Notification Queue 
		self.__setupNotificationQueue()
 
At command receivedPlain text
 
[Unit]
Description=My Sample Service
After=multi-user.target
 
[Service]
Type=simple
ExecStart=/home/pi/Desktop/PiCameraNotifier/main.py
 
[Install]
WantedBy=multi-user.target
 
Github
https://github.com/iotbreaks/PiCameraNotifier

Credits

Geoguard sxuvotrmxk
Kenny Ho

IoT fullstack engineer

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Chicken Coop Livestream
Easy
  • 2,529
  • 10

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

Test Your Internet Speed Using a Raspberry Pi + Ubidots
Easy
  • 284
  • 4

Protip

Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Raspberry Pi Shutdown / Restart Button
Easy
  • 5,176
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

DIY Raspberry Pi Indoor Outdoor Webcam
Easy
  • 1,444
  • 6

Full instructions

Ever want to monitor your home but don't want to buy a $100 1080p webcam? Well I did, and you can too!

3d printed case for a RaspPi 3, an Arduino and a 5" display
Easy
  • 298
  • 4

Full instructions

A simple and compact frame to mount a 5" monitor, a Raspberry Pi, an Arduino, and a battery, which is extensible for other sensors.

DYI hydroponics system powered by UniPi
Easy
  • 1,401
  • 10

Full instructions

DYI cloud connected hydroponics system powered by UniPi and Cloud4RPi

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog