UniPRT_Cloud SDK v2.0.0.0
 
Loading...
Searching...
No Matches
UniPRT_Cloud.Comm.MqttComm.MqttComm Class Reference

Async MQTT Communication Wrapper. More...

Public Member Functions

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.
 

Static Public Member Functions

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.
 

Protected Attributes

 _mqtt_comm
 

Detailed Description

Async MQTT Communication Wrapper.

Provides open/close, publish/subscribe, and helper builders for TSC commands.

Constructor & Destructor Documentation

◆ __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
brokerThe MQTT broker address.
portBroker port (default 8883).
usernameOptional username.
passwordOptional password.
ca_certOptional CA certificate path.
certfileOptional client cert path.
keyfileOptional client key path.
keyfile_passwordOptional client key password.
Returns
None.

Member Function Documentation

◆ 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_idSender identifier (default "SDK").
to_idTarget identifier (default "printer").
transaction_idOptional 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_languageLanguage code to set; must be in supported set.
from_idSender identifier (default "SDK").
to_idTarget identifier (default "SetPCL").
transaction_idOptional TransactionId; random default provided.
Returns
JSON string representing the TSCDataPCL command.
Exceptions
TypeErrorIf pcl_language is not a string.
ValueErrorIf 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
dataThe input data: list[str] for Text; Base64/Hex string for others.
data_typeData type: Text, Base64, or Hex.
from_idSender identifier (default "SDK").
to_idTarget identifier (default "printer").
transaction_id_startStarting TransactionId; random if None.
Returns
List of JSON strings (each a TSCDataTransfer command).
Exceptions
ValueErrorOn 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_uriSource URL for the file (required).
from_idSender identifier (default "SDK").
to_idTarget identifier (default "printer").
transaction_idOptional TransactionId; random if None.
save_filenameOptional filename to save as.
peer_cert_checkOptional 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
topicThe topic to subscribe to.
callbackAsync 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
topicThe MQTT topic to publish to.
payloadThe message payload to send (UTF-8).
Returns
None.

Member Data Documentation

◆ _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: