Appnotes Creating Weblink Endpoint Rev1 English
Appnotes Creating Weblink Endpoint Rev1 English
Date: 6/21/2015
Topic: Creating your own Weblink endpoint.
Overview: A description of to how to use the Weblink feature in Link-OS printers
with your own WebSocket server.
Introduction:
This document describes how to configure a standard WebSocket server to communicate to
Zebra Link-OS printers. It contains information showing how to configure a WebSocket server
and create initial communications to a printer.
Target Audience:
Developers and IT personnel who wish to:
Print labels, invoices, receipts, or encode RFID tags from their web pages.
Create a secure and encrypted connection to Zebra printers from either an on premise a
cloud based webserver.
This document is intended for users who have a working knowledge of WebSockets, seeking to
create a WebSockets connection utilizing PHP and .NET and other development environments.
Key Considerations:
This document does not cover all potential issues. Network configuration, firewalls, proxies, and
other considerations still have to be accounted for when setting up printers to communicate via
WebSockets. See the ‘Using Weblink’ section of the ‘Zebra Programming Guide for SGD, ZPL,
and Weblink’ document for information on how to get the printer’s Weblink log in order to help
troubleshoot connectivity issues.
Page 1 of 9
Zebra Application Note
Server Configuration
To be able create a websockets connection with the Link-OS printer, the server you choose
must support WebSockets. In addition, there are important steps you’ll need to take to in order
to properly connect from the server to the printer. These steps will allow you to communicate
from the server to the printer over the “Raw” or Configuration channels.
The Weblink feature within the printer uses a WebSocket implementation compliant with RFC
6455 (https://tools.ietf.org/html/rfc6455). However, the printer only supports Binary frames. If the
printer receives text frames it will terminate the connection with response code 1003 indicating
that only binary frames are acceptable.
The Weblink implementation on the printer also requires that the HTTP header ‘Content-Length’
be set to 0 when the upgrade response is sent back to the printer. Typically server
implementations will allow the server-side application to provide additional headers or override
existing headers. This may be required for your application when the WebSocket upgrade is
performed. See the example HTTP handshake in the next section for an example.
SSL Configuration
The printer will only communicate via HTTPS. There are a few configuration settings that are
required for the printer to connect. Ensure that your server’s SSL configuration at least meets
these requirements:
Double click on the clip image to the right to open the file:
Page 2 of 9
Zebra Application Note
If there are any issues when connecting, be sure to review the ‘Using Weblink’ section of the
‘Zebra Programming Guide for SGD, ZPL, and Weblink’ document. It contains tips that are
helpful when troubleshooting SSL connection issues.
Page 3 of 9
Zebra Application Note
Here is a sample of the Zebra Discovery Packet JSON message (content trimmed from its
original length for brevity):
{
"discovery_b64" : "OiwuBAIBAAFaQlIAAFgAAAA ..."
}
If the printer is configured to send alerts via Weblink (see the section below titled Unsolicited
Alerts) alerts will be sent by the printer over the Main channel. They can either be parsed or
ignored depending on your needs.
The main channel is also used to open one of two other channels: Raw and Configuration. The
Raw channel is similar to the TCP Raw port that is typically listening on port 9100, or any
connections via USB, Bluetooth, Serial, or Parallel. The Raw channel will accept any ZPL,
CPCL, SGD commands, etc. that are supported by the TCP, USB, Serial, connections.
The Configuration channel is similar to the TCP Raw port that is typically listening on port 9200.
The Configuration channel will only accept JSON formatted SGD-like commands that are used
to modify or read the printer’s settings.
Depending upon your use case, you will need to open one of the two channels (or both at the
same time). To do so, the following message will need to be sent to the printer via the Main
channel. Substitute in the correct channel for your use case. Note that if you wish to open both
channels, one request must be done for each channel request. They cannot be combined into a
single request.
Page 4 of 9
Zebra Application Note
Each request to open a new channel will result in the printer opening a totally new connection.
To determine the type of the channel you may look at the WebSocket protocol string or the
initial JSON message sent by the channel. The Raw and Configuration channels do not send
the Zebra Discovery Packet, but instead send the details of the new connection/channel. Here is
an example message after connecting the Raw channel:
{
"unique_id" : "XXXYYYZZZ",
"channel_name" : "v1.raw.zebra.com",
"channel_id" : "2"
}
The ‘channel_id’ field in the message is the unique ID given to that channel. It can be useful
when troubleshooting printer Weblink issues as the ID shows up in the Weblink log (See Zebra
Programming Guide for SGD, ZPL, and Weblink for more information on how to view the
Weblink log).
1. Point the printer’s weblink location to your server and reboot the printer. Note that the
server DNS name must match that of the Common Name field within the server SSL
certificate.
2. Wait for the Main channel to connect
3. Send the following JSON message to the printer via the Main channel:
{
"open" : "v1.raw.zebra.com"
}
Page 5 of 9
Zebra Application Note
1. Point the printer’s weblink location to your server and reboot the printer. Note that the
server DNS name must match that of the Common Name field within the server SSL
certificate.
2. Wait for the Main channel to connect
3. Send the following JSON message to the printer via the Main channel:
{
"open" : "v1.config.zebra.com"
}
{}{"device.friendly_name":null}
6. The printer should respond with the friendly name in a JSON message
Closing Connections
To close the connection from the server, simply use the WebSocket library for your
server to cleanly close the connection. This will likely require a close code. Typically the
close code used for normal closures is 1000.
Unsolicited Alerts
The printer can send unsolicited alerts over the Main Weblink channel if the printer is
configured to do so. You can either register for individual alerts or register for all of
them. The following is how to register for alerts and the response to expect when an
Unsolicited Alert is send over the Main Channel. Note that the ‘configure_alert’ payload
is that of the ZPL ^SX command and the alerts.add SGD. Please see the Zebra
Programming Guide for SGD, ZPL, and Weblink for more information.
Page 6 of 9
Zebra Application Note
The ‘condition_id’ and ‘condition_state’ indicate the Alert name and if it was “set” or
“cleared”. They will always be returned in English regardless of the printer’s language
Page 7 of 9
Zebra Application Note
configuration. However, ‘condition’ will be translated similar to the printer front panel
alerts. The ‘unique_id’ indicates the device.unique_id of the printer (sometimes referred
to as the printer serial number)
Ping / Pong
The printer will send a PING message roughly every 60 seconds. The server needs to respond
with a PONG per the requirements detailed in RFC 6455 (https://tools.ietf.org/html/rfc6455)
otherwise after three failed PING attempts the printer will disconnect and attempt to reconnect.
Page 8 of 9
Zebra Application Note
Document Control
Disclaimer
All links and information provided within this document are correct at time of writing.
Page 9 of 9