I'm currently working on a project that involves me trying to send a ZPL-Label from a Browser to a Zebra Printer (ZQ520) using Javascript and Bluetooth.
Currently I'm able to find the printer via bluetooth 4.0 using its SUUID and its name. I'm also able to send small ZPL labels to the printer via 'characteristic.writeValue' and the printer prints them correctly immediately after I've sent them.
My main problem is that there is a max length a BLE transmission of a label can have. Anything shorter than 512 characters gets transfered and printed correctly.
If my label exceeds 512 characters, the printer throws a 'DOMException' and doesn't print anything.
My current code is:
navigator.bluetooth.requestDevice({
filters:[
{ name: 'deviceName' }, { services: [ServiceUUID] }
]
}
.then(device => {
console.log(device);
return device.gatt.connect();
})
.then(server => {
console.log(server);
serverInstance = server;
return server.getPrimaryService(ServiceUUID);
})
.then(service => {
console.log(service);
return service.getCharacteristic(commandCharacteristicUUID);
})
.then(characteristic => {
var zpl = "^FS^FT66,339^A0N,68,83^FDBeispieltext^FS^FT66,439^A0N,68,83^FDBeispieltext^FS^FT66,539^A0N,68,83^FDBeispieltext^FS^FT66,639^A0N,68,83^FDBeispieltext^FS^FT66,739^A0N,68,83^FDBeispieltext^FS^FT66,839^A0N,68,83^FDBeispieltext^FS^FT66,939^A0N,68,83^FDBeispieltext^FS^PQ1,0,1,Y^XZ";
var encoder = new TextEncoder();
var data = encoder.encode(zpl);
console.log(data);
return characteristic.writeValue(data);
})
.catch(error => {
console.log('Connection failed!', error);
});
The 512 Byte limit of the BLE connection is also documented in the BLE documentation of the printer: "The amount of data that can be written to the characteristic is the minimum of the remote connection’s ATT MTU and 512 bytes." https://www.zebra.com/content/dam/zebra/software/en/application-notes/AppNote-BlueToothLE-v4.pdf
How can I circumvent the issue? The actual label that I have to send, has a size over 2500 byte.
The documentation mentions that a 'Long Write' via Bluetooth is also possible. I assume there is also a possibility to write small batches of data to the printer instead of sending the whole label at once.
I'm just currently struggling to find the right syntax on how to do that via Javascript.