Learning Linux and playing with Raspberry Pi

Learning Linux and playing with Raspberry Pi

Obviously not content with the (not insignificant) workload from my bootcamp, I turned this weekend to something new - learning Linux and playing around with my Raspberry Pi. We've just come to the end of the backend module of the course and have a study break before diving back into frontend and React, giving me some time for a little foray into something else before lectures start again...

Raspberry Pi 4

For Christmas, I asked Father Christmas for a Raspberry Pi. Father Christmas didn't get the memo, but luckily my brother did...a Raspberry Pi 4 to be precise...it came with the message "never in a million years did I think I would be buying you a Raspberry Pi". Opening it, I felt like, well, a kid at Christmas.

I immediately got stuck into the 'getting started' guide from the Raspberry Pi website and got everything up and running. By far the coolest bit for me though, was inspecting the actual board itself and working out what all the different components were and what they do. I guess I am an engineer's daughter at heart and have a need to ask 'yes, but how exactly does it work' when learning anything new. Having never seen inside a computer before, this was completely fascinating. The official Raspberry Pi beginner's guide has a really useful breakdown and explanation of all the components; the system-on-chip (SoC), including the CPU and the GPU, the RAM chip, the radio component for bluetooth and wifi, the USB ports and controller and the network controller. Since I don't have a Computer Science or engineering degree, to gain a better understanding of what all these parts actually do, I turned to the next best resource...my childrens' lift-the-flap computer books. (I'm not kidding, seriously, they are an excellent way of learning basic computing and programming concepts). See below...

lift-the-flap-screenshot.jpg

The 'What's inside?' page from my sons' 'Usborne Lift-the-flap Computers and Coding' book. Fascinating stuff.

Now what to do with it?

If you have a Raspberry Pi too, or you've looked into getting one, you'll know that the list of projects and things you can do with a Pi is vast. Build a robot? No problem. An automatic waterer for your herb garden? No problem. A surveillance camera for your front door? No problem. The possibilities are seemingly endless. However, I'm not really in the market for that sort of project at the moment, so what else could I do with my new toy? Well one of the key selling points of the Raspberry Pi is that it's great for people (especially kids) to learn to code. However, I'm already doing that (I'm three-quarters of the way through a bootcamp course on which I'm learning, amongst other things, JavaScript). So, after a bit more clicking around the Raspberry Pi operating system (formerly called 'Raspbian', based on the Debian linux distribution), I reluctantly put the little Pi into a drawer and promised to come back to it once the demands of my course were out of the way.

Learning Linux

Fast forward a few weeks and I've been reading a book that piqued my interest after seeing it mentioned on Twitter - Confident Cyber Security by Jessica Barker. First of all, the book is excellent and fascinating, go read it. Second of all, it seems Linux is pretty fundamental for Cyber Security professionals. As a long-standing Windows user and new Mac convert, Linux has always loomed as a slightly intimidating, incredibly 'techie' mystery that real programmers use. In other words, a Challenge (yes, with a capital 'C'). I can't resist. What's more, I've got a tiny Linux machine sitting in my desk waiting to be used. So I dusted off the Pi, connected it up to a monitor and started googling 'how to learn Linux'. I should say at this point that I wasn't entirely sure what I meant by 'learn Linux' - this post sums it up pretty well and was a helpful starting point. So now I've got a couple of goals: become familiar with a Linux OS and desktop, starting with the one already installed on my Raspberry Pi, learn bash and more generally learn how a Linux system fits together and works. Thanks to my bootcamp course, I'm already well-versed in the command line and I already use it every day. I even wrote a post about it a few months ago. I don't often use some of the more advanced commands though, so that might be a good place to start. And like so many other things, I guess the best way to learn something is by doing.

An Express API and MySQL database on a Raspberry Pi?

I also had a chat with Ian, one of the instructors on my bootcamp course, who I know is a Pi enthusiast too, and he suggested a great first project - getting an API I had just finished building for our course up and running on the Raspberry Pi and access it over my home network to send HTTP requests. So I did!

It took all weekend (thank you to my hero of a husband who looked after our boys while I coded away). The API in question is a RESTful API that I built as a bootcamp project, using Express and Node.js to perform CRUD operations on a database. I also built a relational database, which I created inside a Docker container for the original project, to hold the data and used the Sequelize ORM to interact between the Express app and the database. Following some online tutorials, it was fairly straightforward to install Node.js and Express and all the other dependencies I would need for the project on the Pi. In the original project, I used MySQL, however, it turns out MySQL does not work well (not easily at least) with Raspberry Pi. Whilst trying to make it work on the Pi I did manage to get Docker up and running successfully, so that was a win and something to play around with more in future. After some digging around online, I worked out that MariaDB would be a good alternative database system so I used that to get a new database up and running on the Pi. That was the (relatively) easy bit. What was less easy was modifying my code to allow Sequelize to connect to the MariaDB database. It seems that MariaDB is very similar to MySQL (and was even created from MySQL in the first place, I believe) so there were a lot of fundamental similarities. The bit that caught me out in the end was grabbing the connection information from process.env, which is what the original API was set up to do when I built it on my Mac. That didn't work on the Pi but with some hard-coding of passwords (don't tell anyone, and it's not on GitHub!) I finally managed to connect to the new database, access the API over my home network and fire across some HTTP requests using Postman. I felt like I could conquer the world!

So anyway, this a brief interlude for bootcamp and my first steps in learning Linux by playing around with my Raspberry Pi over the weekend. On to the next project!

You can follow me on Twitter and LinkedIn.

Cover photo by Louis Reed on Unsplash.