Trigger IP display on printer

Install the portlister plugin and configure your connection's port and baudrate and check the option to autoconnect. Then when you power off the printer and power it back on OctoPrint will automatically connect to the printer and then my plugin will send the IP to the LCD. That's probably the missing piece for your issue.

1 Like

Oooh, that sounds like exactly what's needed. Will give it a try. Thanks!

(And thanks for the onIPConnect plugin too!)

So I installed the PortLister plugin, but I'm not sure how to make Octoprint auto-connect.

I see the checkbox that says "Auto-connect on server startup," but checking that doesn't seem affect the behavior when I just cycle the printer power.

Am I missing another setting somewhere?

make sure the port and baud rate are set and not set to auto.

you may need to mess with the portlister settings for autoconnect delay as well.

Another thought would be to run a scheduled script on the RPi that checks the IP address and if it has changed, send an email, SMS, or a message with one of the other messaging applications.

@jneilliii Yeah, I set the port and baud rate. I'll try messing with the autoconnect delay.

@b-morgan That's an interesting idea.I could just write a little Python script that sends a UDP packet to a server every 15 minutes. I'm hesitant to write something odd that I'll have to remember the details of in a few months.

The RPi has a hostname associated with it (default is octopi) and in many larger networks, its name isn't octopi.local but octopi.<local dns domain>. Also you may not be the only OctoPrint user on your university network, so I'd change the hostname to something more unique to you. Then see if that hostname is resolvable.

@b-morgan I have 12 printers, and they all have unique hostnames, and I do control their DNS. Maybe I just need to install some dynamic DNS updater.

Looks like maybe something like this would work:

curl -D- -X PUT -H "Content-Type: application/json" \
        -H "X-Api-Key: $APIKEY" \
        -d "{\"rrset_name\": \"$SUBDOMAIN\",
             \"rrset_type\": \"A\",
             \"rrset_ttl\": 1200,
             \"rrset_values\": [\"$MY_IP\"]}" \
        $CURRENT_ZONE_HREF/$SUBDOMAIN/A

(from using gandi livedns as a Dynamic DNS server - Nicolas Herbaut, Associate Professor)

I assume all the printers use DHCP to obtain their IP address(es). Normally the DHCP server communicates with the DNS server so that when an IP address changes, DNS is automagically updated.

When a DHCP client asks for a new lease, it asks for the same IP address as it had previously. Are you turning the RPi systems off for extended periods? I turn my 3D printer off when I'm not using it but the RPi is left on. Even 12 of them won't consume that much power so I'd just leave them running.

Yes, everything you describe is correct, except that the university occasionally reconfigures its network, which gives all 12 printers new IPs. Most of the printers are running close to 24 hours per day, at least when school is underway, so they don't get turned off much.

I set up our domain name so that I wouldn't have to rely on the university to add new printers and such. Generally, it's worked fine, but this week, they're switching things around to debug some network problem, so I thought it would be worth trying to sort this out.

One other thing I just thought of that could interfere with this is if your printer is backpowered from the USB connection of the pi. This would prevent the printer from disconnecting altogether possibly. From memory you select the port and baudrate check the two boxes in the connection pane and click Connect. Once that is done the portlister plugin in theory should work.

Backpowering is certainly a possibility, though the printer does give the appearance of rebooting when the printer power is cut. Still, the USB port could possibly remain up?

Yeah, if the USB is able to power the printer's main board then a connection would already be established when the power was turned on I think. Which means portlister is probably already seeing the connection established and doesn't try to initiate the connection.

You mentioned you see other octopi.local announcing on the same network. Have you tried changing the host name of your device?

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.