helyos_agent_sdk.mqtt_client module

helyos_agent_sdk.mqtt_client.connect_mqtt(rabbitmq_host, rabbitmq_port, username, passwd, enable_ssl=False, ca_certificate=None, temporary=False)
class helyos_agent_sdk.mqtt_client.HelyOSMQTTClient(rabbitmq_host, rabbitmq_port=1883, uuid=None, enable_ssl=False, ca_certificate=None, helyos_public_key=None, agent_privkey=None, agent_pubkey=None)

Bases: object

__init__(rabbitmq_host, rabbitmq_port=1883, uuid=None, enable_ssl=False, ca_certificate=None, helyos_public_key=None, agent_privkey=None, agent_pubkey=None)

HelyOS MQTT client class

The client implements several functions to facilitate the interaction with RabbitMQ. It reads the RabbitMQ exchange names from environment variables and it provides the helyOS routing-key names as properties.

Parameters
  • rabbitmq_host (str) – RabbitMQ host name (e.g rabbitmq.mydomain.com)

  • rabbitmq_port (int) – RabbitMQ port, defaults to 5672

  • uuid (str) – universal unique identifier fot the agent

  • enable_ssl (bool, optional) – Enable rabbitmq SSL connection, default False.

  • ca_certificate (string (PEM format), optional) – Certificate authority of the RabbitMQ server, defaults to None

  • helyos_public_key (string (PEM format), optional) – helyOS RSA public key to verify the helyOS message signature.

  • agent_privkey (string (PEM format), optional) – Agent RSA private key, defaults to None

  • agent_pubkey (string (PEM format), optional) – Agent RSA public key is saved in helyOS core, defaults to None

property is_connection_open

Check if the connection is open

property checking_routing_key

MQTT Topic value used for check in messages

property status_routing_key

MQTT Topic value used to publish agent and assigment states

property sensors_routing_key

MQTT Topic value used for broadingcasting of positions and sensors

property mission_routing_key

MQTT Topic value used to publish mission requests

property summary_routing_key

MQTT Topic value used to publish summary requests

property database_routing_key

MQTT Topic value used to publish database requests

property yard_visualization_routing_key

MQTT Topic value used to broadcast yard visualization data

property yard_update_routing_key

MQTT Topic value used to publish updates for the yard

property instant_actions_routing_key

MQTT Topic value used to read instant actions

property update_routing_key

MQTT Topic value used for agent update messages

property assignment_routing_key

MQTT Topic value used to read assigment messages

get_checkin_result()

get_checkin_result() read the checkin data published by helyOS and save into the HelyOSClient instance as checkin_data.

auth_required()
reconnect()
connect(username, password)

Creates the connection between agent and the message broker server.

helyos_client = HelyOSClient(host='myrabbitmq.com', port=5672, uuid='3452345-52453-43525')
helyos_client.connect_rabbitmq('my_username', 'secret_password') #  <===
Parameters
  • username (str) – username previously registered in RabbitMQ server

  • password (str) – password previously registered in RabbitMQ server’

perform_checkin(yard_uid, status='free', agent_data={}, signed=False, checkin_guard_interceptor=None)

The check-in procedure registers the agent to a specific yard. helyOS will publish the relevant data about the yard and the CA certificate of the RabbitMQ server, which is relevant for SSL connections. Use the method get_checkin_result() to retrieve these data.

The method connect() should run before the perform_checkin(), otherwise, it will be assumed that the agent does not have yet a RabbitMQ account. In this case, if the environment variable REGISTRATION_TOKEN is set, helyOS will create a RabbitMQ account using the uuid as username and returns a password, which can be found in the property rbmq_password. This password should be safely stored.

helyos_client = HelyOSClient(host='myrabbitmq.com', port=1883, uuid='3452345-52453-43525')
helyos_client.connect('my_username', 'secret_password')
helyos_client.perform_checkin(yard_uid='yard_A', status='free')  #  <===
helyOS_client.get_checkin_result()                               #  <===
Parameters
  • yard_uid (str) – Yard UID

  • status (str) – Agent status, defaults to ‘free’

  • agent_data (dict) – Additional data to be sent with the check-in message, defaults to an empty dictionary

  • signed (bool) – Whether or not to sign the check-in message, defaults to False

  • checkin_guard_interceptor (function) – An optional interceptor function to be called to validate the check-in response, returning True or False, defaults to None

publish(routing_key, message, signed=False, reply_to=None, corr_id=None, exchange='xchange_helyos.agents.mqtt')

Publish message in RabbitMQ-MQTT :param message: Message to be transmitted :type message: str :param routing_key: MQTT topic name :type routing_key: str :param encrypted: If this message should be encrypted, defaults to False :type encrypted: str :param exchange: RabbitMQ exchange, cannot be changed, fixed to env.AGENTS_MQTT_EXCHANGE :type exchange: str

set_assignment_queue(exchange='xchange_helyos.agents.dl')

There are no queues in MQTT protocol

set_instant_actions_queue(exchange='xchange_helyos.agents.dl')

There are no queues in MQTT protocol

consume_assignment_messages(assignment_callback)

Subscribe to the MQTT assignment topic

consume_instant_actions_messages(instant_actions_callback)

Receive instant actions messages. Instant actions are used by helyOS to reserve, release or cancel an assignment.

Parameters

instant_actions_callback (func) – call back for instant actions

start_listening()
stop_listening()
close_connection()

Close the MQTT connection with RabbitMQ server