Project, Python, Research

Automating Making Memes & Instagram Posts 4: Setting Up A Raspberry Pi Home Server & Remotely Controlling via VNC Viewer

So now that I’ve got my neural network, automatic meme generator, and Instagram auto-poster functioning, I’m ready to have them run by themselves at home. Not only do I want to update my AI DavidRoseBot Instagram account, but I also want to use these scripts to post my billions of nice Nikon pictures of Madam Crookshanks onto my TheCatGeek IG a few times a day to share with friends and family!

Yes, that’s me, just doing my part to fill the Internet with cat pictures

To start, I purchased a raspberry pi kit on Amazon and found a very useful article to teach me how to run and schedule python scripts on it. I opted to buy a kit because it comes with a power cord, micro SD card with NOOBS (New Out Of Box Software) installed, HDMI cable (which is not necessary after initial set up, but I am considering having a dedicated screen attached to my server anyway), heat sinks, and a case. If you already have these accessories or don’t care, you can just buy the raspberry pi 3 model b+ for $35 a bunch of places on the Internet.

I use another raspberry pi to act as the “brain” of my 3D Printer

I personally love raspberry pi boards, I currently have one attached to my 3D printer with “OctoPrint” installed. A few years back (prior to this blog) I completed a few different retropie projects and it gave me my first experience with Linux. I actually made a 44 page Word document full of my notes as I set up my retropie game console, but it was hard to keep organized and not very enjoyable to reference.

That’s actually why I decided in September 2018 to start taking notes in blog format. Not only is it easier to organize and keep track of my thoughts, but I can implement memes and gifs, which makes it WAY more fun for future-me when I have to come back and reference posts. (Hi future me! 🙂 )

Oh well HELLO THERE past-me!

After the kit came in, I unpacked it, attached the heat sinks, put it in its case and plugged in my monitor, keyboard, mouse, power, and external harddrive. I chose to install the Raspbian OS that came on the micro SD card and went through the user interface to set up WiFi and install upgrades.

In order to use my harddrive, I needed to install the appropriate driver and mount it. The article Permanently Mounting a USB Hard Drive to your Raspberry Pi walked me through how to do this, and it is literally the best “how to” I have ever seen. Ever. Seriously, that guy is now one of my favorite people in the world.

I truly, truly mean this

My next step is to set up the ability to remotely connect to my Raspberry Pi so I don’t have to keep a monitor, keyboard, or mouse attached to it. Ideally, I want to security remote into my pi from anywhere in the world, so not only could I check up on my scripts but I could also access the pictures that I’ll be storing on the external harddrive.

I decided to use VNC Connect since not only did it meet my needs, but I found a super easy to follow guide that got me up and running in no time. I did run into one problem when trying to install the VNC Connect Viewer application onto my Linux laptop. Below are the commands I had to run to get it successfully installed.

sudo dpkg -i VNC-Viewer-6.19.325-Linux-x86.deb
apt-get update --fix-missing
sudo apt-get install -f
sudo dpkg --configure -a

After I set the remote connection, I moved the raspberry pi and the external Hard Drive into another room to connect directly to my Google WiFi router. Unfortunately, when I went to power up I ran into an error that said my root account was locked so it couldn’t boot.

It was all going WAY too well anyway 🤦🤦🤦

I have run into my system not booting in practically every retropie project I’ve done, so I didn’t panic. Instead I took out the micro SD card from the pi and used a USB adapter to plug it into my laptop to try and salvage. I located the file cmdline.txt and added the following at the end of the line init=/bin/sh. I then put the SD card back into the pi and turned it on.

This is fine…it’s fine. IT’S. FINE.

After the pi booted I tried to remount the drive with the correct permission by typing in mount -o remount,rw /dev/mmcblk0p2 /

During the reboot, I pressed “shift” to enter the system’s recovery options and found out I could edit the cmdline.txt file there. I removed the “init=/bin/sh” from the cmdline.txt file, but unfortunately ended up with the exact same error. By this time it was fairly late at night, so I went to bed with my system not booting because this is what always happens.

Time to get some sleep and make this future-me’s problem

The next day I did a lot more research and found a potential explanation for this problem on a raspberrypi forum. The way I interpret the situation is that something got messed up in my filesystem, so the system wants to run in “emergency mode” for me to fix it. Unfortunately, to run in this mode I need to sign in as the “root user”, but since I didn’t set up a root password it fails and thinks the account is locked.

Once again I edited the “cmdline.txt” file to add “init=/bin/sh” to it and rebooted. When I was back in the shell mode I tried a few different fixes including trying to unlock my root account by running: sudo passwd root, and attempting to edit the /etc/shadow file to set a root password.

Unfortunately, neither of those worked since I was unable to log in as the root user to allow me to save changes. So I took the SD card out of my pi and edited the /etc/shadow file from my PC. In order to set a root password, I copied the password used for the “pi” username and pasted it in place of the “*” for the “root” user. Now I should be able to log in as “root” with the same password as the one I use for my “pi” user.

David, you know I’m doing the best I can here

This time when I booted I was able to sign in as root, and I used the command sudo nano /etc/fstab to remove the mount code I had added in the previous instructions. After I rebooted the system started with no issues!!

OMG Yaaaaaaaassss

Now that I can use VNC Viewer to remotely control my rpi, I just need to transfer my code files and pick up where I left off! I could use VNC to do this, but I don’t like its interface for this activity, so I’m going to set up FileZilla instead. I used the first command below to install the program, and the second command to figure out the ip address of my raspberry pi.

sudo apt install filezilla
ip address
I set up two connections, one for the pi username and one for root

After connecting I can easily transfer files between my desktop computer (left) and the raspberry pi (right).

Even though I got FileZilla functioning, I don’t like how difficult it is to navigate to my pictures. I opened up my “Files” program and clicked on “Other Locations” and typed in the “sftp://” + ip address as the server location to connect directly to it. When prompted I entered my pi username and password and voila I have now connected to my external harddrive without using FileZilla!

I went ahead and added a bookmark to my most used folders while I was at it

I then downloaded GNOME Tweaks from the Ubuntu Software in order to access the Files preferences to enable file previews for all locations. With that setting enabled I can easily preview my Nikon photos from my desktop and laptop at home!

So now it’s FINALLY time for me to get my code moved onto my pi and finish automating Instagram posts! Plus I have my Nikon photos available on my desktop AND laptop, so I can share more cat pictures on this blog which is really what this is all for anyway. ENJOY! 😀

Leave a Reply