Kukano surveillance Raspberry bot
Disclaimer: this is something I stitched together once I was bored during very lazy sunday afternoon, this is not something super pythony cleany.
It should serve as home observation and maybe smart home cam. It is based on Raspberry Pi project for motion detection. I just added detection of home user by Bluetooth device and movement by step motor. I also add some audio features and it plays warnings if it detects noise and no Bluetooth devices around.
Initial version photo:
I used only stepper motor, the light and cam which could be bought from here. Also I bought wide range lens in a local shop for cheap things. It is supposed to be used for a phone camera. Later on I added usb microphone and speaker. There is also Bluetooth dongle, any compatible with RPI would do the trick.
What it actually does
TL;DR:
It loops around. If your Bluetooth device is detected, it turns off, otherwise it rotates after movement and if there
is some noise, it takes a picture and play randomly selected warning from folder warning_sounds
.
I see you are interested in more:
The implementation is in main.py
and there is really nothing fancy there.
It do the trics from the article motion detection
my addition to this was that it also says step motor to move after the movements detected.
In addition to that, it also detects Bluetooth devices and if there is some known device, it stops until the device is gone. Sometimes it takes a while because the detection of the devices happens once a minute.
To do not waste that much space, I later added microphone to allow taking the pictures only if there is some noise.
The assumption in here is that people do make noise once they come to steal something. The warning noises are at
warning_sounds
folder. Those are in turkish, polish, russian, german and english. They were once generated by AWS Polly
service and the languages I picked are related to the location I live in.
The sounds are picked randomly so maybe you can add there farts, your mum screaming at you, your dad saying to get the f out or (that is very cool) the noise for the movie Home Alone.
Configuration
This is just a fun project, do not expect anything fancy, basic config should be found at config.json
. The options are as follow:
{
"audio_threshold": 40,
"audio_device": 2,
"min_motion_frames": 8,
"camera_warmup_time": 2.5,
"delta_thresh": 5,
"downscale_width": 500,
"resolution": [1920, 1080],
"fps": 16,
"min_area": 5000,
"allowed_devices" : ["04:B1:67:09:58:D1", "0C:98:38:00:60:B0"],
"aws_access_key_id" : "XXXXXXXXXXXXXXXXXXXX",
"aws_secret_access_key" : "XXXXXXXXXXXXXXXXXXXX",
"aws_bucket": "kukano",
"aws_region": "",
"backend_url": "https://apipath",
"backend_api_key": "apikey"
}
- audio_threshold: my microphone cought slight sound at some relative level of 40, just fiddle with it
- audio_device: just find it with
aplay -L
, that should be usb device with microphone - min_motion_frames: frames with motion detected to be counted before picture is saved to a folder
- delta_thresh, downscale_width, resolution, fps, min_area are all well explained at the article I used
- allowed_devices - those are bluetooth devices which should turn the cam off once they are online
- aws_access_key_id - key id from aws iam, if set, kukano will try to upload the picture to s3 bucket
- aws_secret_access_key - key secret from aws iam, if set, kukano will try to upload the picture to s3 bucket
- aws_bucket - bucket to push pictures to
- aws_region - aws default region
- backend_url - url to backend, see project https://gitlab.com/kukano/backend
- backend_api_key - api key to backend, see project https://gitlab.com/kukano/backend
Installation
Just keep it at folder /home/pi/surveillance/
and deploy kukano.service
to systemd folder.
The python requirements are following: pyaudio, imutils, opencv, bluetooth, picamera & audioop.
App will save the images into /mnt
folder. This should be changed by configuration in future. I used /mnt
cause
that's where my NAS is mounted to.
Scripts to make it rolling
bt.py
- should help you find the MAC of your BT devices currently online around youdetect_sound.py
- should show you relative level of the sounds caught by the microphone, that's where myaudio_threshold
came fromplay_sound.py
- is a tester for playing a sound, it is actually copy & paste from nice explanation how to play a sound on RPI