Trigger IP display on printer

Hi @pingswept

Not sure which version of Octopi that your running, but here is my /etc/netplan config. Start with:

sudo apt install -y wpasupplicant net-tools

ls /etc/netplan/

sudo nano /etc/netplan/00-installer-config.yaml

add this, modify to match your network:

network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
    wifis:
        wlp2s0:
            optional: true
            access-points:
                "XXXXXXX":
                    password: "XXXXXXXX"
            dhcp4: false
            addresses:
                - 192.168.0.115/24
            nameservers:
                addresses:
                    - 192.168.0.1
            gateway4: 192.168.0.1

sudo netplan generate

sudo netplan apply

sudo reboot`

The spacing of this is important. Use a yaml validator to check it.

`

Could you explain a little more why this is useful and what it fixes?

This will set a static IP address on your Octopi, therefor you will always have the same IP address. Doesn't give you the IP on your display like you were asking, but since you will already know what your IP address is, you won't need the IP displayed on your LCD.

So I think @jneilliii was correct in his supposition that the USB port was backpowered by the Pi, or at least for some reason the portlister plugin didn't see an event that would make the ipOnConnect plugin send the IP to the printer. But I think I found a reasonable solution.

I wrote a short script that sends the hostname and IP in a UDP packet to a remote server (a web server that I have access to).

#!/bin/bash
echo $HOSTNAME has the IP $(hostname -I) as of $(date +%c) > /dev/udp/66.228.32.1/8000

Then I set a cron job to run every five minutes using crontab.

*/5 * * * * /home/pi/broadcast-ip.sh

Then I log into my remote server and run netcat like this: nc -luk -p 8000

Every five minutes, I see something like this, which allows me to harvest the IPs I need:

p3 has the IP 10.247.108.24 as of Wed 13 Apr 2022 18:35:01 BST
p11 has the IP 10.247.73.254 as of Wed 13 Apr 2022 18:35:01 BST
p6 has the IP 10.247.84.216 as of Wed 13 Apr 2022 18:35:01 BST
p5 has the IP 10.247.68.182 as of Wed 13 Apr 2022 18:35:01 BST
p12 has the IP 10.247.112.27 as of Wed 13 Apr 2022 18:35:01 BST
p9 has the IP 10.247.96.44 as of Wed 13 Apr 2022 18:35:01 BST
p8 has the IP 10.247.112.38 as of Wed 13 Apr 2022 18:35:01 BST
p4 has the IP 10.247.72.69 as of Wed 13 Apr 2022 18:35:01 BST
p2 has the IP 10.247.96.42 as of Wed 13 Apr 2022 18:35:01 BST
p10 has the IP 10.247.84.94 as of Wed 13 Apr 2022 18:35:02 BST
p7 has the IP 10.247.80.158 as of Wed 13 Apr 2022 18:35:02 BST

I deploy the script and cron job to our fleet of printers with Ansible:

ansible-playbook -i ansible-inventory.ini printer-tasks.yaml, where printers.yaml contains what's below.

---
- hosts: printers
  remote_user: pi
  tasks:
    - name: Add periodic task to broadcast hostname and IP via UDP periodically
      ansible.builtin.cron:
        name: "broadcast-ip"
        minute: "*/5"
        job: "/home/pi/broadcast-ip.sh"
    - name: Add broadcast script
      ansible.builtin.copy:
        src: ./broadcast-ip.sh
        dest: /home/pi/broadcast-ip.sh
        owner: pi
        group: pi
        mode: '0744'

Works pretty well so far. If anyone else wants to use this code, you're welcome to.

New development, if I automate more of the printer maintenance, will appear here.

Thanks for the help, everyone who commented, in helping me narrow down what was going wrong, even if I never really nailed down the exact cause. In any case, my problem is solved.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.