Common

Message

class octopus_sensing.common.message.Message(message_type: str, payload: Any, experiment_id: Optional[str] = None, stimulus_id: Optional[str] = None)[source]

Bases: object

Message class. It is being used for communicating between DeviceCoordinator and various devices. DeviceCoordinator uses message objects to inform devices about an event

Parameters
  • type (str) – The type of message

  • payload (Any) – the message data that can have differnt values

  • experiment_id (str, default: None) – A unique ID for each participant and task in the study

  • stimulus_id (str, default: None) – A unique ID for each stimulus

Example

We can create a customized message using this class, or use prepared messages in the common/message_creators. In this example, we created an instance of message, which its type is start. When DeviceCoordinator dispath this message, it will be sent to all devices in its list. Using this message we inform all devices that start of stimulus_00 is happened.

>>> message = Message("START",
...                   "study_1_p10",
...                   "stimulus_00")
>>> device_coordinator.dispatch(message)

Predefined Messages

class octopus_sensing.common.message_creators.MessageType[source]

Bases: object

Predefined message types including:

1- START: start of a stimulus

2- STOP: End of each stimulus

3- TERMINATE: terminating the process of each device

START = 'START'
STOP = 'STOP'
TERMINATE = 'TERMINATE'
octopus_sensing.common.message_creators.start_message(experiment_id: str, stimulus_id: str, payload=None)[source]

Creates a message to inform device of starting the stimulus

Parameters
  • experiment_id (str, default: None) – A unique ID for each participant and task in the study

  • stimulus_id (str, default: None) – A unique ID for each stimulus

  • payload (Any, default: None) – the message data that can have differnt values

Returns

message – A start message

Return type

Message

Example

In this example, we created a stop message. When DeviceCoordinator dispath this message, it will be sent to all devices in its list. Using this message we inform all devices that stimulus stimulus_00 has started.

>>> message = start_message("study_1_p10", "stimulus_00")
>>> device_coordinator.dispatch(message)
octopus_sensing.common.message_creators.stop_message(experiment_id: str, stimulus_id: str)[source]

Creates a message to inform device of stopping the stimulus

Parameters
  • experiment_id (str, default: None) – A unique ID for each participant and task in the study

  • stimulus_id (str, default: None) – A unique ID for each stimulus

Returns

message – A start message

Return type

Message

Example

In this example, we created a start message. When DeviceCoordinator dispath this message, it will be sent to all devices in its list. Using this message we inform all devices that stimulus stimulus_00 is finished.

>>> message = stop_message("study_1_p10", "stimulus_00")
>>> device_coordinator.dispatch(message)
octopus_sensing.common.message_creators.terminate_message()[source]

Creates a message to inform device of terminating the program

Returns

message – A start message

Return type

Message

Example

In this example, we created a terminate message. When DeviceCoordinator dispath this message, it will be sent to all devices in its list. Using this message we inform all devices to terminate.

>>> message = terminate()
>>> device_coordinator.dispatch(message)