### Configure CloudPRNT Server Settings for HTTP and MQTT Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt These JSON examples demonstrate how to configure CloudPRNT server settings. The first example shows HTTP-only support. The subsequent examples illustrate MQTT configurations, including full MQTT mode and Trigger POST mode, specifying broker details, TLS usage, and authentication. ```json // cloudprnt-setting.json - HTTP only { "title": "star_cloudprnt_server_setting", "version": "1.0.0", "serverSupportProtocol": ["HTTP"] } ``` ```json // cloudprnt-setting.json - MQTT with Full MQTT mode { "title": "star_cloudprnt_server_setting", "version": "1.0.0", "serverSupportProtocol": ["HTTP", "MQTT"], "settingForMQTT": { "useTriggerPOST": false, "mqttConnectionSetting": { "hostName": "172.16.212.228", "portNumber": 1883, "useTls": false, "authenticationSetting": { "username": "user", "password": "pass" } } } } ``` ```json // cloudprnt-setting.json - MQTT with Trigger POST mode { "title": "star_cloudprnt_server_setting", "version": "1.0.0", "serverSupportProtocol": ["HTTP", "MQTT"], "settingForMQTT": { "useTriggerPOST": true, "mqttConnectionSetting": { "hostName": "broker.example.com", "portNumber": 8883, "useTls": true, "authenticationSetting": { "username": "cloudprnt_user", "password": "secure_password" } } } } ``` -------------------------------- ### Add nupkg to Local Source Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/nupkg_apply_cmd_note.txt Adds the specified nupkg file to a local NuGet package source directory. This makes the package available for installation in other projects. ```bash nuget add StarMicronics.CloudPRNT-Utility.1.1.2.nupkg -Source ./packages ``` -------------------------------- ### CloudPRNT Job Retrieval Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md After a job is ready, the client retrieves the job by performing an HTTP GET request to the server, specifying the preferred media type via a query parameter. ```APIDOC ## GET /cloudprnt/job ### Description This endpoint is used by the CloudPRNT client to retrieve the print job data. The client specifies its preferred media type using a query parameter. ### Method GET ### Endpoint /cloudprnt/job ### Parameters #### Path Parameters None #### Query Parameters - **mediaType** (string) - Required - The media type requested by the client (e.g., "application/vnd.star.starprnt"). #### Request Body None ### Request Example ``` GET /cloudprnt/job?mediaType=application/vnd.star.starprnt HTTP/1.1 Host: your-cloudprnt-server.com ``` ### Response #### Success Response (200) - The response body contains the print job data encoded in the requested `mediaType`. #### Response Example (Example depends on the requested mediaType. For `application/vnd.star.starprnt`, it would be binary printer command data.) ``` -------------------------------- ### Print Ticket via HTTP GET Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/ExampleServers/php_queue/print.html This JavaScript function triggers a ticket print using a simple HTTP GET request to a specified PHP endpoint. It retrieves the printer MAC address from URL parameters and displays an alert upon success or failure. This method is suitable for basic HTTP printing. ```javascript var urlParams = new URLSearchParams(window.location.search); var printer = urlParams.get('mac'); function PrintATicket() { $.get("print.php?mac=" + printer) .done(function() { window.alert("Successfully triggered print."); }) .fail(function() { window.alert("An error has occurred."); }); } ``` -------------------------------- ### Print Ticket via MQTT POST Request Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/ExampleServers/php_queue/print.html This JavaScript function initiates a ticket print using an HTTP GET request with specific MQTT parameters for a POST method. It requires a CloudPRNT Version MQTT compatible printer. Alerts indicate success or failure. ```javascript var urlParams = new URLSearchParams(window.location.search); var printer = urlParams.get('mac'); function PrintATicketTriggerPost() { $.get("print.php?mac=" + printer + "&protocol=mqtt&method=request-post") .done(function() { window.alert("Successfully triggered print."); }) .fail(function() { window.alert("An error has occurred."); }); } ``` -------------------------------- ### Handle CloudPRNT Job Delivery and Conversion (PHP) Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt This PHP function handles HTTP GET requests from CloudPRNT printers for print jobs. It retrieves job details, generates Star Markup, converts it to the requested format using 'cputil', and returns the converted job with appropriate headers. It includes cleanup of temporary files. ```php ``` -------------------------------- ### CloudPRNT Job Delivery API Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Handles GET requests from the printer to retrieve a print job. The server converts the job to the requested format and returns it with the appropriate Content-Type header. ```APIDOC ## GET /cloudprnt/job ### Description This endpoint is used by the printer to request and download a print job. The server will convert the job into the format specified by the `type` query parameter and return the job data. ### Method GET ### Endpoint /cloudprnt/job ### Parameters #### Query Parameters - **mac** (string) - Required - The MAC address of the printer requesting the job. - **type** (string) - Required - The desired media type for the print job (e.g., "image/png", "application/vnd.star.starprnt"). ### Request Example ``` GET /cloudprnt/job?mac=00:11:22:33:44:55&type=image/png HTTP/1.1 Host: your-server.com ``` ### Response #### Success Response (200) - **Content-Type** (string) - The media type of the returned print job data. - **Content-Length** (integer) - The size of the print job data in bytes. - **[Print Job Data]** - The actual print job data in the requested format. #### Response Example (for image/png) ``` HTTP/1.1 200 OK Content-Type: image/png Content-Length: 12345 [Binary PNG image data...] ``` ``` -------------------------------- ### Print Ticket via MQTT URL Job Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/ExampleServers/php_queue/print.html This JavaScript function sends a print job for a URL using MQTT protocol via an HTTP GET request. It's designed for CloudPRNT MQTT compatible printers. Success or failure is communicated via browser alerts. ```javascript var urlParams = new URLSearchParams(window.location.search); var printer = urlParams.get('mac'); function PrintATicketPassUrl() { $.get("print.php?mac=" + printer + "&protocol=mqtt&method=print-job&jobType=url") .done(function() { window.alert("Successfully triggered print."); }) .fail(function() { window.alert("An error has occurred."); }); } ``` -------------------------------- ### Print Ticket via Full MQTT Raw Job Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/ExampleServers/php_queue/print.html This JavaScript function triggers a raw print job using the full MQTT protocol via an HTTP GET request. It requires a CloudPRNT MQTT compatible printer. The function provides feedback through alerts for successful or failed print attempts. ```javascript var urlParams = new URLSearchParams(window.location.search); var printer = urlParams.get('mac'); function PrintATicketAllMqtt() { $.get("print.php?mac=" + printer + "&protocol=mqtt&method=print-job&jobType=raw") .done(function() { window.alert("Successfully triggered print."); }) .fail(function() { window.alert("An error has occurred."); }); } ``` -------------------------------- ### Prepare StarPRNT Data with Device Commands (Windows/Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Prepares print data as StarPRNT commands for a 2-inch or 3-inch printer, including options to control cash drawers or buzzers. This command is executed using the cputil utility. ```console .\cputil.exe thermal2 scale-to-fit drawer-end decode "application/vnd.star.starprnt" sourceimage.png outputdata_2.bin ``` ```console .\cputil.exe thermal3 scale-to-fit buzzer-end 1 decode "application/vnd.star.starprnt" sourceimage.png outputdata_3.bin ``` ```console $ ./cputil thermal2 scale-to-fit drawer-end decode "application/vnd.star.starprnt" sourceimage.png outputdata_2.bin ``` ```console $ ./cputil thermal3 scale-to-fit buzzer-end 1 decode "application/vnd.star.starprnt" sourceimage.png outputdata_3.bin ``` -------------------------------- ### Prepare StarPRNT Data for 2-inch Printer (Windows/Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Prepares print data as StarPRNT commands for a 2-inch printer from a PNG source. Includes options for dithering and scaling the image to fit the page. This command is executed using the cputil utility. ```console .\cputil.exe thermal2 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_2.bin ``` ```console $ ./cputil thermal2 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_2.bin ``` -------------------------------- ### Prepare StarPRNT Data for 3-inch Printer (Windows/Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Prepares print data as StarPRNT commands for a 3-inch printer from a PNG source. Includes options for dithering and scaling the image to fit the page. This command is executed using the cputil utility. ```console .\cputil.exe thermal3 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_3.bin ``` ```console $ ./cputil thermal3 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_3.bin ``` -------------------------------- ### cputil mediatypes command Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md The `cputil mediatypes` command can be used to generate the `mediaTypes` list based on an input file format. ```APIDOC ## cputil mediatypes ### Description Generates a JSON array of supported media types based on the provided input file format. This is useful for the CloudPRNT server to inform clients about the available job formats. ### Method Command-line utility ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Command Usage - **Windows:** `.\cputil.exe mediatypes ` - **Linux / macOS:** `./cputil mediatypes ` Where `` is the path to the file representing the print job's initial format (e.g., `sourceimage.png`). ### Request Example ```bash # Windows .\cputil.exe mediatypes sourceimage.png # Linux / macOS ./cputil mediatypes sourceimage.png ``` ### Response #### Success Response Outputs a JSON array of strings representing the supported media types. #### Response Example ```json ["image/png","image/jpeg","application/vnd.star.raster","application/vnd.star.line","application/vnd.star.starprnt","application/vnd.star.starprntcore"] ``` ``` -------------------------------- ### Convert Star Markup to StarPRNT Commands (Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Converts a print job from Star Document Markup text data to StarPRNT printer command data. The output is saved to a specified binary file. Use '-' or '[stdout]' to write to standard output. ```bash ./cputil decode application/vnd.star.starprnt starmarkup.stm outputdata.bin ``` -------------------------------- ### Generate mediaTypes for CloudPRNT Jobs (Windows) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md This command generates a JSON array of supported media types for a CloudPRNT print job. It takes an input image file and outputs the compatible media types. Ensure the input file is in the same directory as the cputil executable. ```bash .\cputil.exe mediatypes sourceimage.png ``` -------------------------------- ### Control Cash Drawer and Buzzer with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Use the cputil command-line tool to embed commands within print jobs to control cash drawers and buzzers. These commands can be set to trigger before or after the print content, offering flexibility in managing peripherals. ```bash # Open cash drawer at end of print job (2-inch printer) ./cputil thermal2 scale-to-fit drawer-end decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Open cash drawer at start of print job ./cputil thermal3 scale-to-fit drawer-start decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Ring buzzer 3 times at end of print job ./cputil thermal3 scale-to-fit buzzer-end 3 decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Ring buzzer at start of print job ./cputil thermal2 scale-to-fit buzzer-start 2 decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Drawer options: # drawer-start - Open drawer before printing # drawer-end - Open drawer after printing # drawer-none - Do not open drawer (default) # Buzzer options: # buzzer-start X - Ring buzzer X times before printing # buzzer-end X - Ring buzzer X times after printing ``` -------------------------------- ### Generate mediaTypes for CloudPRNT Jobs (Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md This command generates a JSON array of supported media types for a CloudPRNT print job. It takes an input image file and outputs the compatible media types. Ensure the input file is in the same directory as the cputil executable. ```bash ./cputil mediatypes sourceimage.png ``` -------------------------------- ### Convert Star Markup to StarPRNT Commands (Windows) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Converts a print job from Star Document Markup text data to StarPRNT printer command data. The output is saved to a specified binary file. Use '-' or '[stdout]' to write to standard output. ```bash .\cputil.exe decode application/vnd.star.starprnt starmarkup.stm outputdata.bin ``` -------------------------------- ### Publish MQTT Message to Star Printer (PHP) Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Publishes an MQTT message to a specified topic and payload using the mosquitto_pub command-line utility. It requires server settings for MQTT connection, including host, port, username, and password. The function returns a boolean indicating success or failure. ```php "request-client-status"]); return publishMqttMessage($topic, $payload); } // Send direct print job via MQTT (raw text) function sendPrintJob($mac) { $topic = "star/cloudprnt/to-device/{$mac}/print-job"; $payload = [ "title" => "print-job", "jobToken" => substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyz'), 0, 16), "jobType" => "raw", "mediaTypes" => ["text/plain"], "printData" => "\nCloudPRNT MQTT Test\nPrint via Full MQTT\n", "printerControl" => [ "cutter" => ["type" => "full", "feed" => true] ] ]; return publishMqttMessage($topic, json_encode($payload, JSON_UNESCAPED_SLASHES)); } // Send print job via URL reference function sendPrintJobWithUrl($mac, $jobUrl) { $topic = "star/cloudprnt/to-device/{$mac}/print-job"; $payload = [ "title" => "print-job", "jobToken" => bin2hex(random_bytes(8)), "jobType" => "url", "mediaTypes" => ["application/vnd.star.starprnt"], "printData" => $jobUrl ]; return publishMqttMessage($topic, json_encode($payload, JSON_UNESCAPED_SLASHES)); } ?> // MQTT Topics Pattern: // star/cloudprnt/to-device/{MAC}/request-client-status - Request printer status // star/cloudprnt/to-device/{MAC}/request-post - Trigger HTTP POST // star/cloudprnt/to-device/{MAC}/print-job - Send print job // star/cloudprnt/to-server/{MAC}/... - Messages from printer ``` -------------------------------- ### Apply Print Width and Scaling with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Utilizes conversion options to control image scaling, dithering, and print area sizing based on printer paper width. Options like 'thermal2', 'thermal3', and 'thermal4' set the print area to match standard Star printer widths. ```bash # Convert with 2-inch printer width, dithering, and scale-to-fit # For mC-Print2 (58mm paper width) ./cputil thermal2 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_2.bin # For mC-Print3 or TSP650II (80mm paper width) ./cputil thermal3 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_3.bin # For TSP800II (112mm paper width) ./cputil thermal4 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata_4.bin # Print width options: # thermal2 / thermal58 - 2 inch / 58mm printers # thermal3 / thermal80 - 3 inch / 80mm printers # thermal82 - 82mm printers # thermal4 / thermal112 - 4 inch / 112mm printers # Image options: # dither - Apply dithering for better grayscale reproduction # scale-to-fit - Scale image to fit print area (otherwise crops) ``` -------------------------------- ### Convert PNG to StarPRNT data for a 2-inch printer with scaling and dithering Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/readme.md This command converts a PNG image to StarPRNT data for a 2-inch thermal printer. It includes options for dithering and scaling the image to fit the print area. The output is saved to a specified file. ```bash cputil thermal2 dither scale-to-fit decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` -------------------------------- ### Convert Job to StarPRNT Commands (Linux/macOS) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Converts a print job from a source image file (e.g., PNG) to StarPRNT printer command data. The output is saved to a specified binary file. Use '-' or '[stdout]' to write to standard output. ```bash ./cputil decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` -------------------------------- ### Add NuGet Package to .NET Project Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/nupkg_apply_cmd_note.txt Adds the StarMicronics.CloudPRNT-Utility package with a specific version to a .NET project from a local source. This is a prerequisite for building or running the project with the utility. ```bash dotnet add package StarMicronics.CloudPRNT-Utility -s ./packages -v 1.1.2 ``` -------------------------------- ### Convert Job to StarPRNT Commands (Windows) Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md Converts a print job from a source image file (e.g., PNG) to StarPRNT printer command data. The output is saved to a specified binary file. Use '-' or '[stdout]' to write to standard output. ```bash .\cputil.exe decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` -------------------------------- ### Star Document Markup Template Syntax Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Utilize Star Document Markup, a printer-agnostic language, to define receipt layouts with tags for formatting, images, barcodes, and more. This markup, combined with JSON data, enables dynamic receipt generation. ```markup [align: center] [font: a] [image: url https://example.com/logo.jpg; width 60%; min-width 48mm] [magnify: width 2; height 2] ${store_name} [plain] [align: left] [column: vl; left Order ${order_number}; right ${time}] [column: vl; left Sale for ${sales_type}; right Served by ${server}] Transaction #${transaction_id} [fixedWidth: text ------------------------------------------------] [templateArray: start] [column: vl; left ${item_list.quantity%-2d} ${item_list.name}; right ${item_list.unit_price%6.2lf}] [templateArray: end] [fixedWidth: text ------------------------------------------------] [column: vl; left Subtotal; right ${subtotal%6.2lf}] [column: vl; left Tax; right ${tax%6.2lf}] [bold: on] [column: vl; left Total; right ${total%6.2lf}] [bold: off] [barcode: type code39; data ${transaction_id}; height 15mm; module 0; hri] [cut: feed; partial] ``` -------------------------------- ### Convert PNG to StarPRNT data using cputil Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/readme.md This command converts a PNG image file into StarPRNT printer command data. It specifies the output format and the source and destination file paths. The output can also be directed to standard output. ```bash cputil decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` -------------------------------- ### Negotiate Media Types with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Generates a JSON array of supported output formats that 'cputil' can produce from a given input file. This information is used in CloudPRNT protocol responses to indicate available formats for a print job. ```bash # Get supported output media types for a PNG image input # Linux/macOS ./cputil mediatypes sourceimage.png # Windows .\cputil.exe mediatypes sourceimage.png # Output (JSON array for CloudPRNT mediaTypes field): ["image/png","image/jpeg","application/vnd.star.raster","application/vnd.star.line","application/vnd.star.starprnt","application/vnd.star.starprntcore"] # Get media types for Star Document Markup input (by MIME type) ./cputil mediatypes-mime "text/vnd.star.markup" ``` -------------------------------- ### Convert Print Jobs with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Converts print jobs from various source formats (PNG, JPEG, BMP, GIF, text, Star Markup) into printer-specific command formats. This is essential for delivering print jobs to CloudPRNT clients in their preferred format. ```bash # Basic conversion: PNG to StarPRNT commands # Linux/macOS ./cputil decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin # Windows .\cputil.exe decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin # Convert Star Document Markup (.stm) to StarPRNT commands ./cputil decode "application/vnd.star.starprnt" receipt.stm outputdata.bin # Output to stdout instead of file (use "-" or "[stdout]") ./cputil decode "application/vnd.star.starprnt" sourceimage.png - # Supported input formats: # - image/png, image/jpeg, image/bmp, image/gif # - text/plain # - text/vnd.star.markup (.stm files) # Supported output formats: # - application/vnd.star.starprnt (StarPRNT commands) # - application/vnd.star.line (Line mode commands) # - application/vnd.star.raster (Raster graphics) # - image/png, image/jpeg # - text/plain ``` -------------------------------- ### Clear Local NuGet Packages Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/nupkg_apply_cmd_note.txt Clears all local NuGet package caches. This ensures a clean state before adding new packages, preventing potential conflicts or outdated versions from being used. ```bash nuget locals all -clear ``` -------------------------------- ### Control Hold Print Feature with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Configure the TSP650IISK's paper presenter feature using the cputil command-line tool. These settings manage how the printer handles receipts left at the paper exit and affect subsequent print jobs. ```bash # Enable hold print status reporting, disable hardware control ./cputil thermal2 scale-to-fit presentstatus-valid holdprint-invalid decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Full example with multiple options ./cputil thermal3 dither scale-to-fit presentstatus-valid holdprint-invalid drawer-end decode "application/vnd.star.starprnt" receipt.png outputdata.bin # Hold print status options: # presentstatus-default - Follow printer firmware setting # presentstatus-valid - Enable hold print status reporting # presentstatus-invalid - Disable hold print status reporting # Hold print control options: # holdprint-default - Follow printer firmware setting # holdprint-valid - Enable hardware hold print control # holdprint-invalid - Disable hardware hold print control (recommended for CloudPRNT) ``` -------------------------------- ### Generate Star Markup Print Job using PHP Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt This PHP function generates a print job using Star Document Markup. It takes a filename, position, queue, and design array as input to create a formatted print document with text, images, and alignment. The output is a file containing Star Markup that can be processed by cputil. ```php ``` -------------------------------- ### Generate mediaTypes for CloudPRNT Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/Readme_En.txt Generates a JSON array of supported media types for a given input print job file. This is used by CloudPRNT servers to inform clients about the available formats for a print job. The output is a JSON array of strings, each representing a media type. ```windows .\cputil.exe mediatypes sourceimage.png ``` ```linux-macos ./cputil mediatypes sourceimage.png ``` -------------------------------- ### cputil decode command Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md The `cputil decode` command converts print job data from one format to another, facilitating server-side preparation and client-side retrieval. ```APIDOC ## cputil decode ### Description Converts print job data from a specified input format to a requested output format. This is useful for servers that prepare jobs in one format and need to convert them to the format requested by the client. ### Method Command-line utility ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Command Usage - **Windows:** `.\cputil.exe decode ` - **Linux / macOS:** `./cputil decode ` Where: - `` is the target media type (e.g., `"application/vnd.star.starprnt"`). - `` is the path to the source print job data file. - `` is the path where the converted data will be saved. Use `-` or `[stdout]` to write to standard output. ### Request Example ```bash # Convert PNG to StarPRNT commands (Windows) .\cputil.exe decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin # Convert STM to StarPRNT commands (Linux/macOS) ./cputil decode application/vnd.star.starprnt starmarkup.stm outputdata.bin ``` ### Response #### Success Response Creates an output file containing the converted print job data. #### Response Example (The content of `outputdata.bin` will be binary printer command data.) ``` -------------------------------- ### Decode Printer Status with cputil Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Converts Star ASB (Auto Status Back) hexadecimal status codes from CloudPRNT devices into a human-readable JSON format. This helps in understanding printer states like online status, paper levels, and error conditions. ```bash # Decode printer status from ASB hex string to JSON # Linux/macOS ./cputil jsonstatus "23 86 00 00 00 00 00 00 00 00 00" # Windows .\cputil.exe jsonstatus "23 86 00 00 00 00 00 00 00 00 00" # Output: { "Online": true, "CoverOpen": false, "CompulsionSwitch": false, "OverTemperature": false, "Recoverable": true, "CutterError": false, "MechanicalError": false, "ReceiveBufferOverflow": false, "BlackMarkError": false, "PresenterPaperJam": false, "VoltageError": false, "PaperEmpty": false, "PaperLow": false } ``` -------------------------------- ### CloudPRNT MQTT Publishing API Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt This API allows you to publish MQTT messages to Star Micronics printers for various operations. It includes functions for requesting client status, sending direct print jobs with raw text, and sending print jobs referenced by a URL. ```APIDOC ## CloudPRNT MQTT Publishing ### Description This API enables the publishing of MQTT messages to Star Micronics printers using predefined topic patterns. It supports sending status requests, triggering POST requests, and dispatching print jobs. ### Methods #### Publish MQTT Message ##### Description Publishes a given payload to a specified MQTT topic. ##### Endpoint N/A (Function within SDK) ##### Parameters - **topic** (string) - Required - The MQTT topic to publish to. - **payload** (string) - Required - The message payload to send. ##### Request Example ```php $topic = "star/cloudprnt/to-device/YOUR_MAC_ADDRESS/request-client-status"; $payload = json_encode(["title" => "request-client-status"]); publishMqttMessage($topic, $payload); ``` #### Request Client Status ##### Description Requests the current status of a specific printer identified by its MAC address. ##### Endpoint N/A (Function within SDK) ##### Parameters - **mac** (string) - Required - The MAC address of the target printer. ##### Request Example ```php requestClientStatus("YOUR_MAC_ADDRESS"); ``` #### Send Direct Print Job (Raw Text) ##### Description Sends a direct print job containing raw text data to the printer. Includes options for printer control like cutting. ##### Endpoint N/A (Function within SDK) ##### Parameters - **mac** (string) - Required - The MAC address of the target printer. ##### Request Example ```php sendPrintJob("YOUR_MAC_ADDRESS"); ``` #### Send Print Job (URL Reference) ##### Description Sends a print job to the printer by providing a URL where the print data can be fetched. ##### Endpoint N/A (Function within SDK) ##### Parameters - **mac** (string) - Required - The MAC address of the target printer. - **jobUrl** (string) - Required - The URL pointing to the print job data. ##### Request Example ```php sendPrintJobWithUrl("YOUR_MAC_ADDRESS", "http://your.server.com/print/job/123"); ``` ### MQTT Topics Pattern - `star/cloudprnt/to-device/{MAC}/request-client-status` - Request printer status - `star/cloudprnt/to-device/{MAC}/request-post` - Trigger HTTP POST - `star/cloudprnt/to-device/{MAC}/print-job` - Send print job - `star/cloudprnt/to-server/{MAC}/...` - Messages from printer ``` -------------------------------- ### Convert print job to StarPRNT data Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/Readme_En.txt Converts a print job from a specified input format (e.g., PNG image or Star Document Markup) to StarPRNT printer command data. This is useful when a client requests a specific media type that the server does not natively support. The output can be written to a file or standard output. ```windows-png .\cputil.exe decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` ```linux-macos-png ./cputil decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` ```windows-stm .\cputil.exe decode application/vnd.star.starprnt starmarkup.stm outputdata.bin ``` ```linux-macos-stm ./cputil decode application/vnd.star.starprnt starmarkup.stm outputdata.bin ``` -------------------------------- ### Star Document Markup Template Field Data JSON Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Provide dynamic data for Star Document Markup templates using JSON. This JSON structure includes placeholders for text, numbers, and arrays, allowing for customizable receipt content and formatting. ```json { "store_name": " Star Cafe ", "order_number": "#2-007", "time": "10/16 11:13PM", "sales_type": "Walk-in", "server": "Jane", "transaction_id": "0123456789", "item_list": [ { "name": "Vanilla Latte", "unit_price": 4.99, "quantity": 1 }, { "name": "Chocolate Chip Cookie", "unit_price": 3.25, "quantity": 1 } ], "subtotal": 8.24, "tax": 0.73, "total": 8.97, "credit_card_number": "VISA 0123", "approval_code": "OK2443", "amount": 8.97, "address": "123 Star Road, City,\nState 12345", "tel": "123-456-7890", "mail": "info@star-m.jp", "url": "star-m.jp" } ``` -------------------------------- ### CloudPRNT Job Ready Poll Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/readme.md When a CloudPRNT compatible server has a print job ready, it must wait for a poll request from the client and reply with a JSON response indicating job readiness and available media types. ```APIDOC ## POST /cloudprnt/poll ### Description This endpoint is polled by the CloudPRNT client to check for available print jobs. The server responds with job status and supported media types. ### Method POST ### Endpoint /cloudprnt/poll ### Parameters #### Query Parameters None #### Request Body None (The client sends an empty POST request) ### Request Example (Client sends an empty POST request) ### Response #### Success Response (200) - **jobReady** (boolean) - Indicates if a print job is ready for the client. - **mediaTypes** (array of strings) - A list of media type names (e.g., "image/jpeg", "application/vnd.star.starprnt") in which the job can be provided. #### Response Example ```json { "jobReady": true, "mediaTypes": ["image/jpeg", "image/png"] } ``` ``` -------------------------------- ### Specify print area size for conversion Source: https://github.com/star-micronics/cloudprnt-sdk/blob/master/CloudPRNTSDKSamples/cputil/Readme_En.txt Specifies the print area size for image scaling and cropping during print job conversion. This option informs cputil about the target printer's width, enabling accurate image manipulation. Supported options include 'thermal2', 'thermal58' for 2-inch printers and 'thermal3', 'thermal80' for 3-inch printers. ```windows-2inch .\cputil.exe --printWidth thermal58 decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` ```linux-macos-2inch ./cputil --printWidth thermal58 decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` ```windows-3inch .\cputil.exe --printWidth thermal80 decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` ```linux-macos-3inch ./cputil --printWidth thermal80 decode "application/vnd.star.starprnt" sourceimage.png outputdata.bin ``` -------------------------------- ### Handle CloudPRNT Poll Response (PHP) Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt This PHP function handles POST requests from CloudPRNT printers, determining if a print job is ready and what media formats are available. It updates device status in a database and can handle client actions like requesting page information. It returns a JSON response indicating job readiness. ```php // Example poll response JSON when job is ready: { "jobReady": true, "mediaTypes": ["image/png", "image/jpeg", "application/vnd.star.raster", "application/vnd.star.starprnt"] } // Example poll response requesting device info: { "jobReady": false, "clientAction": [ {"request": "PageInfo", "options": ""}, {"request": "ClientType", "options": ""}, {"request": "ClientVersion", "options": ""} ] } ``` -------------------------------- ### CloudPRNT Poll Response API Source: https://context7.com/star-micronics/cloudprnt-sdk/llms.txt Handles POST requests from the printer to poll for new print jobs. The server responds with JSON indicating if a job is ready and what media formats are available. ```APIDOC ## POST /cloudprnt/poll ### Description This endpoint is used by the printer to poll for new print jobs. The server responds with a JSON object indicating whether a print job is available and the supported media types for the job. ### Method POST ### Endpoint /cloudprnt/poll ### Parameters #### Request Body - **printerMAC** (string) - Required - The MAC address of the printer. - **statusCode** (string) - Required - The current status code of the printer. - **clientAction** (array) - Optional - An array of client actions requested by the printer, such as 'PageInfo', 'ClientType', or 'ClientVersion'. - **request** (string) - The type of client action requested. - **result** (object) - The result of the client action (if applicable). - **printWidth** (string) - The print width reported by the printer. - **horizontalResolution** (string) - The horizontal resolution reported by the printer. ### Request Example ```json { "printerMAC": "00:11:22:33:44:55", "statusCode": "idle", "clientAction": [ {"request": "PageInfo", "options": ""}, {"request": "ClientType", "options": ""}, {"request": "ClientVersion", "options": ""} ] } ``` ### Response #### Success Response (200) - **jobReady** (boolean) - Indicates if a print job is ready for the printer. - **mediaTypes** (array) - An array of strings representing the supported media types for the print job (e.g., "image/png", "application/vnd.star.starprnt"). - **clientAction** (array) - If the printer requested client actions, this field may contain results. #### Response Example (Job Ready) ```json { "jobReady": true, "mediaTypes": ["image/png", "image/jpeg", "application/vnd.star.raster", "application/vnd.star.starprnt"] } ``` #### Response Example (Requesting Device Info) ```json { "jobReady": false, "clientAction": [ {"request": "PageInfo", "options": ""}, {"request": "ClientType", "options": ""}, {"request": "ClientVersion", "options": ""} ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.