Pages

Sunday, February 26, 2023

AirPrint with Raspberry Pi and CUPS

 

AirPrint using a Raspberry Pi



After you succeed with these steps you will be able to print to CUPS printers from an iOS device.


CUPS = Common Unix Print Service

Steps:

0: Have an SSH connection or local terminal access to a Raspberry Pi. Also in this step make sure that the device you wish to print from and the CUPS server are on the same network.

I am 99% positive that all Pis have CUPS installed. But in any case, follow along.

Install CUPS 

First, we’ll install CUPS, which is a printing system by Apple Inc. for macOS and other UNIX-like operating systems. 

sudo apt install cups

We need to add the pi user to the lpadmin group

sudo usermod -a -G lpadmin pi

Allow CUPS access from anywhere in our LAN.

sudo cupsctl --remote-any

Edit the CUPS config file

sudo nano /etc/cups/cupsd.conf 

Change

Listen localhost:631  -----> Liten 631

And further down the file add Allow @local after the lines with "<Location>"




Restart CUPS for the changes to take effect.

sudo systemctl restart cups

Install drivers

sudo apt install printer-driver-gutenprint

Add printers as needed

Add your printer to CUPS as you normally do. In my case http://<piIPaddress>:631

Install avahi-daemon to allow service discovery.
That is what allows devices on the network to broadcast what they are and can do.

sudo apt install avahi-daemon

Start avahi-daemon.

sudo systemctl start avahi-daemon

Enable auto-start at boot time.

sudo systemctl enable avahi-daemon


IMPORTANT
If your iDevice cannot see the printer(s)

1) Make sure that the Pi, iDevice are on the same network.
2) Make sure that client isolation is disabled in your access point/wireless router. I reflashed my Pi about three times because I could not figure it out.

On the Xfinity Forums, they recommend disabling Hotspot on your gateway/router. That did it for me.

Before you get mad and reflash the Pi
Connect the Pi to the iPhone hotspot, for example, and the printer to the Pi; in my case, it was via USB. 
Restart CUPS and avahi-daemon

sudo systemctl restart cups
sudo systemctl retart avahi-daemon


On the pi open raspi-config and change the network connection to connect to your iPhone's hotspot. If you cannot ssh into it then hook up a monitor and keyboard.
This is just to let you vent the frustration of not seeing the printers on the iDevice. Then proceed to disable client isolation on your router. Don't forget to restart CUPS and avahi-daemon when you change networks.


Happy printing from the walled-garden.




Tuesday, December 15, 2020

Select unique random indexes from a list in Dart

The goal here is to select 4 unique index id's from a given list in Dart. 
Hardcoded: source list, how many numbers to pick, zero excluded, printing the selected items list as having 4 elements.




import 'dart:math';
void main() {
    List<int> numbers = [1, 2, 3, 4, 5,6,7,8,9];
  
 
  List<int> pickedList =[];
  
  /// pick 4 random numbers
  
  for(var i=0; pickedList.length <4 ;i++) {
        var picked = new Random().nextInt(numbers.length);
        // skip the generated 0
        if(picked >0 && !pickedList.asMap().containsValue(picked)) 
        {
            pickedList.add(picked);
        } //for i to 4
   } ///picked > 0 && not yet picked
  print('Here are you selected numbers. No repeats');
  
  print('=======');
  for (var i =0; i<4; i++) {
    print(pickedList[i]);
  }
//   print(pickedList.asMap());
} /// /main