Async MQTT Communication Wrapper.
More...
|
| None | __init__ (self, str broker, int port=8883, Optional[str] username=None, Optional[str] password=None, Optional[str] ca_cert=None, Optional[str] certfile=None, Optional[str] keyfile=None, Optional[str] keyfile_password=None) |
| | Initialize the MQTT communication client wrapper.
|
| |
| None | open (self) |
| | Open the connection to the MQTT broker.
|
| |
| None | close (self) |
| | Close the connection to the MQTT broker.
|
| |
| None | write (self, str topic, str payload) |
| | Publish a message to a topic.
|
| |
| None | read (self, str topic, Callable[[str, str], Awaitable[None]] callback) |
| | Subscribe to a topic and start an async listener task.
|
| |
|
| list[str] | make_tsc_data_transfer_bulk (data, Union[DataTransferType, str] data_type, from_id="SDK", to_id="printer", transaction_id_start=None) |
| | Build a list of TSCDataTransfer JSON commands for bulk data.
|
| |
| str | make_tsc_abort_command (str from_id="SDK", str to_id="printer", int transaction_id=None) |
| | Build a TSCDataTransfer command with Action="Abort" to clear printer buffer.
|
| |
| str | make_tsc_data_pcl_command (str pcl_language, str from_id="SDK", str to_id="SetPCL", Optional[int] transaction_id=random.randint(1000, 9999)) |
| | Build a TSCDataPCL command to set printer language (e.g., ZPL, TSPL).
|
| |
| str | make_tsc_download_file_command (str download_uri, str from_id="SDK", str to_id="printer", int transaction_id=None, str save_filename=None, bool peer_cert_check=None) |
| | Build a TSCDownloadFile command instructing the printer to download a file.
|
| |
Async MQTT Communication Wrapper.
Provides open/close, publish/subscribe, and helper builders for TSC commands.
◆ __init__()
| None UniPRT_Cloud.Comm.MqttComm.MqttComm.__init__ |
( |
| self, |
|
|
str | broker, |
|
|
int | port = 8883, |
|
|
Optional[str] | username = None, |
|
|
Optional[str] | password = None, |
|
|
Optional[str] | ca_cert = None, |
|
|
Optional[str] | certfile = None, |
|
|
Optional[str] | keyfile = None, |
|
|
Optional[str] | keyfile_password = None ) |
Initialize the MQTT communication client wrapper.
- Parameters
-
| broker | The MQTT broker address. |
| port | Broker port (default 8883). |
| username | Optional username. |
| password | Optional password. |
| ca_cert | Optional CA certificate path. |
| certfile | Optional client cert path. |
| keyfile | Optional client key path. |
| keyfile_password | Optional client key password. |
- Returns
- None.
◆ close()
| None UniPRT_Cloud.Comm.MqttComm.MqttComm.close |
( |
| self | ) |
|
Close the connection to the MQTT broker.
- Returns
- None.
◆ make_tsc_abort_command()
| str UniPRT_Cloud.Comm.MqttComm.MqttComm.make_tsc_abort_command |
( |
str | from_id = "SDK", |
|
|
str | to_id = "printer", |
|
|
int | transaction_id = None ) |
|
static |
Build a TSCDataTransfer command with Action="Abort" to clear printer buffer.
- Parameters
-
| from_id | Sender identifier (default "SDK"). |
| to_id | Target identifier (default "printer"). |
| transaction_id | Optional TransactionId; random if None. |
- Returns
- JSON string representing the Abort command.
◆ make_tsc_data_pcl_command()
| str UniPRT_Cloud.Comm.MqttComm.MqttComm.make_tsc_data_pcl_command |
( |
str | pcl_language, |
|
|
str | from_id = "SDK", |
|
|
str | to_id = "SetPCL", |
|
|
Optional[int] | transaction_id = random.randint(1000, 9999) ) |
|
static |
Build a TSCDataPCL command to set printer language (e.g., ZPL, TSPL).
- Parameters
-
| pcl_language | Language code to set; must be in supported set. |
| from_id | Sender identifier (default "SDK"). |
| to_id | Target identifier (default "SetPCL"). |
| transaction_id | Optional TransactionId; random default provided. |
- Returns
- JSON string representing the TSCDataPCL command.
- Exceptions
-
| TypeError | If pcl_language is not a string. |
| ValueError | If language is not supported. |
◆ make_tsc_data_transfer_bulk()
| list[str] UniPRT_Cloud.Comm.MqttComm.MqttComm.make_tsc_data_transfer_bulk |
( |
| data, |
|
|
Union[DataTransferType, str] | data_type, |
|
|
| from_id = "SDK", |
|
|
| to_id = "printer", |
|
|
| transaction_id_start = None ) |
|
static |
Build a list of TSCDataTransfer JSON commands for bulk data.
- Parameters
-
| data | The input data: list[str] for Text; Base64/Hex string for others. |
| data_type | Data type: Text, Base64, or Hex. |
| from_id | Sender identifier (default "SDK"). |
| to_id | Target identifier (default "printer"). |
| transaction_id_start | Starting TransactionId; random if None. |
- Returns
- List of JSON strings (each a TSCDataTransfer command).
- Exceptions
-
| ValueError | On invalid input types/encodings. |
◆ make_tsc_download_file_command()
| str UniPRT_Cloud.Comm.MqttComm.MqttComm.make_tsc_download_file_command |
( |
str | download_uri, |
|
|
str | from_id = "SDK", |
|
|
str | to_id = "printer", |
|
|
int | transaction_id = None, |
|
|
str | save_filename = None, |
|
|
bool | peer_cert_check = None ) |
|
static |
Build a TSCDownloadFile command instructing the printer to download a file.
- Parameters
-
| download_uri | Source URL for the file (required). |
| from_id | Sender identifier (default "SDK"). |
| to_id | Target identifier (default "printer"). |
| transaction_id | Optional TransactionId; random if None. |
| save_filename | Optional filename to save as. |
| peer_cert_check | Optional TLS peer certificate validation (True/False). |
- Returns
- JSON string representing the TSCDownloadFile command.
◆ open()
| None UniPRT_Cloud.Comm.MqttComm.MqttComm.open |
( |
| self | ) |
|
Open the connection to the MQTT broker.
- Returns
- None.
◆ read()
| None UniPRT_Cloud.Comm.MqttComm.MqttComm.read |
( |
| self, |
|
|
str | topic, |
|
|
Callable[[str, str], Awaitable[None]] | callback ) |
Subscribe to a topic and start an async listener task.
- Parameters
-
| topic | The topic to subscribe to. |
| callback | Async callback handling (topic, payload). |
- Returns
- None.
◆ write()
| None UniPRT_Cloud.Comm.MqttComm.MqttComm.write |
( |
| self, |
|
|
str | topic, |
|
|
str | payload ) |
Publish a message to a topic.
- Parameters
-
| topic | The MQTT topic to publish to. |
| payload | The message payload to send (UTF-8). |
- Returns
- None.
◆ _mqtt_comm
| UniPRT_Cloud.Comm.MqttComm.MqttComm._mqtt_comm |
|
protected |
Initial value:= MqttCommInternal(
broker,
port,
username,
password,
ca_cert,
certfile,
keyfile,
keyfile_password,
)
The documentation for this class was generated from the following file:
- /Users/bob_huang/Documents/Project/UniPRT_Cloud/UniPRT_Cloud/Comm/MqttComm.py