You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
Python

2 years ago
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