glenndehaan / unifi-voucher-site

UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers
MIT License
27 stars 6 forks source link

Label Printing #37

Closed jlengelbrecht closed 2 weeks ago

jlengelbrecht commented 3 weeks ago

Hi there.

Playing around a bit more with this app, and trying to figure out the printer part of the app. I went out and purchased the following 80mm receipt printer.

I didn't see anything in the documentation on how this is supposed to be setup? I attempted to pass through the printer into the container, but the app does not seem to be able to see the printer. My plan was to pass this through into the container so mobile users of the app could just press the print button, and the printer that I passed through into the container is able to pick this up.

Is this not how the printing feature is supposed to work? Any guidance you could give me on this would be much appreciated.

Docker-Compose.yml

version: '3'
services:
  app:
    image: glenndehaan/unifi-voucher-site:latest
    ports:
      - "3003:3000"
    restart: unless-stopped
    devices:
      - "/dev/bus/usb/005/002:/dev/bus/usb/005/002"
    environment:
      UNIFI_IP: 'my-ip'
      UNIFI_PORT: 443
      UNIFI_USERNAME: 'Automationbot'
      UNIFI_PASSWORD: 'my-secret'
      UNIFI_SITE_ID: 'default'
      SECURITY_CODE: 'my-secret'
      DISABLE_AUTH: 'false'
      VOUCHER_TYPES: '1440,0,25000,25000,2048;4320,0,25000,25000,2048;10080,0,25000,25000,2048;'
      VOUCHER_CUSTOM: 'true'
      SERVICE_WEB: 'true'
      SERVICE_API: 'false'
      SMTP_FROM: 'my-gateway-email'
      SMTP_HOST: 'my-smtp'
      SMTP_PORT: '465'
      SMTP_SECURE: 'true'
      SMTP_USERNAME: 'my-gateway-email'
      SMTP_PASSWORD: 'my-secret'
      LOG_LEVEL: 'info'
glenndehaan commented 3 weeks ago

Hi,

Yeah the feature works a bit differently. Currently it only generates an 80mm compatible PDF that you could then send off to the printer. Seeing that your printer is a network enabled one you should still be able to send the PDF to the printer if the client has it configured. I was also looking at implementing direct ESC commands that would allow direct sends to compatible printers on a network. However I currently do not have such a compatible printer.

aroundmyroom commented 3 weeks ago

@jlengelbrecht how do you access the portal? Cause from your browser you print the PDF which you open through the portal. you just gave me an idea with this printer, cause price seems ok (shipping price is drama btw)

jlengelbrecht commented 2 weeks ago

@aroundmyroom I use Unifi's Identity Enterprise as an IDP. I currently have the app setup as a url redirect inside of the IDP. When someone comes to visit my wife or whom ever will access the app through the Identity Enterprise application which redirects to the apps endpoint in traefik. It works fairly seamless as it allows her and the family access to assigned applications all from with in Unifi's app. The problem is that on mobile it seems the printing option does not show. You can press the button but you don't get the box to save as a PDF like you normally would on a computer. This is why I initially thought that printing would be possible on mobile if the printer was passed through into the container. printing from the computer does not seem to be an issue. As mentioned above you can just save as a PDF and print. Hope that clears it up a bit.

glenndehaan commented 2 weeks ago

@jlengelbrecht,

Are you using iOS or Android? Because I did test this on Android and there it seems to work.

aroundmyroom commented 2 weeks ago

I use an iphone and when pressing the printer the PDF is opening in my screen and I can press the square with arrow below in the middle of the screen, scroll down and than press 'print' .. but that last part is part of the Phone's OS, rather than the voucher tool

For my use purpose I tell myself and my kids and wife to access the app, enter the pincode, create or use the voucher available and give them to their friends, family etc.. It gives them more problem to remember the URL to access the voucher system rather than creating one ;) (So If I understand you correctly, they can access the Identity Enterprise application and than just press the tile where there is no need for a code. the printing feature is a nice feature, but again: no cheap printers avail.

glenndehaan commented 2 weeks ago

Oke that is good to know. It could have something to do with the UID app. Maybe it stays within the app context and the app is not allowed to save files, but this is just purely speculation. I would need to see the flow in action to understand in what context we are then.

@aroundmyroom In terms of the 'remembering' of the url. The app is prepared to function as as PWA (Progressive Web App) on android it will prompt you to install it. But on iOS you can add it manually: https://www.macrumors.com/how-to/add-a-web-link-to-home-screen-iphone-ipad/

aroundmyroom commented 2 weeks ago

ah .. yeah if you want to use the app as PWA app within IOS it does not give the ability to print the PDF when the PDF is opened within the PWA .. actually the system would than be 'stuck' as the PDF part gives no option to return to the app

As I do not know if you want to support that, than there needs to be done some extra work I think .. Open the PDF differently probably so that the app can be working without opening the PDF within the app.

So two issues here for PWA usage: (within IOS) PDF is opened correctly but cannot print PDF is opened but you cannot go back to your 'control center of the voucher app'

glenndehaan commented 2 weeks ago

Yeah after reading some bugreports this has been an issue since the beginning. So unfortunately I won't be able to resolve this issue since this is part of the Safari codebase. I hope to get an escpos compatible printer soon, then if that implementation works it should be able to send the print directly to compatible printers

glenndehaan commented 2 weeks ago

Small update from my side, I have been working on getting escpos printing working since my printer has arrived. And here is the first result from the prototype. All seems to be looking good. I need to refactor the print functionality within the app first and I will then add the feature. This will allow escpos printers on the network to receive the print from the container itself without the client needing to add the printer locally.

20240829_211040

glenndehaan commented 2 weeks ago

I have just released version 3.4.0 this version implements support for ESC/POS network enabled printers. The means the app can send the print server side to the printer. Therefore the client does not need to have the printer installed locally. Please see the readme on how to configure this if you have a supported printer: https://github.com/glenndehaan/unifi-voucher-site#print-functionality

I will be closing this issue since there are now 2 methods available to get prints off to a supported printer