I'm a bit of a Raspberry Pi noob so I'm having a problem that I haven't been able to solve.
I'm using a Raspberry Pi 4 with OctoPi at the university where I am studying. The IT department has allowed me to connect the Raspberry to the network via an ethernet cable. To access OctoPrint I have to fill in the IP address of the ethernet connection in the browser. However, the IP address changes regularly as it's running a DHCP server. So I would need to know the IP address everytime it changes.
I found a video that shows that you can have your Raspberry Pi send you an e-mail with the IP address in it. You can see the video here: Have your RPi email you its IP address on startup - YouTube. The maker of the video has Raspbian installed on his Raspberry so he can easily write the script that sends the e-mail. With OctoPi installed, I don't know how to do the same. I found out that you can install a Desktop GUI on OctoPi so I tried that, but I didn't manage to get it to work.
What I did was:
I found that I had to install the desktop environment, lightdm and xinit. At first I only managed to install the desktop environment but that wouldn't work without the others. I figured I should update everything to make sure the latest firmware was running but that wouldn't work either. The message I got was:
'Index of /raspbian buster InRelease' changed its 'Suite' value from 'testing' to 'stable' N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
I found someone online who said to use this command:
sudo apt-get update --allow-releaseinfo-change
This then allowed me to update using sudo apt-get update
After this I could finally succesfully install the desktop, xinit and lightdm. However, when I open the desktop with sudo startx I get a black screen with a small white screen that contains the command prompt. When I hover outside of the command prompt, the cursor changes to a fancy crosshair, which I guess is the default cursor for the desktop environment. But the desktop itself never shows. I've rebooted the Raspberry Pi and the desktop environment a couple of times and I've changed the settings for the output resolution to match the monitor I was using, but it wouldn't change anything. Any idea how I could get the desktop environment to work? Or is there another easy solution to get the IP address? Like I said, I'm a noob in Raspberry Pi stuff so please make suggestions as if you're talking to a child Thanks in advance!
If you can get to the prompt and run commands etc. - don't you already know the IP address then?
The easiest way to get the ip address is by checking on your router on your network or using a tool like:
but if you have a modern os you can also just open octopi.local
Thank you for your suggestion! I will try the Raspberry Pi Finder tomorrow. I can indeed find the IP address by going into the prompt but this would require me to detach the Raspberry Pi from the printer and hook it up to a monitor, keyboard and mouse every day. Normally I could indeed access it by using .local, but that doesn't work in this case. The raspberry pi is hooked up by an ethernet cable and my laptop connects to wifi. Those are actually different networks in my faculty.
But wouldn't it be simpler to hand your faculty's IT department the Pi's MAC address so that the DHCP server always assigns the same IP to your Pi ?
I was looking at plugins that might help, and this is what I've got so far.
If it will always auto connect to the printer, you could use this plugin below. But that needs the printer to always be on to work:
Then I remember seeing that the Telegram or Discord bot plugins can report the IP address to you iirc, so that's an option.
With your script that emails you the IP address, you should be able to use that over the terminal/command line without needing the desktop interface. It would be interesting to know which part of that needs the desktop.
I looked at the OctoText plugin, which can send emails/text messages for OctoPrint status updates, but it doesn't seem to have a 'startup' email that would work for this.
Thanks for your suggestion! I've just e-mailed the IT department to ask this and they say it's possible, but a few things have to be changed so they will get back to me next week. They already had the MAC address to allow the Raspberry Pi to connect to the network. Hopefully it will be fixed somewhere next week.
Thanks! Didn't know about this plugin. I got it to work by also connection my laptop to the network by ethernet, which is not really the solution I was looking for, because I want to have my laptop free from any cables as much as possible. But it's definitely a way easier option to check it like this once in the morning and have it work wirelessly the rest of the day so your suggestion helps a lot. I was already afraid that I had to connect the Raspberry to a monitor and keyboard every morning (which I would have to do in a different room than where the printer is placed). Connecting my laptop to the ethernet once is definitely something I could do. But hopefully the suggestion from @SwHawk will work out too, which would make things even easier.
I have no idea how I would have to install the script using just the terminal. I guess it wouldn't really need the desktop itself, but I don't know how to set up such a script in the terminal. Any suggestions? I would love to learn.
There a multiple ways to do this, but one of the simplest would be to actually type the script on a regular computer, using Notepad++ as an editor, as it won't mess up with line endings. Then you'd have to use WinSCP, which allows you to transfer file from a Windows computer to a Linux machine. The Raspberry Pi is running a Linux distribution, so you'll be able to connect to it, and then transfer the script from the computer you've written it on, to the Pi.
Otherwise, if you need to run commands on the Pi, I'd suggest you use PuTTY which will allow you to connect to the Pi and interact with its command prompt. You'll only have a textual interface, but it is more than enough for the commands you'll have to run.
As a last resort you can always plug in a monitor and a keyboard, but the software above will most certainly cover what you will need to do.
If you need more help, do not hesitate to ping me or ask anyone on the official Discord.
Once you have an SSH connection with PuTTY, the terminal editors vi and nano should be available. You can also install emacs if you prefer that.
I use WinSCP and Notepad++ on my desktop as well.
Thanks guys! Great suggestions! My apologies for the late reply. I've been busy on the project that I'm using the 3D printer and OctoPi for. So in the past few days I've been using the approach that @Charlie_Powell suggested. It takes a few minutes each morning, but it's easy to do. ll look into the approach that @SwHawk and @b-morgan suggested, which would make things a lot easier in daily use, but it will be a challenge for me to figure everything out as I don't have a lot of experience in coding. But perhaps I'll take the Raspberry Pi home on Friday so I have a nice challenge for the weekend. The suggestion to ask the IT department to always assign the same IP address is still a great suggestion, but the IT department did not get back to me yet. I'll send them a reminder for the request.
But I would definitely want to thank you all for your suggestions. You've helped me a lot!
I found this solution on github, https://github.com/jbarguil/raspberrypi-get-ip. You don't need to install the desktop. You might want to create a gmail account specifically for this purpose.