Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification function #24

Merged
merged 26 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to set restart to "no"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually a mistake, sorry.
I changed it for my tests because I didn't want containers to be restarted after a RPi reboot.

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 @@ -41,7 +41,7 @@ services:

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

nginx:
image: arm32v7/nginx
restart: always
restart: "no"
network_mode: "host"
depends_on:
- janus
Expand All @@ -66,3 +66,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/*