ROV CTD Zero MQ Client
Message Structure
The data coming from the CTD is parsed into the following fields
| Variable | Data Type |
|---|---|
| temperature | real |
| conductivity | real |
| pressure | real |
| analog1 | real |
| analog2 | real |
| analog3 | real |
| analog4 | real |
| sound_velocity | real |
| in_water | bool |
| receiving_data | bool |
When you subscribe to the ZeroMQ proxy, you will want to subscribe to SEABIRD_CTD_MSG.
Python
Here is an example script to subscribe to the ROV CTD messages coming over ZeroMQ (note you need the python ZMQ module installed in your Python environment)
# Import ZeroMQ module
import zmq
import json
from datetime import datetime
# ZMQ Channel. Some common channels are:
ZMQ_CHANNEL = "SEABIRD_CTD_MSG"
# A function to flatten the json data
def flatten_json(json_string):
# The JSON object to return
out = {}
# Convert the string to JSON object
json_object = json.loads(json_string)
# Load the top level properties
if "lcm_channel" in json_object:
out["lcm_channel"] = json_object["lcm_channel"]
if "message_type" in json_object:
out["message_type"] = json_object["message_type"]
if "num_integers" in json_object:
out["num_integers"] = json_object["num_integers"]
if "num_reals" in json_object:
out["num_reals"] = json_object["num_reals"]
if "pub_id" in json_object:
out["pub_id"] = json_object["pub_id"]
if "pub_sequence" in json_object:
out["pub_sequence"] = json_object["pub_sequence"]
if "pub_timestamp" in json_object:
out["pub_timestamp"] = json_object["pub_timestamp"]
if "integer_list" in json_object:
for integer_object in json_object['integer_list']:
out[integer_object['key']] = integer_object['value']
if "real_list" in json_object:
for real_object in json_object['real_list']:
out[real_object['key']] = real_object['value']
if "string_list" in json_object:
for string_object in json_object['string_list']:
out[string_object['key']] = string_object['value']
if "boolean_list" in json_object:
for boolean_object in json_object['boolean_list']:
out[boolean_object['key']] = boolean_object['value']
return out
# Change these to point to your server and port
host = "coredata-rcsn.rc.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(ZMQ_CHANNEL)
# Receives a multipart message
while(True):
the_response = socket.recv_multipart()
payload_s = the_response[-1].decode("utf-8", errors="strict")
data = flatten_json(payload_s)
print(json.dumps(data, indent=4))
# Convert the timestamp to a human-readable format
human_readable_date = datetime.fromtimestamp(data['pub_timestamp']).strftime('%Y-%m-%d %H:%M:%S')