-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 483dfec
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Mail Detector | ||
|
||
## Raspberry pi part will be running: | ||
- https://projects.raspberrypi.org/en/projects/laser-tripwire/2 | ||
- comms over bluetooth | ||
|
||
## Phone app will: | ||
- Detect comms over bluetooth | ||
- Send push notification if mail received | ||
- Have a single button that resets the Pi ("Mail picked up, alert me when more comes") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from gpiozero import LightSensor | ||
import serial | ||
import time | ||
|
||
# LightSensor classes and methods | ||
## Pause until no light is detected | ||
# wait_for_dark() | ||
# ------------------------- | ||
## Pause until light is detected | ||
# wait_for_light() | ||
# ------------------------- | ||
## Return True if light is detected | ||
# light_detected | ||
# ------------------------- | ||
## Function to run when it is dark | ||
# when_dark = my_function | ||
# ------------------------- | ||
## Function to run when it is light | ||
# when_light = my_function | ||
# ------------------------- | ||
def try_send(timestamp): | ||
# https://towardsdatascience.com/sending-data-from-a-raspberry-pi-sensor-unit-over-serial-bluetooth-f9063f3447af | ||
# tty for bluetooth | ||
ser = serial.Serial('/dev/tty.raspberrypi-SerialPort', timeout=1, baudrate=115000) | ||
# flush | ||
serial.flushInput();serial.flushOutput() | ||
# https://www.arduino.cc/reference/en/language/functions/communication/serial/write/ | ||
# Send data to device | ||
serial.write(F"Post received at: {timestamp}") | ||
# Sleep waiting for response | ||
time.sleep(2) | ||
# If we received reset message from device, reset warning | ||
if serial.readline().decode() == "Reset": | ||
return True | ||
# Else try again | ||
else: | ||
return False | ||
|
||
def notification_set(value): | ||
timestamp = datetime.datetime.now().strftime("%H:%M:%S %m-%h-%Y") | ||
print(value) | ||
sent = False | ||
while true: | ||
# Try to send notification | ||
sent = try_send(timestamp) | ||
# If sent, reset notification value and break | ||
if sent: | ||
return True | ||
# else sleep 10 sec | ||
else: | ||
time.sleep(10) | ||
|
||
# TODO | ||
# Debug | ||
# Create log | ||
# Test with app / device | ||
|
||
# Should log | ||
# Time post arrived | ||
# Time phone was notified | ||
if __name__=="__main__": | ||
# Assumes connection on GPIO17 | ||
ldr = LightSensor(17) | ||
# All values are given as float between 0 (dark) and 1 (light) | ||
print(ldr.value) | ||
# When it gets dark, send notification (beam broken) | ||
when_dark = notification_set(ldr.value) | ||
|