PC Pro

“The addition of wireless suddenly makes this a far more useful little board for IoT projects”

Paul finds the new Raspberry Pi Zero W is an excellent platform for creating a “thing”, and provides a tip for Netgear Orbi owners

- @PaulOckend­en

Ithought I’d follow on from last month’s column by starting to show you how to build a genuinely useful Internet of Things (IoT) “thing”. And to prove there’s plenty of choice in the marketplac­e when it comes to ultra-cheap wireless platforms, I’m going to change boards. Last month was mostly about the ESP8266-based NodeMCU developmen­t kit; this month I’ll focus on the Raspberry Pi Zero W. Why? Well, because it’s fairly new (the “W” wireless variant first went on sale at the end of February), and because it’s British, and PC Pro loves to promote home-grown talent!

I’m sure many of you already know this, but the Raspberry Pi Foundation is a charity, founded in Cambridge, and its stated aim is to “promote the study of computer science and related topics, especially at school level, and to put the fun back into learning computing”. The foundation is primarily supported by Cambridge University’s Computer Laboratory and hardware manufactur­er Broadcom – whose chips you’ll find at the heart of the device.

There have been several Raspberry Pi models over the past four years, but there was a real buzz in late 2015 when the Pi Zero hit the streets. It was small, and low cost – about £5. It wasn’t as powerful as the Raspberry Pi 3, but with a single-core 1GHz processor it was no slouch, either.

It was missing wireless, however. The board had only a single USB port, so if you added a USB wireless dongle it meant you’d effectivel­y cut the Pi off from any other communicat­ion. You could add a USB hub, of course, but then the whole “small and cheap” ethos was out of the window.

Which all goes to explain my excitement over the launch of the Pi Zero W. It’s essentiall­y the Pi Zero with added Wi-Fi and Bluetooth. The Wi-Fi is 802.11bgn; no 802.11ac and no 5GHz, but given its price is less than a tenner, I don’t think anyone will be surprised. The on-board Bluetooth is 4.1 with low energy (BLE) support. The addition of wireless functional­ity suddenly makes this a far more useful little board for IoT projects, and puts it on a par with the NodeMCU developmen­t board, for example.

I want to get a little nerdy for a moment about the Pi Zero W’s onboard 2.4GHz antenna. Normally you’d expect this to be a track on the PBC with a length that’s an exact fraction of the 12.5cm wavelength found with 2.4GHz radio signals. This makes use of the fact that since resonance occurs at whole number fractions of the wavelength (1/2, 1/3, 1/4 and so on), shorter antennas can be used. They aren’t as efficient as full-wave antennas, but without such fractional antennas many electronic gadgets would have to be bigger. For example, an 800MHz mobile phone signal would need an antenna that’s 37.5cm long!

Fractional wavelength PCB tracks aren’t the only option, however – the other major player is the ceramic chip antenna. There are several types, but the common factor is that they use a material with a high permittivi­ty (which my dictionary defines as

“the ability of a substance to store electrical energy in an electric field”.) The key is that in high-permittivi­ty materials the wavelength of a radio signal is reduced, so the antenna can be made smaller as a result.

Until now, those have been the only two choices, but the Pi Zero W introduces a third type of antenna. If you look carefully at a photo of the board, you may notice a tiny triangular shape etched into the copper of the PCB. This is an amazing new type of 2.4GHz antenna. It acts as a tuned resonant cavity, and the geometric shape, together with a couple of associated capacitors, allow the structure to capture Wi-Fi and Bluetooth radio traffic. The technology is licenced from Swedish company Proant, and is similar in concept to the traditiona­l “slot” or “notch” antenna – but in this case it’s so small that Proant has called the product design “niche” rather than notch. I suspect that probably passes for a joke in Sweden!

I was sceptical at first, but it works well. And, more importantl­y, it keeps the board small and cheap. Signal strength is decent, but if you need more you’ll find there are pads on the board onto which you can solder a standard U.FL RF connector, for use of an external antenna. For most folk, the little triangle will be adequate.

It’s a setup

The kit I looked at last month was configured by loading firmware and/ or code via the USB connection. The normal Raspberry Pi setup is different to this. Since the device is actually a computer running an OS, the usual way to get things running is to connect a USB mouse and keyboard (because there’s only one socket on the Pi Zero boards, a wireless “desktop” combo is the easiest option), with a monitor connected to the HDMI port. It isn’t dissimilar to setting up a new desktop computer.

