Return of the Mac

At work, since I work in .Net-land, I do most if not all of my dev work on a Windows box. Consequently, I would do a lot of my for-fun stuff also on a Windows box. A few years ago I got a MacBook Pro because every Windows laptop I got was built like crap and would get destroyed very quickly when I traveled – I went through like 4 laptops in a 2 year period. The only laptop I’d ever used that was physically durable enough while also not weighing a ton was an aluminum MacBook, so I got one of those.

I never really did much dev work on it, though – it was a solid machine for travel, some games (yay Steam). I maybe noodled around a little doing some front-end experimentation and a little bit of Python, but nothing more than toy projects.

With Hoshi, I’ve decided to start using my Mac for the development, since it’ll all be in Angular and Python + Flask. I’m using VS Code for my editor, since it’s a really nice editor.  Some of the *nix stuff I’ve been learning while setting up my Pis has been helpful, though things like Brew vs. apt-get and some of the other OS X related stuff is a bit annoying.

So far it’s been very nice – even though I’m still figuring out the workflow and fumbling around looking for commands, I’m finding it a pretty decent tool. I have Parallels with a copy of Windows 10 on it, so that’s also been good – I can mix and match bits and pieces in the pipeline.

How to bake a Raspberry Pi

When they first came out, I picked up a couple of Raspberry Pi 3 model B kits out of curiosity. I set up one of them and tooled around for a few minutes. It was pretty decent – I was able to play videos and stuff on it, and do a little surfing, but I didn’t really have a project in mind, or more than the most basic *nix knowledge to do anything useful with it, so I stopped tinkering with it and haven’t used it since.

Recently, however, I had the inkling of an idea for a project that would require a reasonably capable computer at the heart of it, and the Pi seemed like a perfect fit. This morning I dusted off my Pis and got them up and running again, using the following steps:

0. Smoke tests: I used a micro USB cable connected to a charger I have laying around, and that worked fine for powering the Pis. After plugging in a mouse and keyboard, I hooked the Pi to my tv and voila, it was up and at the desktop pretty quickly. I connected to my wifi and made sure I could hit the web and stuff like that. Everything was working as expected.

1. Host Name and Password: Since IP addresses can change, I want to be able to remote into my Pis by name, which won’t change. I also wanted to change the Pi user password from the default to something more secure.

First, I changed the name of my Pis by following howtogeek’s guide, and picked something memorable.  After rebooting, I went to a terminal and changed my password using the passwd command, followed by a reboot.

2. Wifi: Once I rebooted, my Pi didn’t automatically reconnect to my wifi. I want my Pis to always connect to wifi so that I’m able to remote into them without having to manually reconnect to wifi – who wants to break out the keyboard and mouse and all that noise?

Using the fine tutorial by adafruit, I set my Pis to automatically connect to my wifi. Now when my power goes out or I reboot or whatever, they will automatically reconnect. Partial yay!

Partial because automatically connecting is just part of the problem – some versions of the Pi are known to go into a sleep mode/power save mode wherein they will shut down their wifi if the network has been inactive for too long, so I needed to fix this as well. For that, I decided to make a cron job to have it ping something every minute or so, which should keep it alive. A bit of googling and some judicious use of man pages lead to the following solution. In a terminal window, I typed:

sudo crontab -e

which opened an editor that allowed me to create a cron job. In the editor, I added in the following line at the bottom:

* * * * * ping -c1 8.8.8.8 > /dev/null 2>&1 &

This says, basically  “every minute send one ping and one ping only to 8.8.8.8 and don’t bother worry about the response, and do all this in the background.” 8.8.8.8 is, I believe, one of Google’s name servers, just FYI. I saved and exited the editor, and then entered:

sudo crontab -l

This gave me a list of the cron jobs on my Pi, and I was able to confirm that the one I had added was indeed there. Then I rebooted, not because I needed to for the cron job to run, but because I wanted to make sure that my wifi would auto connect and that my ping would run even after a reboot:

reboot

When the system came back online, I went into a terminal and typed:

grep "ping" /var/log/*

which yielded a list of all the times “ping” showed up in any log file – I was looking for the ping I’d entered as a cron job and it did in fact show up. Success! Now I should be able to always remote into my Pis.

Because my Pis are now accessible through wifi, I was able to do the remaining steps by remoting in to the Pi from my laptop, which was much more convenient.

3. Updates: There were probably some updates in the 2ish years since these Pis were bought, and I figured I should update my OS to be as current as possible. At a terminal I entered the following:

sudo apt-get update
sudo apt-get dist-upgrade

Running the first command took about a minute, and the second took a longish time (30 minutes or so?) because I have crappy internet (I’m out in the boonies) and it needed to pull down a number of files. Once this finished and I rebooted, my Pis were now up to date.

4. Boot to Command Line: Since I will be remoting in all the time, I don’t need a graphical desktop on my Pis, and I definitely don’t need the overhead of having the desktop. Finally, I wanted to make sure that nobody who happened to take my Pi would be able to use it without knowing the password – by default the Pi boots to the desktop already logged in. That’s bad.

At a terminal window I entered:

sudo raspi-config

and followed the handy menu that came up to set it so that my pi will boot to the command line only and not log me in automatically, and I can still remote in as per usual.

NOW I’m finally ready to get to work on my project!