# Import ZeroMQ module
import zmq

# Change these to point to your server and port
host = "coredata-dpkd.dp.mbari.org"
port = "5556"

# Creates a subscriber socket instance
context = zmq.Context()
socket = context.socket(zmq.SUB)

# Connects to a bound socket
socket.connect("tcp://{}:{}".format(host, port))

# Subscribes to all topics
socket.subscribe("ROV_UHS_MSG")

# Receives a multipart message
while(True):
    the_response = socket.recv_multipart()
    string_rep = ""
    counter = 0
    for i in the_response:
        if counter > 0:
            string_rep += ":"
        string_rep += i.decode()
        counter += 1
    #print(string_rep + "\n")
    result1 = string_rep.index('pub_timestamp')
    result2 = string_rep.index('rov_wire_length')
    result2b = string_rep.index("},{\"key\":\"rov_wire_speed")
    result3 = string_rep.index("\"rov_wire_speed\",\"value\":")
    result3b = string_rep.index("},{\"key\":\"rov_tension")
    result4 = string_rep.index('rov_tension')
    result4b = string_rep.index("},{\"key\":\"ctd_set_length")
    print(string_rep[result1+15:result1+30] + "  " 
    + string_rep[result2+25:result2b] + "  "
    + string_rep[result3+25:result3b] + "  "
    + string_rep[result4+21:result4b])