The thing is, unless you have a suitable mouse, keyboard and screen lying around, plus the various connectors/converters to plug into the micro-USB and mini-HDMI, you could easily find yourself spending far more on peripheral­s and leads than you did on the Pi itself. Also, because we’re going to set it up as an IoT “thing”, the keyboard, mouse and monitor won’t be needed beyond the initial setup.

Luckily, with some fiddling it’s possible to configure the board without using a keyboard and screen. There are just two things we need to do: the first is to get the onboard Wi-Fi connected to your network; the second is to enable SSH, so we can open a remote command prompt.

But I’m jumping ahead of myself here. The very first thing you’ll need to do is to create a microSD card containing the OS for the Pi. There are several options available (see raspberryp­i.org/downloads), including a version of Windows 10. However, for most people, the most sensible option will be Raspbian – a flavour of Debian Linux.

If you look at the download page ( raspberryp­i.org/downloads/ raspbian), you’ll see two versions listed – one with PIXEL, and a “Lite” version. PIXEL is the Raspberry Pi desktop environmen­t, and since we’ll be operating without a monitor, there simply isn’t a need for that. Download the Lite version.

It will be easiest to download the ZIP version. Once unzipped, you’ll see an IMG file, just under 1.5GB in size. Flash that onto a microSD card. Even if you don’t have one kicking around, they’re incredibly cheap. If your card reader only has a full-sized SD card slot, you’ll also need an adapter.

If you’re using Windows then the recommende­d flashing tool is Win32 Disk Imager ( pcpro.link/273disk), whereas Mac users can either use dd from the command line, or use Etcher ( etcher.io), which will be easier for novices. However you do it, you’ll end up with a microSD that can be used to boot the Pi Zero W.

But we’re not done yet. First we need the board to hop onto your Wi-Fi network, and to do that it will need to know your network name and password. Now if you were using a keyboard, mouse and screen, this would be easy: you could simply select the network using the Pi’s GUI. But since we’re doing this using a headless setup, you’ll need to add the details manually. Eject the card from your card reader (using the OS tools, rather than just pulling out the card) then re-insert it. It should mount like a normal disk, and you’ll see a file system in place.

The card has two partitions: one called boot, the other root. The root partition uses an ext4 file system and contains the normal Linux file structure, which is mounted as “/” once the Pi boots – it’s where pretty much everything to do with the Pi lives. The boot partition is a FAT file system and is used only during booting. You’ll see it mounted as /boot once you have the Pi up and running.

When you insert a Pi microSD card into the card reader on a PC or a Mac, you’ll see this boot partition is visible with full read/write access. But the main root partition normally isn’t accessible – you’ll need to install additional software to view it. Luckily, we don’t have to do that. The designers of Raspbian have created a facility where if you put certain files in the boot partition, they’re copied over to root when the Pi starts up (and then deleted from boot).

To get your Pi Zero W connected to your wireless network, you’ll need to place a file called wpa_supplicant.conf in the root folder of the boot partition, and in that text file include the following text:

“With some fiddling, it’s possible to configure the Pi Zero W without using a keyboard and screen”

