User Tools

Site Tools


squawk

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
squawk [2016-10-05 13:39] – [Usage] robsquawk [2016-10-09 22:31] tim
Line 20: Line 20:
 ==== raspi-config ==== ==== raspi-config ====
  
 +  * Expand filesystem
   * Medium overclock   * Medium overclock
   * Graphics mem reduced to 16M   * Graphics mem reduced to 16M
Line 46: Line 47:
 <code> <code>
 su -c "mpg123 /home/pi/sounds/indyboot.mp3" pi & su -c "mpg123 /home/pi/sounds/indyboot.mp3" pi &
-su -c "/home/pi/respawn --syslog /home/pi/squawk.py" pi &+su -c "/home/pi/respawn --syslog --max-backoff=10 /home/pi/squawk.py" pi &
 </code> </code>
- 
 ===== Scripts ===== ===== Scripts =====
  
Line 64: Line 64:
 import signal import signal
 import time import time
 +import random
  
- +logging.basicConfig(level=logging.INFO)
-last_state None+
  
 max_playtime  = 15 max_playtime  = 15
 +sounds_path = "/home/pi/sounds"
  
-sounds_path "/home/pi/sounds"+status 'closed'
  
 # runs a command and terminates it after a specified timeout # runs a command and terminates it after a specified timeout
Line 130: Line 131:
     base, ext = os.path.splitext(filename)     base, ext = os.path.splitext(filename)
     if ext == '.mp3':     if ext == '.mp3':
-        command = ['mpg123', ' -q', filename]+        command = ['mpg123', '-q', filename]
         call_with_timeout(command, timeout=timeout)         call_with_timeout(command, timeout=timeout)
     else:     else:
-        command = ['play', ' -q', filename]+        command = ['play', '-q', filename]
         call_with_timeout(command, timeout=timeout)         call_with_timeout(command, timeout=timeout)
  
Line 139: Line 140:
     client.subscribe("sound/g1/play")     client.subscribe("sound/g1/play")
     client.subscribe("sound/g1/speak")     client.subscribe("sound/g1/speak")
 +    client.subscribe("sound/g1/announce")
 +    client.subscribe("display/doorbot/intercom")
 +    client.subscribe("labstatus")
  
 def on_message(client, userdata, msg): def on_message(client, userdata, msg):
 +
 +    global status
 +
 +    if msg.topic == 'labstatus':
 +        if msg.payload == 'open':
 +           status = 'open'
 +        else:
 +           status = 'closed'
  
     # ignore retained (non-realtime) messages     # ignore retained (non-realtime) messages
Line 147: Line 159:
  
     if msg.topic == 'sound/g1/play':     if msg.topic == 'sound/g1/play':
- play(msg.payload)+        play(msg.payload)
  
     if msg.topic == 'sound/g1/speak':     if msg.topic == 'sound/g1/speak':
- play('dong.mp3')+        play('dongq.mp3')
         speak(msg.payload)         speak(msg.payload)
-        + 
 +    if msg.topic == 'sound/g1/announce': 
 +        play('chime.mp3'
 +        speak(msg.payload) 
 + 
 +    if msg.topic == 'display/doorbot/intercom': 
 +        if msg.payload == '1' and status == 'closed': 
 +            play('doorbell.mp3')
  
 m = mqtt.Client() m = mqtt.Client()
squawk.txt · Last modified: 2023-11-25 23:45 by jaso55555

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki