From fe2ef1b3a48bb53da2cd1251f49d3e1902588892 Mon Sep 17 00:00:00 2001 From: joak Date: Tue, 16 May 2023 15:50:49 +0200 Subject: [PATCH] week3 python script --- week3/call.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 week3/call.py diff --git a/week3/call.py b/week3/call.py new file mode 100644 index 0000000..d710f34 --- /dev/null +++ b/week3/call.py @@ -0,0 +1,29 @@ +from sim800l import SIM800L +import logging +import os +import time +#logging.getLogger().setLevel(5) + +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")) +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 + sim800l.command("ATA\n") #answer the phone + print("playing sound file") + os.system("play test.wav &") + 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") + break