Skip to content

Blog

The Case for a Local Smart Home

Home assistant logo and a selection of local network addresses
Use Home Assistant and keep your smart devices local!

I like to think that I'm quite tech conscious, and that IoT can be a force for good, if installed properly and made easy enough to use. The most important thing, in my opinion, is that the 'smart' devices are just that, and will work reliably not just now, but a few years down the line. They shouldn't be a pain to maintain, or cause problems if the internet dies, or there's a power cut.

Building an Offsite Backup NAS

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalise a purchase. Learn more.

Hard drive on fire spurting images
Making sure that failures like these don't cause total data loss (AI generated image)

You've likely heard of the 3-2-1 rule for backups. If not, it's really simple:

  • You want 3 copies of your data,
  • of these copies, 2 on different mediums (e.g., HDD/tape),
  • and finally there should be 1 offsite copy.

When forming your backup plan, you should consider each of these requirements, and formulate a plan for how you'll fulfill them. You also want to consider the type of data you'll be storing, how frequently it'll be accessed, and whether the data is truly irreplaceable, or something that can be re-downloaded or imported from another medium.

In this article, I'll be explaining my 3-2-1 backup solution, including the architecture, costs, and overall performance.

Raspberry Pi Boot Modes and Security

Set of army boots next to a hard drive and a cloud
Different *boot* modes... (AI generated image)

This is just a quick post to highlight the possible boot modes on the Raspberry Pis, how these can be used in conjunction with network booting, and the key differences between the Pi 3 and 4B. I found this to all be quite confusing when I first looked at it, so hopefully this post will help it make a bit more sense.

Some of these principles can be applied to other computers, especially PXE boot. This post is, however, more geared towards the specifics encountered with the Raspberry Pi family of single-board computers.

Testing SD Card Failure and Storage Reliability

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalise a purchase. Learn more.

AI-generated grim reaper trying to take SD card
How long until your storage dies? (AI generated image)

I've been auditing the SD cards I have in use on various devices, including the data on them, and whether they are still reliable. I've recently freed up some of these SD cards for use in other projects, as I move to network booting my Raspberry Pis. Some of these SD cards are completely dead, I think because they have had lots of small writes, for things such as databases, which cause lots of stress on the underlying flash, and eventually cause it to fail. One example I can think of is a previous Pi running my Home Assistant, which randomly died one day and had lots of database activity.

Wales 2022: Lakes, Climbing Snowdon, and Caving

This is the second and final instalment for the Wales 2022 trip. In this one, we go to Llyn Padarn, one of the largest lakes for swimming in Snowdon, climb Mt. Snowdon (Yr Wyddfa as the Welsh like to call it) on the Ranger Path, then go caving underground at Zip World in LLechwedd, whilst Jack goes off and looks at a castle somewhere.

South West Coast Path: Pentireglaze Mines to Watergate Bay

This video series comes from my January trip with Dad to Cornwall to smash out yet another bit of the coast path. I didn't post the earlier ones here, mainly because I didn't yet have a functional blog, but they are available on the YouTube playlist.

Here's the latest one, where we walk from Watergate Bay to Porthcothan:

Why Here?

We picked this bit of the coast path to do based on Dad's research as to the more flat bits, as at the time, he was having issues with his foot and wanted to take it easy.

In terms of the overall trip, we covered from just East of Newquay at Watergate Bay all the way round to Pentireglaze Mines, which is Northeast of Polzeath. As with most of our trips, we hop around from day to day, covering different sections in different directions. For this stretch, we did the following in chronological order:

  • 29th January: Porthcothan to Harlyn Bay (video)
  • 30th January: Harlyn Bay to Padstow (video)
  • 31st January: Watergate Bay to Porthcothan (video)
  • 1st February: Rock to Pentireglaze Mines (video not yet available)

Instead of parking in Padstow and taking the ferry across to Rock, we started and ended the walk on either side of the ferry crossing. This makes sense, especially with one vehicle, as it saves getting the ferry back across or going the long way round at the end of the day, and is what we try to do whenever possible.

Accomodation and Shops

For the first night, we wild camped on the side of the road, nearish Newquay Airport. We arrived late and left early, and as per usual, left no trace.

