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.