From 203ca08eb47a4af47329c74704731b50ee39af81 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 May 2023 12:10:42 +0100 Subject: [PATCH 1/2] update --- week3/call-simpler.py | 9 ++++---- week3/call.py | 14 ++++++------ week3/receivecalls.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 week3/receivecalls.py diff --git a/week3/call-simpler.py b/week3/call-simpler.py index aead28f..f5a98b6 100644 --- a/week3/call-simpler.py +++ b/week3/call-simpler.py @@ -4,7 +4,7 @@ import os import time import subprocess import random -#logging.getLogger().setLevel(5) +logging.getLogger().setLevel(5) sim800l = SIM800L(port='/dev/serial0', baudrate=115000, timeout=3.0) audios = ["love1.wav", "love2.wav", "love3.wav"] @@ -17,9 +17,8 @@ time.sleep(3) while True: activecall = sim800l.command("AT+CPAS\n") #check if someone is calling or not - if "+CPAS: 3" in activecall: #if someone is calling - print("some one is calling") - time.sleep(3) #wait 3 seoncds + if "3" in activecall: #if someone is calling + print("some one is calling") sim800l.command("ATA\n") #answer the phone audio = random.choice(audios) print("playing python file") @@ -29,5 +28,5 @@ while True: callisactive = sim800l.command("AT+CPAS\n") if "+CPAS: 0" in callisactive: #call is not active anymore print ("call stopped") - os.system("killall play") + os.system("sudo killall play") break diff --git a/week3/call.py b/week3/call.py index 9167162..bd0cdbc 100644 --- a/week3/call.py +++ b/week3/call.py @@ -2,7 +2,7 @@ from sim800l import SIM800L import logging import os import time -import subprocess +#import subprocess #logging.getLogger().setLevel(5) sim800l = SIM800L(port='/dev/serial0', baudrate=115000, timeout=3.0) @@ -20,15 +20,15 @@ while True: time.sleep(3) #wait 3 seoncds sim800l.command("ATA\n") #answer the phone print("playing python file") - # os.system("play test.wav &") - p = subprocess.Popen([sys.executable, 'audio.py'], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) + os.system("play test.wav &") + #p = subprocess.Popen([sys.executable, 'audio.py'], + #stdout=subprocess.PIPE, + #stderr=subprocess.STDOUT) while True: #check if call is still active callisactive = sim800l.command("AT+CPAS\n") if "+CPAS: 0" in callisactive: #call is not active anymore print ("call stopped") - # os.system("killall play") - p.terminate() + os.system("killall play") + #p.terminate() break diff --git a/week3/receivecalls.py b/week3/receivecalls.py new file mode 100644 index 0000000..1983e80 --- /dev/null +++ b/week3/receivecalls.py @@ -0,0 +1,53 @@ +from sim800l import SIM800L +import logging +import os +import time +logging.getLogger().setLevel(5) + +play = False +call = False +audios = ["love1.wav", "love2.wav", "love3.wav"] +sim800l = SIM800L(port='/dev/serial0', baudrate=115000, timeout=3.0) +print(sim800l.command("ATS0=0\n")) +time.sleep(2) +print(sim800l.command("AT\n")) +time.sleep(5) +#print(sim800l.command("AT+DDET=1\n")) +#time.sleep(3) +#print("<>") +time.sleep(3) + +while True: + if call is False: + try: + activecall = sim800l.command("AT+CPAS\n", waitfor=1500) #check if someone is calling or not + except: + activecall = "" + print(activecall) + r = sim800l.check_incoming() + print(r) + if r[-1] is not None and "3" in r[-1] and call is False: #if someone is callin + print("some one is calling") + call = True + time.sleep(1) #wait 3 seoncds + sim800l.command("ATA\n") #answer the phone + if play is False: + print("playing sound file") + import random + audio = random.choice(audios) + os.system("play " + audio + " &") + play = True + #check =sim800l.command("AT+DDET=?\n") + #print(check) + while True: + #check if call is still active + callisactive = sim800l.command("AT+CPAS\n") + r = sim800l.check_incoming() + print(r) + if r[-1] is not None: + if "0" in r[-1]: #call is not active anymore + print ("call stopped") + os.system("sudo killall play") + call = False + play = False + break From 0fa5224b5eaccb0622d9beff45591e2f5a42ade4 Mon Sep 17 00:00:00 2001 From: joak Date: Tue, 23 May 2023 15:12:20 +0200 Subject: [PATCH 2/2] week3 schematics drawing --- week3/schematics-pi-sim800l.svg | 26126 ++++++++++++++++++++++++++++++ 1 file changed, 26126 insertions(+) create mode 100644 week3/schematics-pi-sim800l.svg diff --git a/week3/schematics-pi-sim800l.svg b/week3/schematics-pi-sim800l.svg new file mode 100644 index 0000000..6dc606f --- /dev/null +++ b/week3/schematics-pi-sim800l.svg @@ -0,0 +1,26126 @@ + + + +diode 1N4007capacitor 100uF 15volt+-Audio outputsolder cables to jack plug to connect to raspberry pisolder cables to jack socket to connect to jack cable for speakersaudio in