On the second and third nights, we stayed at Tregella Place Caravan and Camping, which is one of the sites that has a licence to operate year-round. Whilst the site wasn't 'open' in the true sense of the word, for a tenner a night for a hot shower and actual bathroom on some hard standing, we couldn't really go wrong.

During the first day, there's a couple of Cafés on the way, but no shops and nothing properly built up. At Harlyn Bay, there's a good place to get some chips and either a hot or alcoholic drink. Camping wise, there's not too much closer to Padstow, and we found that Tregella Place was a reasonable distance from all points from Newquay to Padstow.

If doing further than Pentireglaze Mines though, it probably makes sense to camp to the East of the river Camel from that point on. Both Newquay and Padstow have good shops and a variety of places to eat. There's both Rick Stein's Deli and The Seafood Restaurant, which are pricey but very, very good.

There's a wonderful pasty to be had at the Malcom Barnecutt Bakery in Rock, and both The Fish Bar Newquay and the Towan Blystra in Newquay if you're looking for a good fish restaurant or a cheap and cheerful spoons. Finally, there's also The Pig - at Harlyn Bay, which we didn't try as it's very expensive, but have heard very good things about.

Parking and Public Transport

Parking on day one was in the Porthcothan Bay Car Park, which is free in the off-season, and otherwise quite pricey. Day two was at Harlyn Bay Car Park. Day 3 we parked at the Premier Inn in Newquay and took the bus to the start and back from the end. On the last day, we parked on the side of the road in Rock, but I believe this is restricted in peak season. There's a car park at the harbour at the bottom of the road during peak season, but why pay to park in the off-season when we can park for free?

Public transport was abysmal for two of the three days we used it, having to walk back from Harlyn Bay to Porthcothan on day 1, and having to get off the bus at the top of the road on day 2. Besides that it wasn't too bad, and cost £2 for a single each time.

If you have similar bus issues, you can contact the bus company, who will probably tell you what you need to know. Taxis aren't brilliant around this area, so book in advance and make sure a Taxi can get to you if you want to use one.

Other Things to Do

We didn't fancy walking every day of the trip, so we went to St. Ives to the Tate gallery there, and a wonder round. Bear in mind St. Ives is about an hours' drive each way, however.

You're also not too far from the Eden Project, but that can be quite expensive to get into.

Wales 2022 Day 1&2: Travelling up and Climbing Moel Hebog

Almost 2 years after the trip, I've finally finished editing the first episode! In this one, we drive up from Salisbury to Wales, stopping off in the Beacons on the way. On the second day, we climb Moel Hebog, which is the mountain overlooking the campsite.

The Fun of Coding a Discord Bot

Hello, everyone! Today's post is all to do with my Discord Bot and how I made it. If you haven't already joined my Discord Server, a) You Should and b) you won't have seen my Bot.

On the server, I have made a bot which can do a few fun things and fills in for my friend David. For example, typing /xkcd would show you the latest xkcd comic. You can also update Davvo's game and eventually, I will be adding a /weather module for him. Now for a little guide on creating your own bot:

Step 1: Setting Up

First of all, I will assume that you have a basic level of JS knowledge, and that you know how to use Discord.

When creating a bot on Discord, you need to do a few things. First of all you have to create a bot user, which you can do here. You'll want to go ahead and create a new app. You'll want to give it a name like Super Bot and give it an icon, much like a user profile icon. Once you've done that, go ahead and finish creating your bot.

You'll then see a page like this with lots of useful information: Go ahead and click Create a Bot User and then copy the token.

After that, you'll need to invite the bot to your server by hand, using this URL (replacing CLIENT_ID with your ID). https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot&permissions=1341643969. Then add the bot to your server and you're good to go.

Now that you have a Bot setup on the website, you can go ahead and start your text editor and a terminal window.

First, create a folder for your bot where you can store all of your code and then cd into your bot's directory (e.g. cd ~/Coding/Discord Bot). From there, you'll want to type npm init to create your node package. Just hit enter through all prompts.

After that, you'll need to grab the Discord.js module by doing npm install discord.js --save to get the package and save it to package.json. After that, we can create our files.

Create 2 files, 1 called settings.json and one called index.js. We'll be putting all of the tokens etc in the JSON file and all of the functionality in the JS file.

in your settings.json, add the following:

