ircterm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
ircterm [2015-10-05 15:55] – external edit 127.0.0.1 | ircterm [2016-10-07 17:04] – [Playing the sound] tim | ||
---|---|---|---|
Line 111: | Line 111: | ||
/ | / | ||
< | < | ||
- | # | + | #!/usr/bin/env python |
- | import | + | import |
- | import | + | import |
- | import pika | + | |
- | import time | + | |
- | logging.getLogger('' | + | last_state = None |
- | logging.getLogger(' | + | |
- | amqp_host = "amqp.hacklab" | + | def on_connect(client, |
- | amqp_exchange = " | + | client.subscribe("sensor/ |
- | topic = " | + | |
- | tvstate = False | + | def on_message(client, |
+ | global last_state | ||
- | connection = pika.BlockingConnection(pika.ConnectionParameters(host=amqp_host, | + | # ignore retained |
- | channel = connection.channel() | + | #if msg.retain: |
- | channel.exchange_declare(exchange=amqp_exchange, | + | # |
- | result | + | if last_state != msg.payload: |
- | queue_name = result.method.queue | + | # state has changed |
- | channel.queue_bind(exchange=amqp_exchange, queue=queue_name, routing_key=topic) | + | if msg.payload == " |
+ | # screen on | ||
+ | subprocess.call(" | ||
+ | elif msg.payload == " | ||
+ | # screen off | ||
+ | subprocess.call(" | ||
+ | last_state = msg.payload | ||
- | def callback(ch, | + | m = mqtt.Client() |
- | global tvstate | + | m.on_connect |
- | + | m.on_message | |
- | changed | + | m.connect("mqtt") |
- | state = properties.headers[' | + | m.loop_forever() |
- | old_state = properties.headers.get(' | + | |
- | + | ||
- | if state == ' | + | |
- | if tvstate == False: | + | |
- | os.system(" | + | |
- | os.system(" | + | |
- | tvstate | + | |
- | elif state == ' | + | |
- | os.system("tvservice -o") | + | |
- | | + | |
- | tvstate = False | + | |
- | + | ||
- | + | ||
- | channel.basic_consume(callback, | + | |
- | queue=queue_name, | + | |
- | no_ack=True) | + | |
- | channel.start_consuming() | + | |
</ | </ | ||
Line 163: | Line 149: | ||
< | < | ||
apt-get install python-pip | apt-get install python-pip | ||
- | pip install | + | pip install |
</ | </ | ||
Line 421: | Line 407: | ||
* / | * / | ||
- | * / | ||
- | |||
- | The following was required for hacksense.py but has been suggested by Tim that any Redis stuff should be removed from hacksense.py instead. | ||
- | |||
- | < | ||
- | apt-get install python-redis | ||
- | </ | ||
* uhoh.mp3 is on doorbot which has the speaker attached to it. | * uhoh.mp3 is on doorbot which has the speaker attached to it. | ||
In irssi config: beep_cmd = "/ | In irssi config: beep_cmd = "/ |
ircterm.txt · Last modified: 2021-05-21 14:00 by simon