![52f1f23f9bf1b85596b45f31ea2751ea.jpg](https://ppmm.org/images/2020/08/07/52f1f23f9bf1b85596b45f31ea2751ea.jpg)
在门上粘个红外对管,外加树莓派和喇叭,一套~~朴实无华且枯燥~~**领先全球**的**主动安全防御系统**就完成了(滑稽
门上用了一个8266,检查红外对管为高电平就向树莓派发送一个get请求,树莓派收到后就播放~~恐怖~~音频。
树莓派程序:
```
import web
import os
urls = (
'/(.*)', 'main'
)
web.config.debug = False
app = web.application(urls, globals())
class main:
def GET(self, name):
web.header('Access-Control-Allow-Origin','*')
web.header('Access-Control-Allow-Methods','GET,POST')
if name == 'a':
os.system('screen -x -S audio -p 0 -X stuff "aplay /home/pi/a.wav\n"')
elif name == 'b':
os.system('screen -x -S audio -p 0 -X stuff "aplay /home/pi/b.wav\n"')
return '{"status":"ok","name":"' + name + '"}'
if __name__ == "__main__":
app.run()
```
8266程序([其中requests库](https://github.com/fcannizzaro/esp8266-request)):
```
from machine import Pin
from requests import Request as req
from time import sleep
p = Pin(5,Pin.IN)
while True:
if p.value():
req.get("http://192.168.xxx.xxx:8080/a")
sleep(1)
```