与Bose SoundTouch互动

2024-09-30 06:33:05 发布

您现在位置:Python中文网/ 问答频道 /正文

导言

我正在用树莓做警报系统。这很简单。 当GPIO X上出现事件时,它会执行一些操作。我指定RaspberryPi,因为它会影响代码

问题

我以一种非常简单的方式构建了代码,如果其中一个主机无法访问,那么代码就会停止。我是Python新手,我希望代码可以以任何一种方式工作,因为它是一个报警系统

头脑风暴

首先,它可以尝试列出的每个设备,然后仅使用可用设备执行代码的其余部分

有用信息

我使用了libsoundtouch模块,它非常有趣。查尔斯·布朗德的道具

GitHubDocumentation

错误

HTTPConnectionPool(host='192.168.1.10',port=8090):url:/info超过最大重试次数(由NewConnectionError引起)(':无法建立新连接:[WinError 10060]

代码

from libsoundtouch import soundtouch_device
from libsoundtouch.utils import Source, Type
import RPi.GPIO as GPIO



device1 = soundtouch_device('192.168.1.10')
device2 = soundtouch_device('192.168.1.20')

GPIO.setmode(GPIO.BOARD)


GPIO setup(19,GPIO.IN) # In for a switch


while True:
      if (GPIO.input(19)):
          device1.play_url('--------')
          device2.play_url('--------')

可能的解决办法

IPdevice1 = 192.168.1.10
IPdevice2 = 192.168.1.20

Device1Up = true   
#Ping 

ping device1 if Up 
       device1Up= true

if device1Up = true 
       execute some code 

 *Be aware that I know this isn't real code* 

Tags: 代码fromimporttrueurlplaygpioif

热门问题