User avatar
HermannSW
Posts: 2533
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Show Raspberry Pi IP-address on PWR led on boot

Sat Dec 14, 2019 4:41 pm

I just read on sending IP-address per email out:
https://www.raspberrypi.org/forums/view ... 3#p1578898

Where I am now you have to login to Wifi via a web page.
So I could try to figure out how to automate the Wifi login and send an email.

I thought what to do in case there is no internet access, and how to signal the IP-address without help.
The ACT activity LED is too busy, so I chose the PWR led (sorry PiZero).

The script can be executed at boot as described in above posting:

Code: Select all

$ cat signal_ip_pwr 
#!/bin/bash

ini() { echo gpio | sudo tee /sys/class/leds/led1/trigger
}
exi() { echo input | sudo tee /sys/class/leds/led1/trigger
}

d() { echo $1 | sudo tee /sys/class/leds/led1/brightness
}

p() { sleep 1
}
s() { sleep 0.4
}
b() { d 1; sleep 0.$(($1?8:1)); d 0; s;
}

ini; d 0; p; d 1; p; d 0; p; 

#b 0; b 0; b 0; b 1; b 1; b 1; b 0; b 0; b 0; p; exi
#exit

for d in `ifconfig | grep broadcast | cut -f2 -dt | cut -f2 -d\   | sed "s/\./ /g"`
do
  for((p=128; p>0; p/=2))
  do
    b $((($d & $p) != 0))  
  done
done

p; exi
$
It does determine the internal Wifi IP (needed to access from other PIs/laptop), toggle PWR led off, on and off for 1 second, and then sends the 32 bits of ipv4 address.
Finally it waits with PWR led off a second, and then switches back to normal PWR led operation.

I was not able to make notes of the bits while seeing on paper.
But I took a smartphone video, and watching that video allows to stop and take notes ... ;-)
IP-address signalled in the video is 172.27.1.22
(1010 1100 0001 1011 0000 0001 0001 0110);
https://www.youtube.com/watch?v=m4pM8KD ... e=youtu.be


P.S:
The script is kind of followup of script from "flag_semaphore att rest R A S P B E R R Y read" thread using servos for signalling:
https://www.raspberrypi.org/forums/view ... ?p=1550959
Last edited by HermannSW on Sat Dec 14, 2019 8:49 pm, edited 2 times in total.
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

emma1997
Posts: 762
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Show Raspberry Pi IP-address on PWR led on boot

Sat Dec 14, 2019 8:36 pm

A great solution but IMO basic decimal blinks would make it easier to enter IP in the other computer. Flag semaphore or whatever the new one is don't seem ergonomic. Might be easier to decode realtime if it was more familiar?

hippy
Posts: 7361
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Show Raspberry Pi IP-address on PWR led on boot

Sun Dec 15, 2019 8:37 am

Installing espeak and adding a cheap 5V powered speaker allows a Pi to speak its IP address which I have found a perfect way to do it.

And that alerted me to anbox ( an android emulator ) having created multiple extra IP addresses after I'd installed it which I hadn't noticed until I rebooted that Pi and got multiple IP addresses spoken.

And that leads to the question; what exactly is a Pi's IP address ? They don't always just have one. That could be an awful lot of LED flashing which it seems a user would be hard pushed to keep up with.

User avatar
HermannSW
Posts: 2533
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Show Raspberry Pi IP-address on PWR led on boot

Sun Dec 15, 2019 3:07 pm

hippy wrote:
Sun Dec 15, 2019 8:37 am
Installing espeak and adding a cheap 5V powered speaker allows a Pi to speak its IP address which I have found a perfect way to do it.
Nice solution, but with extra hardware.

And that leads to the question; what exactly is a Pi's IP address ? They don't always just have one.
I am not a network expert, but there was a reaseon that in the script I grep for "broadcast" first.
On Pi[34] and Pi2 with USB Wifi dongle that leads to one IP address to be signalled.
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

mattmiller
Posts: 2230
Joined: Thu Feb 05, 2015 11:25 pm

Re: Show Raspberry Pi IP-address on PWR led on boot

Sun Dec 15, 2019 3:48 pm

The ACT activity LED is too busy, so I chose the PWR led (sorry PiZero).
I think I remember doing this a few years ago and once you've taken control of the green led on the PiZero - it doesn't get activity updates until the program hands back control

And IIRC, the PiZero LED is inverted compared to the big Pis

But my memory may be in error - I'm starting to lose bits nowadays and my error-correction algorithms are not what they used to be :)

User avatar
HermannSW
Posts: 2533
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Show Raspberry Pi IP-address on PWR led on boot

Fri Dec 20, 2019 10:43 pm