network={

ssid=“Your_wifi_network_name”

psk=“Your_wifi_password”

key_mgmt=WPA-PSK

Then plug the Pi Zero W into a USB power supply (or a USB port on your computer, which should have enough power to drive it) and you should see the green LED flash for a while, and then stay lit green.

Next go to your wireless router and view the list of connected devices. If everything has gone to plan, you’ll see your Raspberry Pi listed, along with its IP address (it will have a MAC address starting with B8:27:EB). If you don’t have admin access to your wireless router, just run a network scan – it’s easiest to do this from an app on your phone – and you’ll see the Pi listed as “raspberryp­i”.

Once you know the IP address you’ll find you can ping it, but you won’t be able to open an SSH connection – that’s because SSH is disabled by default in the latest versions of Raspbian. This change was made shortly after the tech world became paranoid about IoT devices being taken over and used as part of a botnet.

To enable SSH, at least initially, simply power down the Pi, plug the SD card back into your PC, and create a blank file called ssh (with no extension) in the root of the /boot partition. Then pop the card back into the Pi and reboot it.

Incidental­ly, you’ll probably see that the green LED continues to flash, rather than appearing solid after a minute or so. It’s because you pulled the power, rather than performing a clean shutdown. Don’t worry, though – everything is fine. Just give it a few more minutes and the flashing will stop once the system has checked that the file system is clean.

You should see a solid green LED once it has booted, and not only be able to ping the device (its IP address may have changed) but also connect to it via SSH. The username is “pi” and the password “raspberry”. It’s important to remember that the ssh file gets deleted, so you get only one shot. If you reboot the Pi, you’ll need to add the ssh file again.

Incidental­ly, if you don’t have an SSH client then I recommend PuTTY for Windows users ( pcpro.

link/273putty) and vSSH for those of you on a Mac ( pcpro.link/273vssh). Both are excellent.

Once you can access the Pi’s command line you’ll be able to do things like “ping www.google.co.uk” to test connectivi­ty. Unlike ping on a Windows PC, it just keeps going, so you’ll need to use Control+C to stop it.

Rather than messing around with SSH files, we can configure the Pi to have SSH permanentl­y enabled. Type sudo raspi-config, go into Interfacin­g Options, select SSH and then the option to enable it. While you’re there make sure IC2 is enabled, too, as we’ll need that in a moment. You can also change the password for the pi account from “raspi-config” – and that’s probably a good idea. Then select Finish to exit raspi-config. Incidental­ly, “sudo” is a little like running something as administra­tor on a PC. The Pi login doesn’t have access to write these configurat­ion changes, but preceding the command with sudo means to run it as a “super-user”.

Now you can reboot the Pi as often as you like, and it will hop onto your wireless network and enable SSH access. No more messing around with files in the boot partition. Incidental­ly, rather than just pulling the plug, the correct way to shut down the Pi is by using sudo shutdown – by default, it will take a minute. Or you can reboot by using sudo reboot. This way, you won’t get the flashing green LED mentioned earlier, while the device scans the file system for errors.

Next month, I’ll show you how to turn your newly configured Raspberry Pi Zero W into a useful IoT thing.

Into Orbi

I continue to be impressed by Netgear’s Orbi “whole house” Wi-Fi system. It’s incredibly fast and bathes the whole area in a really strong Wi-Fi signal. As I move around the house, I find my gadgets hop instantly and seamlessly between the main router and the satellite. It’s so much better than using convention­al Wi-Fi extenders and boosters. And the latest firmware update offers a guest access facility (addressing one of my complaints the last time I wrote about Orbi). It’s fantastic kit, but a real shame that there isn’t a xDSL version, so you still need a separate modem if you have a telephone line-based internet connection.

One little tip. If you have an Orbi, go to orbilogin.com/debug.htm and enable telnet (note that this link only works if you have an Orbi setup). Then telnet into the router and execute the following commands:

nvram set enable_adv_attached=1 nvram commit

Don’t forget to go back to the debug page and switch telnet back off afterwards! Now when you view the attached devices in the Orbi user interface, you’ll be able to see whether they’re connected to the main router or the satellite. This is incredibly useful when it comes to finding the best position for each unit, and I’m surprised that it isn’t enabled by default.

“Netgear’s Orbi is incredibly fast, and bathes the whole area in a strong Wi-Fi signal”

 ??  ?? BELOW There are a few OSes available for the Raspberry Pi, but Raspbian is the best place to start
BELOW There are a few OSes available for the Raspberry Pi, but Raspbian is the best place to start
 ??  ?? ABOVE The antenna is that little triangle between the HDMI and USB sockets
ABOVE The antenna is that little triangle between the HDMI and USB sockets
 ??  ?? RIGHT The Raspberry Pi Zero, now with Wi-Fi and Bluetooth 113
RIGHT The Raspberry Pi Zero, now with Wi-Fi and Bluetooth 113
 ?? @PaulOckend­en ?? Paul owns an agency that helps businesses exploit the web, from sales to marketing and everything in between
@PaulOckend­en Paul owns an agency that helps businesses exploit the web, from sales to marketing and everything in between
 ??  ?? BELOW A quick hack allows you to see which Orbi unit your devices are connected to
BELOW A quick hack allows you to see which Orbi unit your devices are connected to
 ??  ?? ABOVE When I’m using my Mac, vSSH is my tool of choice
ABOVE When I’m using my Mac, vSSH is my tool of choice

Newspapers in English

Newspapers from United Kingdom