Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
This rather long post steps you through the process of setting up a WiFi router on a Raspberry Pi Zero W or Raspberry Pi 3. There are a number of reasons why you might want to do such a thing:
- Setup a demo any where access point for your web apps
- Create deployable devices for use in network testing.
As an added bonus this post also describes how to install NodeJS and the AWS command line tool to created scripted workflows with AWS.
Setting up the Raspberry Pi
Setup the Raspberry Pi Zero W using Raspbian Lite. The version I used was 2018-06-27-raspbian-stretch-lite.img
The following instructions are Mac OSX centric but not too different for how youâd do this using other operating systems.
Locate SDÂ card
On Mac you can do this using diskutil via the command line. Execute the command below and look for a /dev/disk that matches the size of your SD card. For me, thatâs /dev/disk2
$ diskutil list
Unmount the SDÂ card
Next unmount the SD card using the disk number.
$ diskutil unmountDisk /dev/disk2
Flash the OSÂ image
Use the dd command to flash the Raspbian lite image onto your SD card. Be careful when doing this!
This is a good time to mention that the dd command can be very dangerous if you're not careful using it. Always make sure that you're pointing dd to the correct disk drive! You wouldn't want to erase the wrong drive. After all, there's a reason why the command is known as the Disk Destroyer, but that's not what dd stands for. See this bit of dd history if you're interested.
$ sudo dd bs=1m if=./2018-06-27-raspbian-stretch-lite.img of=/dev/disk2 conv=sync
While dd is running you can press ctrl-t on your keyboard to check on the status. The SD disk flash can take a while based on the speed of your SDÂ card.
Itâs recommended that you use a Class 6 or Class 10 microSDHC card for performance reasons.
Once the copy completes you can cd onto the card:
$ cd /Volumes/boot
Create an empty ssh file to tell the OS that you wish to enable SSHÂ access:
$ touch ssh
Next create a wpa_supplicant.conf file with the following, make sure to replace your ssid and psk fields with your router's settings.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1country=USnetwork={ ssid="YOUR-SSID" psk="YOUR-PASSWORD" scan_ssid=1}
Safely unmount the SD after your changes.
$ cd ~$ diskutil unmountDisk /dev/disk2
Connecting to and configuring your Raspberry Pi
Next, insert the SD into your Pi Zero and boot the device.
Give that a minute or so to complete then try pinging the device to locate it.
$ ping raspberrypi.local
Or locate the device using your network router or a Wifi scanner such as Whoâs on My Wifi
You can ssh into the device using:
$ ssh pi@raspberrypi.localor$ ssh pi@10.10.0.107
The default password is raspberry.
If you encounter the following error:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
then simply edit your .ssh/known_hosts file and remove the line that has the raspberrypi entry.
$ vi /Users/${USER}/.ssh/known_hosts
So moving right along, once you sign in, the first order of business is to change the password!
$ passwd
The username will still remain pi but you'll be able to sign in using your new password.
You can optionally proceed to make other tweaks using the raspi-config utility if youâd like.
$ sudo raspi-config
Next make sure the OS is up to date:
$ sudo apt-get update$ sudo apt-get upgrade
- A note regarding the update command above: if while installing packages you get an error such as E: Unable to fetch some archives, maybe run apt-get update or try withâââfix-missing? Then rerun sudo apt-get update and retry the package update that failed. This has proven to be successful.
Lastly, here take a moment to setup your timezone:
$ sudo dpkg-reconfigure tzdata
Adding NodeJS
For the Pi ZeroWÂ use:
$ mkdir nodejs; cd nodejs$ wget https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-armv6l.tar.xz$ tar -xvf node-v8.12.0-linux-armv6l.tar.xz$ cd /usr/local/bin$ sudo cp /home/pi/nodejs/node-v8.12.0-linux-armv6l/bin/node .$ sudo ln -sf /home/pi/nodejs/node-v8.12.0-linux-armv6l/bin/npx npx$ sudo ln -sf /home/pi/nodejs/node-v8.12.0-linux-armv6l/bin/npm npm$ cd ~
If using a Raspberry Pi 3Â use:
$ mkdir nodejs; cd nodejs$ wget https://nodejs.org/dist/v10.14.0/node-v10.14.0-linux-armv7l.tar.xz$ tar -xvf node-v10.14.0-linux-armv7l.tar.xz$ cd /usr/local/bin$ sudo cp /home/pi/nodejs/node-v10.14.0-linux-armv7l/bin/node .$ sudo ln -sf /home/pi/nodejs/node-v10.14.0-linux-armv7l/bin/npx npx$ sudo ln -sf /home/pi/nodejs/node-v10.14.0-linux-armv7l/bin/npm npm$ cd ~
You can test the NodeJS install by:
$ node --version
Installing the AWS command line tool
This is an optional step but is useful if you have files in an S3 bucket that youâd like to copy into the Raspberry Pi.
$ sudo apt-get install awscli
Next configure AWSÂ access:
$ aws configureAWS Access Key ID [None]: ************AWS Secret Access Key [None]: ***************************Default region name [None]: us-west-2Default output format [None]: json
Download assets script
#!/bin/bashmkdir -p $1aws s3 cp s3://bucketname/$1 ./$1 â recursive
Usage:
./download.sh 303A0FA/teb002/3A0FA-2018/10/18/90918447â2fnaodyxhbr
Setup as a Router
- steps provided by https://medium.com/@ivaylov/raspberry-pi-wifi-router-82921ed2ac17 with some changes below:
Remove WPA Supplicant
$ sudo apt-get purge wpasupplicant
Install an DHCP server$ sudo apt-get install isc-dhcp-server
Setup DHCP $ sudo vi /etc/dhcp/dhcpd.conf
Add to end of file:
subnet 172.16.1.0 netmask 255.255.255.0 { range 172.16.1.25 172.16.1.50; option domain-name-servers 8.8.4.4; option routers 172.16.1.1; interface wlan0;}
Install the host access point daemon$ sudo apt-get install hostapd
Configure hostapd
Create a hostapd.conf file$ sudo vi /etc/hostapd/hostapd.conf
add these lines to hostapd.conf file
interface=wlan0#driver=nl80211ssid=YOUR_STATIONhw_mode=gchannel=5wpa=1wpa_passphrase=SECRETPASSWORDwpa_key_mgmt=WPA-PSKwpa_pairwise=TKIP CCMPwpa_ptk_rekey=600macaddr_acl=0
Moving right alongâŠ
$ sudo ifconfig wlan0 172.16.1.1$ sudo /etc/init.d/isc-dhcp-server restart
-d is for debug mode so you can see if any errors appear$ sudo hostapd -d /etc/hostapd/hostapd.conf
Might need to ctrl-c after ^^^
Now lets make these changes persistent$ sudo vi /etc/network/interfaces
Next, add or edit these following line
auto wlan0iface wlan0 inet staticaddress 172.16.1.1netmask 255.255.255.0
Edit rc.local âŠ
$ sudo vi /etc/rc.local
and add two lines before the last line exit 0
hostapd -B /etc/hostapd/hostapd.confiptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Then uncomment the following line in /etc/sysctrl.conf
$ sudo vi /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4#net.ipv4.ip_forward=1
So above should read:
net.ipv4.ip_forward=1
Thatâs it. We can now reboot the box.
$ sudo reboot
Testing
At this stage you should be able to access the WiFi network.
â
Thanks for reading! If you like what you read, hold the clap button below so that others may find this. You can also follow me on Twitter.
Raspberry Pi based Wifi Routers was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.