Line 49: |
Line 49: |
| Before running the example, you must have a recent python, recent libzmq installed, and must have pyzmq installed. | | Before running the example, you must have a recent python, recent libzmq installed, and must have pyzmq installed. |
| | | |
− | #!/usr/bin/env python
| + | <syntaxhighlight lang="python"> |
− | import zmq
| + | #!/usr/bin/env python |
| + | import zmq |
| + | |
| + | context = zmq.Context.instance() |
| + | |
| + | # Create a zmq socket that will SUBscribe to door nodes. |
| + | door_socket = context.socket(zmq.SUB) |
| + | door_socket.connect("tcp://frontdoor.pumpingstationone.org:5556") |
| + | door_socket.connect("tcp://backdoor.pumpingstationone.org:5556") |
| + | |
| + | # The doors send a lot of types of messages. We only care about "door.state.unlock" messages |
| + | door_socket.setsockopt(zmq.SUBSCRIBE, b"door.state.unlock") |
| + | |
| + | # create a zmq socket that will PUSH data to our IRC actuator node. |
| + | zirc_socket = context.socket(zmq.PUSH) |
| + | zirc_socket.connect('tcp://sally.ad.pumpingstationone.org:5558') |
| + | |
| + | # Loop forever |
| + | while True: |
| | | |
− | context = zmq.Context.instance()
| + | # Read messages from the doors |
− |
| + | topic, message = door_socket.recv_multipart() |
− | # Create a zmq socket that will SUBscribe to door nodes. | + | |
− | door_socket = context.socket(zmq.SUB)
| + | # Send the message to the irc channel |
− | door_socket.connect("tcp://frontdoor.pumpingstationone.org:5556")
| + | zirc_socket.send(message) |
− | door_socket.connect("tcp://backdoor.pumpingstationone.org:5556")
| + | <syntaxhighlight> |
− |
| |
− | # The doors send a lot of types of messages. We only care about "door.state.unlock" messages
| |
− | door_socket.setsockopt(zmq.SUBSCRIBE, b"door.state.unlock")
| |
− |
| |
− | # create a zmq socket that will PUSH data to our IRC actuator node.
| |
− | zirc_socket = context.socket(zmq.PUSH)
| |
− | zirc_socket.connect('tcp://sally.ad.pumpingstationone.org:5558')
| |
− |
| |
− | # Loop forever
| |
− | while True:
| |
− |
| |
− | # Read messages from the doors
| |
− | topic, message = door_socket.recv_multipart()
| |
− | | |
− | # Send the message to the irc channel
| |
− | zirc_socket.send(message)
| |
| | | |
| == Hardware == | | == Hardware == |