{
  "discord_token":"PUT YOUR TOKEN HERE",
  "status":"Following a Tutorial"
}
After you're done with that, save the file and open up index.js where you can copy and paste this code:
const Discord = require("discord.js");
const client = new Discord.Client();
const settings = require("./settings.json");

client.on("ready", () => {
  console.log("Staring Bot...");
  client.user.setGame(settings.status);
});

client.on("message", message => {
  // We'll put some stuff here later...
  return;
});

client.login(settings.discord_token);
Once that's all done, you'll have a Discord bot that does... well... nothing... (yet).

Step 2: Adding Functionality

So, it's all well and good that you now have a working bot, but it doesn't do anything! In this section we'll cover some basic things you can do with your bot (you might want to open this to help you).

First of all, a ping. Where the code currently returns in the client.on("message"...)

Next, we want to add a response, so, for example, when the message is equal to "ping", we'll want to send "pong".

This can be setup fairly easily with the usage of messsage.content = "ping" in an if statement. We then use the message.reply() method to reply and the result we get will look something like this:-

client.on("message", message => {
  if(message.content === "ping") {
  // Checks to see if the message content is "ping"
    message.reply("pong");
    // Replies to the user with "pong".
  };
});

Step 3: Virtually Infinite

The previous section just covers 1 basic bit of functionality and the possibilities are virtually infinite. For example, you can add a dice roller fairly easily, by using the following code:-

function getRandomInt(min, max) {
// A function to get a random integer...
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

if(message.content === "/roll") {
// Checks for a "roll" command
  message.channel.send(getRandomInt(1, 6));
}

I also coded an xkcd command to get the latest xkcd and display it nicely (you'll need another node module called requestify which you can get by using the command npm install --save requestify):-

const requestify = require('requestify');
// Imports the node module.

if(message.content === "/xkcd") {
  requestify.get('https://xkcd.com/info.0.json').then(function(response) {
  // Gets the latest XKCD in a JSON format.
    var pr = response.getBody();
    // Gets the body of the response and parses it as JSON.
    const embed = new Discord.RichEmbed();
      embed.setTitle(pr.safe_title);
      embed.setDescription(pr.alt);
      embed.setFooter('This XKCD was brought to you by Davvo', 'http://charliebritton.me/IMG_0057.JPG');
      embed.setColor([255, 0, 0]);
      embed.setImage(pr.img);

    message.channel.send({embed});

  });

}

Conclusion

Thanks for reading my blog post on how to create a Discord bot. I hope you found it useful and informative. If you have any questions, Tweet me @charliebrittdev or have a look at the official discord.js site.

Update

I've noticed that I haven't been posting to the site much for a while which disappoints me because the whole idea of this site was to allow people to easily see what I was up to and this hasn't been happening as I have liked. Since my last post about EURO 2 (which is here on YouTube), I have been up to a lot of things which I will briefly outline below.

  • I have made a lot of progress coding wise and I have made a perfectly functional Discord bot which I now use on my discord server and I am working to improve it and get it into full time use.
  • I have also been on a couple of holidays, which again can be found on my YouTube channel including a mini road trip around Somerset and Devon and a week long holiday with my dad's side of the family.
  • As I am writing this post, I am trying to think of things that I can post and do for the blog but I will be adding many more things soon.

EURO 2 - Days 3 & 4

In the morning of the Tuesday, we woke up to a broken hard drive :( which was not good at all. We were very chilly in the morning and so it was a welcome surprise when the sun came out. We spent the morning at the campsite and did some droning before we set off on a short journey to a place which was about an hour south of Cléuger.

We drove around for about an hour rejecting various campsites and aires before we arrived at an almost abandoned campsite (we were literally the only people there)! We then walked down to the beach which was less that 1km from the site and had a swim in the very cold sea.

After we were settled in at the site, we cooked up some 'Lentielles' and 'Coq au Vin' for dinner. We then got into bed for another reasonably cold evening.

On day 4 (a Tuesday), we woke up very cold and prepared for the journey to Jonzac (near where 'Bampi' lives). We stopped at Guérande City where we had galettes and bought some salt before we continued our journey for the long haul.

Finally, we arrived at Bampi's house where we had a very lovely spaghetti bolognese and a nice bed to sleep in for the night. That concludes days 3 and 4 of our #Euro2 road trip and I will be updating you for days 5 and 6 soon.