Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnpanda committed Mar 18, 2021
0 parents commit 483dfec
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc

11 changes: 11 additions & 0 deletions README.md
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")

68 changes: 68 additions & 0 deletions detect.py
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)

0 comments on commit 483dfec

Please sign in to comment.