Skip to content

Commit

Permalink
Notification function (#24)
Browse files Browse the repository at this point in the history
* New docker image for noisedetection

* Update Dockerfile

* Noise detection

* noisedetection

* noisedetection

* noisedetection

* notif

* notif

* notif

* notif

* notif

* notif

* notif

* notif

* notif

* notif

* update temperature.py

* Update temperature.py

* Update temperature.py

* Notification feature

Added a Docker container for notification purpose (based on temperature only for the moment)

* Updated INSTALLATION.md

Updated the instructions for notification feature configuration

* Update INSTALLATION.md

Updated the "Notification function" instructions

* Changed build instructions for notification container

- Based notification image build on the ivadim/fruitnanny image
- Changed the way the container will retrieve the temperature.py script (mounted volume instead of a COPY)

* Updated restart policy

* Added motion sensor to Notification feature

- Created a "configuration" file for notification feature
- Added "motion detection" to Notification feature (being notified when a motion is detected)

* Fixed temperature.py

- Fixed the type of temp_min and temp_max variables
- Uncommented the loop
  • Loading branch information
jeremyfritzen authored and ivadim committed Jan 6, 2020
1 parent 6e1ccd8 commit c894bd3
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 5 deletions.
5 changes: 5 additions & 0 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ openssl passwd -apr1 >> ./configuration/nginx/.htpasswd

`openssl` will prompt for password

### Configure notification function
First, create an account on Pushbullet.com.

Then, set up your own configuration by editing the notification configuration file (available here in the fruitnanny folder: bin/configuration).

### Run the system
```console
cd /opt/fruitnanny
Expand Down
7 changes: 7 additions & 0 deletions bin/configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[NOTIFICATION]
url: http://rpi-nanny.home/
Pushbullet_API_Key: abcdefgh

[TEMPERATURE]
temp_min: 20
temp_max: 20
33 changes: 33 additions & 0 deletions bin/motion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python

import time
import board
import digitalio
from pushbullet import Pushbullet
import configparser

# parsing configuration file
config = configparser.RawConfigParser()
config.read('/opt/fruitnanny/bin/configuration')

# set up motion sensor
pir_sensor = digitalio.DigitalInOut(board.D23)
pir_sensor.direction = digitalio.Direction.INPUT

#set up identification and other variables
pb = Pushbullet(config.get('NOTIFICATION','Pushbullet_API_Key'))
monitor_url = config.get('NOTIFICATION','url')
frequence_notification = 1200

while True:
try:
message = ("Rpi-Nanny : Motion detected!")
print(pir_sensor.value)
if pir_sensor.value:
print("Motion detected")
push = pb.push_link(message, monitor_url)
time.sleep(frequence_notification)
time.sleep(1)
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
43 changes: 43 additions & 0 deletions bin/temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python

import time
import adafruit_dht
import board
from pushbullet import Pushbullet
import configparser

# parsing configuration file
config = configparser.RawConfigParser()
config.read('/opt/fruitnanny/bin/configuration')

# set up temperature sensor
dhtDevice = adafruit_dht.DHT22(board.D24)

#set up identification and other variables
pb = Pushbullet(config.get('NOTIFICATION','Pushbullet_API_Key'))
monitor_url = config.get('NOTIFICATION','url')
frequence_notification = 1200
temp_min = float(config.get('TEMPERATURE','temp_min'))
temp_max = float(config.get('TEMPERATURE','temp_max'))

#print(temp_min)
#print(temp_max)


while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
message = ("Rpi-Nanny : {}°C !".format(temperature_c))
print(message)
if temperature_c > temp_max or temperature_c < temp_min :
#push = pb.push_note("Rpi-Nanny", message)
push = pb.push_link(message, monitor_url)
time.sleep(frequence_notification)
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])

time.sleep(5.0)

#print(message)
43 changes: 38 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
janus:
image: ivadim/fruitnanny-janus
restart: always
restart: "no"
privileged: true
network_mode: "host"
volumes:
Expand All @@ -16,7 +16,7 @@ services:

gstreamer-video:
image: ivadim/fruitnanny-gstreamer
restart: always
restart: "no"
privileged: true
network_mode: "host"
depends_on:
Expand All @@ -30,7 +30,7 @@ services:

gstreamer-audio:
image: ivadim/fruitnanny-gstreamer
restart: always
restart: "no"
privileged: true
network_mode: "host"
depends_on:
Expand All @@ -42,7 +42,7 @@ services:

fruitnanny:
image: ivadim/fruitnanny-app
restart: always
restart: "no"
privileged: true
volumes:
- ./fruitnanny_config.js:/opt/fruitnanny/fruitnanny_config.js
Expand All @@ -55,7 +55,7 @@ services:

nginx:
image: arm32v7/nginx
restart: always
restart: "no"
network_mode: "host"
depends_on:
- janus
Expand All @@ -67,3 +67,36 @@ services:
ports:
- "80:80"
- "443:443"

notification-temp:
build:
context: .
dockerfile: docker/notification/Dockerfile
restart: "no"
network_mode: "host"
privileged: true
volumes:
- /opt/fruitnanny/bin:/opt/fruitnanny/bin
depends_on:
- nginx
- janus
- fruitnanny
#command: /bin/bash
#tty: true
command: python3 /opt/fruitnanny/bin/temperature.py

notification-motion:
image: fruitnanny_notification-temp
restart: "no"
network_mode: "host"
privileged: true
volumes:
- /opt/fruitnanny/bin:/opt/fruitnanny/bin
depends_on:
- nginx
- janus
- fruitnanny
- notification-temp
#command: /bin/bash
#tty: true
command: python3 /opt/fruitnanny/bin/motion.py
13 changes: 13 additions & 0 deletions docker/notification/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ivadim/fruitnanny-app

RUN apt-get update \
&& apt-get install -y libgpiod2 \
&& pip3 install adafruit-circuitpython-lis3dh \
&& pip3 install adafruit-circuitpython-dht \
&& pip3 install pushbullet.py \
&& pip3 install configparser \
&& pip3 install adafruit-blinka \
&& apt-get --purge remove -y $buildDeps && apt-get --purge -y autoremove \
&& apt-get clean \
&& rm -rf /tmp/* \
&& rm -rf /var/lib/apt/lists/*

0 comments on commit c894bd3

Please sign in to comment.