-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outline reference code for use cases that use long polling e.g printing or synchronisation with other systems #61
Comments
I tried
Once the printer was installed, this is a basic discovery command: brother_ql -b pyusb discover
deprecation warning: brother_ql.devicedependent is deprecated and will be removed in a future release
INFO:brother_ql.output_helpers: Found a label printer: usb://0x04f9:0x2042_Љ (model: unknown)
usb://0x04f9:0x2042_Љ if you have say a brother_ql -b pyusb -m QL-700 -p usb://0x04f9:0x2042 print -l 62 ~/Downloads/sample_label.jpg Haven't cleaned this example up, but here's an extremely simplistic example of printing the same JPG via a python script: from brother_ql import BrotherQLRaster, create_label
from brother_ql.backends.helpers import send
from brother_ql.backends import backend_factory, guess_backend
from PIL import Image, ImageDraw, ImageFont
# Printer model and label size setup
PRINTER_MODEL = 'QL-700' # Adjust to your printer model
LABEL_WIDTH = 696 # Common width in pixels for 62mm labels
LABEL_HEIGHT = 200 # Adjust for the height of your label
def create_basic_label(text):
# Read the image from ~/Downloads/sample_label_mta_australia.jpg
image = Image.open('/Users/devraj/Downloads/sample_label_mta_australia.jpg')
return image
def print_label(text, printer_model=PRINTER_MODEL):
qlr = BrotherQLRaster(printer_model)
# qlr.exception_on_warning = True # Enable warnings if needed
# Create label image and render to raster data
label_image = create_basic_label(text)
create_label(qlr, label_image, "62")
# Define backend and specify the printer connection
backend = 'pyusb' # 'pyusb' for USB, 'network' if using network
printer_identifier = 'usb://0x04f9:0x2042' # Replace with actual printer USB ID or network IP
# Send the print job
send(instructions=qlr.data, printer_identifier=printer_identifier, backend_identifier=backend)
# Print a label with simple text
print_label("Hello, World!") |
The following are some observations regarding events raised in the Command Centre when a door access is granted. This is to support the research I am doing around printing. For our demo command centre if we get a list of groups and read through the event types we will find that {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/groups/23",
"id": "23",
"name": "Card Event",
"eventTypes": [
{
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/15800",
"id": "15800",
"name": "Access Granted - Mobile Reader"
},
{
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/15815",
"id": "15815",
"name": "Card presented (Controlled Challenge) – Mobile Reader"
},
{
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/15816",
"id": "15816",
"name": "Card Exit Granted - Mobile Reader"
},
{
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/20001",
"id": "20001",
"name": "Door Access Granted"
},
{
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/20002",
"id": "20002",
"name": "Level Access Granted"
}
]
} In particular we want to track {
"card": {
"facilityCode": "P61405",
"issueLevel": 1,
"number": "Card App"
},
"cardholder": {
"firstName": "Devraj",
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/cardholders/9985",
"id": "9985",
"lastName": "Mukherjee",
"name": "Mukherjee, Devraj"
},
"division": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/divisions/2",
"id": "2",
"name": "Root Division"
},
"entryAccessZone": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/access_zones/9992",
"id": "9992",
"name": "Anomaly Demo Access Zone"
},
"group": {
"id": "23",
"name": "Card Event"
},
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/4715",
"id": "4715",
"message": "Mukherjee, Devraj was granted entry into Anomaly Demo Access Zone through Anomaly Demo Door.",
"priority": 1,
"source": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/doors/9991",
"id": "9991",
"name": "Anomaly Demo Door"
},
"time": "2024-07-29T10:32:21Z",
"type": {
"id": "20001",
"name": "Door Access Granted"
}
} the command used to produce the above is: http get https://commandcentre-api-au.security.gallagher.cloud/api/events\?group\=23 "Authorization: GGL-API-KEY $GACC_API_KEY" this will produce |
To conclude the example of printing to a label printer on an event. Here's a simulated event to trigger the polling script to trigger a print. Quoting Gallagher's documentation there are limitations (understandably) on what sort of events you can create via the API:
This is a echo -n '{
"type": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/events/types/4000"
},
"source": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/doors/9991"
},
"priority": 1,
"message": "Via API Mukherjee, Devraj was granted entry into Anomaly Demo Access Zone through Anomaly Demo Door.",
"details": "",
"cardholder": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/cardholders/9985"
},
"entryAccessZone": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/access_zones/9992"
},
"door": {
"href": "https://commandcentre-api-au.security.gallagher.cloud/api/doors/9991"
}
}' | http post https://commandcentre-api-au.security.gallagher.cloud/api/events "Authorization: GGL-API-KEY $GACC_API_KEY" |
Is your feature request related to a problem? Please describe.
One of the obvious use cases for the long poll functionality is calling other systems as events progress on the command centre e.g printing of labels or synchronisation with other systems. It would be useful to provide a reference implementation of how this could work for
Describe the solution you'd like
Ideally we would like to provide this as a complete solution for printing and or synchronisation, but for this exercise we would just want to implement something that sits in the
samples
folder and provides a starting point for how this could work.Additionally provide a list of hardware that the users can use with the library.
Describe alternatives you've considered
NA
Additional context
The text was updated successfully, but these errors were encountered: