ircterm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
ircterm [2015-03-21 23:03] – tim | ircterm [2018-06-14 19:38] – [Hardware Status] alfie | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Hardware Status ===== | ||
+ | |||
+ | Normal screen is currently < | ||
+ | |||
===== Project Background ===== | ===== Project Background ===== | ||
Line 111: | Line 115: | ||
/ | / | ||
< | < | ||
- | # | + | #!/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 162: | Line 152: | ||
< | < | ||
- | apt-get install python-pika | + | apt-get install python-pip |
+ | pip install paho-mqtt | ||
</ | </ | ||
Line 420: | Line 411: | ||
* / | * / | ||
- | * / | ||
- | |||
- | 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