hippy wrote:
Sun Dec 15, 2019 8:37 am
Installing espeak and adding a cheap 5V powered speaker allows a Pi to speak its IP address which I have found a perfect way to do it.
I followed your proposal, but using smartphone headphones in Pi 3.5mm jack.
espeak did not work for me, so I used aplay instead.
Find complete solution in thread "aplay_ip_address on Raspberry Pi during boot":
https://www.raspberrypi.org/forums/view ... 6&t=259891
Here is sample sound:
https://www.youtube.com/watch?v=Mj4Vk8VeRPg
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

hippy
Posts: 7361
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Show Raspberry Pi IP-address on PWR led on boot

Sat Dec 21, 2019 1:36 pm

HermannSW wrote:
Fri Dec 20, 2019 10:43 pm
hippy wrote:
Sun Dec 15, 2019 8:37 am
Installing espeak and adding a cheap 5V powered speaker allows a Pi to speak its IP address which I have found a perfect way to do it.
espeak did not work for me, so I used aplay instead.
'espeak' can be a major pain due to ALSA throwing errors left right and centre but it does seem to work in conjunction with 'aplay' using ...

espeak "Hello World" --stdout | aplay 2> /dev/null

Might be worth a try. Your 'aplay' version sounds good, more natural than 'espeak'. I'll check that out in more detail later. Thanks.

User avatar
HermannSW
Posts: 2533
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Show Raspberry Pi IP-address on PWR led on boot

Sat Dec 21, 2019 11:38 pm

hippy wrote:
Sat Dec 21, 2019 1:36 pm
'espeak' can be a major pain due to ALSA throwing errors left right and centre but it does seem to work in conjunction with 'aplay' using ...

espeak "Hello World" --stdout | aplay 2> /dev/null

Might be worth a try. Your 'aplay' version sounds good, more natural than 'espeak'. I'll check that out in more detail later. Thanks.
THANK you!
While I might not use espeak for the until now aplay only solution I posted, you made espeak usable for me (and others!) despite the ALSA mess.
<EDIT>
I did test, this command line in /etc/rc.local does "espeak" IP address on headphone on reboot:

Code: Select all

pi@raspberrypi4B:~ $ tail -10 /etc/rc.local
# By default this script does nothing.

# Print the IP address
sleep 15  # workaround for Buster
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  hostname -I | sed "s/\./dot/g" | espeak --stdout -p 5 | aplay 2>/dev/null
fi
exit 0
pi@raspberrypi4B:~ $ 
</EDIT>

Default pitch 50 was way too fast to recognize the IP address.
And only the first number got spoken correctly (one hundred seventy two).
The dots of IP address confuse espeak.
I did sed the "." as "dot" and all is fine.
Yesterday I learned that for uploading sound only to youtube you need to convert to video, and how to overlay with a jpg still image:
https://superuser.com/a/1041818

The overlayed screenshot shows how I created the youtube video:
https://www.youtube.com/watch?v=z3R0U77-cLY

P.S:
espeak reminds me of C64 Basic "say" command back in 1982!
As German I liked these two sounds generated:
say "*" --> asterisk (same with espeak)
say "#" --> railroad crossing ("hash" with espeak)
Attachments
espeak.ip.png
espeak.ip.png
espeak.ip.png (177.75 KiB) Viewed 1023 times
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

hippy
Posts: 7361
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Show Raspberry Pi IP-address on PWR led on boot

Sun Dec 22, 2019 2:30 pm

HermannSW wrote:
Sat Dec 21, 2019 11:38 pm
THANK you!
While I might not use espeak for the until now aplay only solution I posted, you made espeak usable for me (and others!) despite the ALSA mess.
And it truly is a mess. No one seems to know why, nor seems to be getting it fixed, or can even say who should be fixing it. The only 'solution' which has been reported to work I have seen is to roll the kernel back. Not ideal.

The ALSA mess also affects 'aplay' in some circumstances, can cause the first second or so of output to not appear and the output may be truncated, losing stuff at the end.

Hopefully it will get fixed one day. I have my Pi's speak when they boot up and I sometimes hear these ALSA bugs but it hasn't been too problematic for me. I'm using a Python program to monitor a button so I can have it speak again as well as give other information, reboot and shutdown so it truly can be a headless system I don't need to connect into.

I did my IP address parsing in that Python program so I could convert "." to a spoken "dot", also put spaces after each digit so "192" becomes "one, nine, two" rather than "one hundred and ninety two" etc, and handled multiple IP addresses.

Code: Select all

def IpAddress():
  s = os.popen("hostname -I").read().strip()
  result = ""
  for c in s:
    if   c == "." : result = result + " dot"
    elif c == " " : result = result + ". Plus"
    else          : result = result + " " + c
  return "My IP address is" + result + "."

Return to “Raspberry Pi OS”