Blink IP address on headless Raspberry PiAugust 14 2020
I often have this problem. I have a headless (no monitor or keyboard) Raspberry Pi, put a flash card in already configured for my network (using another Raspberry Pi), and it connects to my network. But I don't what IP address my DHCP server assigned to it, so I can't connect to it via SSH or WWW.
I can look on my router to see what address was just assigned, but that's awkward and not practical if it's on someone else's Wi-Fi network.
So I wrote this Python script which blinks the last digits of the IP address on the built-in status LED of a Raspberry Pi after boot up. But rather than using Morse code (too complicated), I blink it out the digits as roman numerals, with 'I' (1) being a short blink, 'V' (5) being a medium long blink and 'X' (10) as a long blink. I use X to represent the digit zero. That way I don't have to try to count 8 or 9 blinks sometimes.
Each decimal digit is blinked separately, so 102 is blinked as I X II, not CII
If the second last octet of the IP4 address is a zero (which it usually is), it is omitted.
So if my Pi is assigned 192.168.0.249, it will only blink "249".
Sometimes Wi-Fi will initialize with a bogus IP address but not connect, in which case, you may recognize that the last two octets blinked out don't match your network at all.
Example blink patterns:
Short blinks (I) are 0.1 seconds long
The IP address is blinked after boot completes, waiting for Wi-Fi to initialize. The IP address is blinked ten times, with a three second pause between. After that the status LED is returned to its default functionality, to blink on flash card access. On Raspbery Pi zero W, there is only one green LED used for power and status, so it blinks that one. On other Pi's, it blinks the green status LED.
The script needs to run as root. If you run it, it will check hat it has an IP which isn't changing,
then blinks the IP address. There is also an "install" option to add it to root's crontab
to make it run at startup.
You can get this this script from github here
Or by typing
or via this link: http://woodgears.ca/tech/blink_ip.py
Update, Sep 11 2020:The raspberry pi block has linked to this video and github, nicely written up:
And as with my video, lots of comments to the effect of "why not just use method ___ instead". There are other methods, yes. I wasn't aware that DHCP servers these days will allow you to just refer to hostname.local (where hostname is the network name of the device). If I had known this, I might not have published this script. But I still like to have this script on all my pi's lying around. That way, when I power one up, I can just look at it to figure out what the address of THIS Raspberry Pi is. No need to install an app on a phone, figure out the MAC address, check the DHCP server or any of it, or figure out what hostname I happen to have this Pi configured to.
Squirrel shooter fail (video only, 2019)
My imgcomp program (motion triggered time-lapses, 2016)
More tech stuff on my website:
The cheapest USB scope I could find (video only, 2019)
What's inside a Sonicare toothbrush (video only, 2019)
Braun hand mixer speed control fix (video only, 2019)
booster dish (2014)
Figuring out a mystery motor (video only, 2019)
Does dusting out a fridge reduce power? (video only, 2019)
Physics related articles
To my Woodworking website.