auto-display ip address on a raspberry pi

Here’s a quick one.  I like using a pi as a server for things like mqtt, but with my experimentation I bring it back and forth between home and my local hackerspace.  Now, sane people might use DNS to find the mqtt server, I had trouble with that and gave up.  I can usually guess the ip address because the router holds on to the one it gave me last time, but that doesn’t always work.  Here’s how I decided to have the headless pi tell me the ip it is connected at.

I tried doing this with an HD44780, I have seen people do it with a 10k pot and no other electronics between the pi and display.  I tried for a day and couldn’t make that work.  My next option was to but a display on a breakout board for the pi, then I can’t doubt my wiring and it either works or it doesn’t.  It turns out that a nokia 5110 display is really cheap on ebay, so I looked around briefly and figured that I could get it working when it came in.

Here’s what I found:

the unit I got was wired to gpio that is not on the hardware spi bus, but the pins seemed the same as the one described in this article.

That means using the adafruit libraries described here.

The contrast sucks with the initial image test, but the text looks ok.

I needed to get my ip address in python, I used netifaces as described here.

That broke when there was no cable plugged in, so I caught the exception like this.

I wanted the hostname as well, so I used socket, like this.

I wanted it to start on boot so I used rc.local as found here.

my final code is located on my github here.

2 Responses to “auto-display ip address on a raspberry pi”

  1. Intro to my ESP8266 adventures | Evan's Techie-Blog Says:

    […] Setting up a raspberry pi mqtt server to display the IP and hostname on a Nokia LCD […]

  2. Amazon Dash Button Re-Hack! | Evan's Techie-Blog Says:

    […] arp packet and prints out to the terminal and sends a mqtt command.  I run all this on my mqtt server pi and have it autostart just like the screen […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: