Things Bus: Difference between revisions

From Pumping Station One
 
(5 intermediate revisions by 2 users not shown)
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 ==
Line 87: Line 89:


== Inter-Node Communication ==
== Inter-Node Communication ==
{{ambox
|type=content
|text=The code snippits contain errors
}}


The software for a node can be written in any language that supports zmq and json.
The software for a node can be written in any language that supports zmq and json.


Nodes send messages using json data. Sensors use zmq PUB/SUB. Actuators use zmq PUSH/PULL. Neurons use whatever they have to do get the job done, which is to SUB to sensors, and PUSH to actuators.
Nodes send messages using json data. Sensors use zmq PUB/SUB. Actuators use zmq PUSH/PULL. Neurons use whatever they have to do get the job done, which means they SUB to sensors, and PUSH to actuators.


=== Code Snippits ===
Sensors send data like this:
Sensors send data like this: