Set up a Raspberry Pi Zero headless

If you are using the GUI (Raspian full download) and want to connect your RPi Zero to a keyboard and monitor there are probably easier ways to do this. These notes are for people that want to use a headless (no monitor and GUI) setup ready to connect to your RPi after first boot via SSH from another terminal. "Raspberry Pi Zero W" (CC BY-SA 2.0) by lespounder Download Raspbian Lite wget -O Download link: Write Image to SD Card dd bs=4M if=2017-08-16-raspbian-stretch-lite.img of=/dev/sdb After this step there should be 2 additional mounts (if not mount the 2 SD card partitions manually). Set up network interfaces Create a new config file for the wireless interface. cd etc/network/interfaces.d/ vim wlan0.conf Add the following to the new file (if you want to use DHCP - change to static if you want to fix the IP): auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf Set up connection details for local wireless network vim etc/wpa_supplicant/wpa_supplicant.conf Check the file and ensure the network settings are as per the Wireless Network you are connecting to. country=AU ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="SSID" psk=HASHED_PSK_VALUE } You could use the clear-text PSK passphrase but I prefer not to do that in configuration files. Create a PSK hash using 'wpa_passphrase' this older article There could be other config values you might need depending on the network you are connecting to. More info: Ensure there are DNS Servers configured sudo vim etc/resolv.conf Add the following to the new…

Continue ReadingSet up a Raspberry Pi Zero headless

RaspberryPi Version 3 SOE

Since there is now a supported Raspbian version without GUI and other unneeded add-ons available as Raspbian Lite the need to use other installers (with sometimes some downsides) is now not a necessity anymore. Below is a list of steps I like to perform before using them for any purpose as my Standard Operating Environment. Download Raspbian Lite Download link: Write to SD Card dd bs=4M if=2016-05-27-raspbian-jessie-lite.img of=/dev/sdb Boot RPi Default login details are UID: pi PWD: rasbperry Regional settings locale-gen en_AU.UTF-8 dpkg-reconfigure locales ln -sf /usr/share/zoneinfo/Australia/Adelaide /etc/localtime System update sudo apt update && sudo apt -y upgrade apt install vim Setup SSH keys As a security precausion it's a good idea to disable password authentications ssh-keygen -t rsa vim /root/.ssh/authorized_keys # --> add RSA public key Setup Wireless LAN iwlist wlan0 scan wpa_passphrase SSID WPA_KEY vim /etc/wpa_supplicant/wpa_supplicant.conf Copy the resulting hash from the previous command Example config country=AU ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YOURSSID" psk=123456789012345678901234567890 } Rename default user account The default Raspbian images use the default user 'pi' - I prefer to change this user to another account for security purposes and to be in line with other Linux system I use. Reboot and log in to the RPi as root - you need to run the following commands as root. usermod -l NEW_USER_ID pi usermod -m -d /home/NEW_USER_ID NEW_USER_ID groupmod --new-name NEW_USER_ID pi mkdir /home/NEW_USER_ID/.ssh/ vim /home/NEW_USER_ID/.ssh/authorized_keys # --> add RSA public key # change owner and permissions on key files chown -R NEW_USER_ID:NEW_USER_ID /home/NEW_USER_ID/.ssh/ chmod 700…

Continue ReadingRaspberryPi Version 3 SOE

FreedomBox + RaspberryPi = FreedomPi

I have been watching progress on FreedomBox ever since watching a video of Eben Moglen a few years ago. Turns out that that they recently announced the availability of their 0.1 preview release. As part of this there is one component that is extremely useful for RaspberryPi users (funnily the co-founder of RasperryPi is also called Eblen by first name - go figure) out there concerned about increasing snooping of private information by governments and corporations for a variety of reasons. Meet 'freedombox-privoxy' This software combines the functionality of the Adblock Plus ad blocker, the Easy Privacy filtering list, and the (HTTPS Everywhere]( website redirection plugin into a single piece of software to run on your FreedomBox. Combining these different plugins into software for your FreedomBox means that you can use them with almost any browser or mobile device using a standard web proxy connection. Best of all this has already been made available via the Raspbian repositories ( so the install is extremely simple. sudo apt-get install freedombox-privoxy Note: make sure that you have the 'contrib' branch in the Raspbian repositories enabled in /etc/apt/sources.list deb wheezy main contrib non-free deb-src wheezy main contrib non-free Kudos to James Vasile for the technical work ! To get some more idea on the usage of privoxy you can check this article.

Continue ReadingFreedomBox + RaspberryPi = FreedomPi

Enabling the watchdog timer on the Raspberry Pi

Turns out that the Broadcom BCM2708 chip on the RPi has a hardware watchdog. This can be very useful if your RPi is located remotely and locks up. However, this would not the preferred method of restarting the unit and in extreme cases this can result in file-system damage that could prevent the RPi from booting. If this occurs regularly you better find the root cause of the problem rather than fight the symptoms. Enable Watchdog Kernel Module echo 'bcm2708_wdog' >> /etc/modules sudo modprobe bcm2708_wdog Install Watchdog Daemon sudo apt-get install watchdog chkconfig chkconfig watchdog on sudo /etc/init.d/watchdog start sudo vim /etc/watchdog.conf # Uncomment the line watchdog-device = /dev/watchdog # You might also want to uncomment max-load-1, or add something like "max-load-1 = 24" to reset your Pi if the load average exceeds 24 in any 1-minute span. sudo /etc/init.d/watchdog restart The watchdog daemon will send /dev/watchdog a heartbeat every 10 seconds. If /dev/watchdog does not receive this signal it will brute-force restart your Raspberry Pi. If you are feeling adventurous you can test the setup by launching one of the fork-bombs you can find out there. Just make sure you don't have anything of importance running. : (){ :|:& };: Thanks to gadgetoid for the original tip !

Continue ReadingEnabling the watchdog timer on the Raspberry Pi

Dropping the wires on the Raspberry PI

Testing the RPi for some remote sensing application I needed to use a wireless connection as it would have been a pain to reach with an Ethernet cable. Parts Raspberry Pi Series B 512MB Raspbian 3.6.11+ Kernel Comfast 802.11n - Realtek RTL8188CUS WLAN Adapter Install WPA Supplicant sudo apt-get install wpasupplicant See Check for the USB adapter sudo lsusb This should show output similar to this (depending on your USB adapter) Bus 001 Device 004: ID 0bda:8176 Realtek SemicondRTL8188CUSuctor Corp. 802.11n WL:AN Adapter Generate PSK Key If you want to use the cleartext PSK you could probably skip this step. wpa_passphrase YOUR_SSID YOURCLEARTEXTWPAKEY This should show output similar to this: network={ ssid="YOUR_SSID" #psk="YOURCLEARTEXTWPAKEY" psk=c885c4288a0c68b989289586cb075c0ccd1729d2c035820d02ed813fc729f317 } Edit network configuration sudo vim /etc/network/interfaces auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "YOUR_SSID" wpa-psk c885c4288a0c68b989289586cb075c0ccd1729d2c035820d02ed813fc729f317 Finish off sudo shutdown -h now Unplug ethernet cable Power up the RPi and you should see another wireless DHCP assignment on the router

Continue ReadingDropping the wires on the Raspberry PI

Webserver and database combination on Raspberry Pi

My normal combination on the big-server side would be Apache + MySQL (or PostgreSQL), but on the RPi this seems to be absolute overkill. For data-logging operations I would not use the local system anyway (looking at MQTT as well as Remote MongoDB datastore via REST Webservices). After some poking around and reading up on the options I decided to go for the following combo: LightHTTPD + SQLite. Both are lightweight replacement of their fully-featured big-server counterparts (Apache HTTP & MySQL) and have very familiar configurations. There would be other options that have even less resource usage, but I really don't have the time to start from scratch somewhere. Another reason to go for this combination is that these are very well supported systems with regular security audits. Even though I am not planning to use my RPi's for anything mission-critical this is always worth a consideration as you don't need to unnecessarily introduce vulnerabilities to your network. Install & configure LightHTTPD sudo apt-get install lighttpd php5 php5-cgi php5-sqlite sudo lighty-enable-mod fastcgi sudo lighty-enable-mod fastcgi-php Further config changes can be also made via the config file. sudo vim /etc/lighttpd/lighttpd.conf sudo service lighttpd force-reload Install & configure SQLite sudo apt-get install sqlite3 sqlite3 /home/username/database_name.db All other commands are standard SQL from the 'sqlite>' command prompt or via SQL scripts like sqlite3 /home/username/database_name.db < sql_script.sql Access Databases from the webserver (using PHP) < ?php $db = new SQLite3('mysqlitedb.db'); $results = $db->query('SELECT bar FROM foo'); while ($row = $results->fetchArray()) { var_dump($row); } ?>…

Continue ReadingWebserver and database combination on Raspberry Pi

Raspberry Pi – Raspbian post install tasks

The Raspbian Install process is fairly well documented using the Raspbian Installer. This is just to document common tasks after the stock install. Install base utils apt-get install sudo vim ntpdate git-core binutils make gcc ca-certificates rpi-update Allow non-root user account access to 'sudo' adduser USERNAME sudo For those Ubuntu users there is no 'admin' group in Raspbian (Debian Wheezy). NTP time update sudo rm /etc/localtime sudo ln -s /usr/share/zoneinfo/Australia/Adelaide /etc/localtime sudo ntpdate -u Probably best to choose an NTP Server closest to your location or provided by your ISP Firmware upgrade EDIT (2014-03-31): rpi-update is now part of the Raspbian repositories and can be installed via apt-get install rpi-update (I have added this to the above line). Note: unless you want the latest firmware this is not a necessary step as apt-get will update the firmware to the latest stable release. Using Hexxeh updater. Install dependencies wget -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update sudo rpi-update Install WiringPi Thanks to the excellent work of Gordon Henderson ( this is a C-based program to read/write to the Raspberry Pi GPIO pins. cd /usr/share git clone git:// cd wiringPi git pull origin ./build Output: wiringPi Build script ===================== The wiringPi I2C helper libraries will not be built. WiringPi library [UnInstall] [Compile] wiringPi.c [Compile] wiringPiFace.c [Compile] wiringSerial.c [Compile] wiringShift.c [Compile] gertboard.c [Compile] piNes.c [Compile] lcd.c [Compile] piHiPri.c [Compile] piThread.c [Compile] wiringPiSPI.c [Compile] softPwm.c [Compile] softServo.c [Compile] softTone.c [Link (Dynamic)] [Install] GPIO Utility [Compile] gpio.c [Link] [Install] All Done. Testing the…

Continue ReadingRaspberry Pi – Raspbian post install tasks

Accessing 1-wire devices on Raspberry Pi using OWFS

To connect 1-wire serial devices to the RPi I am using a DS9490R USB 1-wire adapter (rather than wiring I2C 1-Wire master components to GPIO I2C - which I might look at sometime down the track) Install packages sudo apt-get install owfs ow-shell Edit config file vim /etc/owfs.conf ! server: server = localhost:4304 # USB device: DS9490 server: usb = all ######################### OWFS ########################## mountpoint = /mnt/1wire allow_other ####################### OWHTTPD ######################### http: port = 2121 ####################### OWFTPD ########################## ftp: port = 2120 ####################### OWSERVER ######################## server: port = localhost:4304 Create Startup Script I created a startup script for owfs modelled on the owserver script (not sure why this one is actually missing) vim /etc/init.d/owfs #!/bin/sh ### BEGIN INIT INFO # Provides: owfs # Required-Start: $remote_fs $syslog $network $named # Required-Stop: $remote_fs $syslog $network $named # Should-Start: owfs # Should-Stop: owfs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: 1-wire file system mount & update daemon # Description: Start and stop 1-wire file system mount & update daemon. ### END INIT INFO CONFFILE=/etc/owfs.conf DESC="1-Wire file system mount" NAME="owfs" DAEMON=/usr/bin/$NAME case "$1" in start) echo "Starting $NAME" $DAEMON -c $CONFFILE ;; stop) echo "Stopping $NAME" killall $NAME ;; *) echo "Usage: $N {start|stop}" >&2 exit 1 ;; esac exit 0 Starting daemons /etc/init.d/owserver start /etc/init.d/owfs start Checking output #ls /mnt/1wire/ Should show output similar to: 10.575349000000 12.95DD17000000 alarm simultaneous uncached 10.575349000000 12.95DD17000000 bus.0 statistics 12.57DD16000000 81.B2EA2E000000 bus.1 structure 12.57DD16000000 81.B2EA2E000000 settings system cat /mnt/1wire/10.575349000000/temperature Will then show…

Continue ReadingAccessing 1-wire devices on Raspberry Pi using OWFS

Installing OMXPlayer on Raspberry Pi

Since I didn't have any luck playing videos on the RPi using mplayer I found omxplayer after some search. It has the ability to use the RPi's GPU thus taking some load of the CPU. UPDATE 2013-04-01: omxplayer is now included in the Raspbian (Debian Wheezy) repositories and can be simply installed by one line. sudo apt-get install omxplayer Check another article on how to install Raspbian. OMXPlayer binary (.deb) downloads can be found here: Install dependencies apt-get install libpcre3 fonts-freefont-ttf fbset libpcre3-dev libpcrecpp0 libva-dev libva-x11-1 libva1 Install omxplayer wget dpkg -i omxplayer_0.2.4~git20121205~ec7ac68f_armhf.deb Play video omxplayer -o hdmi video.mp4 Note: If there is no sound when playing through the HDMI interface make sure your /boot/config.txt file has the following line (and it's not commented out). hdmi_drive = 2 OMXPlayer Key bindings Key Action 1 Increase Speed 2 Decrease Speed j Previous Audio stream k Next Audio stream i Previous Chapter o Next Chapter n Previous Subtitle stream m Next Subtitle stream s Toggle subtitles q Exit OMXPlayer Space or p Pause/Resume - Decrease Volume + Increase Volume Left Seek -30 Right Seek +30 Down Seek -600 Up Seek +600

Continue ReadingInstalling OMXPlayer on Raspberry Pi

Raspberry Pi – Text to Speech

Just a quick note on Speech Synthesis a Raspberry Pi project. I had to research some of the options on the Raspberry Pi while looking into a project where I need some audio announcements. Configuring Sound echo 'snd-bcm2835' >> /etc/modules sudo modprobe snd-bcm2835 sudo apt-get install mplayer alsa-base alsa-utils pulseaudio mpg123 # make mplayer use mpg123 codec instead of default ffmp3float echo "afm=mp3lib" >> ~/.mplayer/config Since I am using Raspbian which is a Debian based (Wheezy) Distribution I used some Ubuntu documentation ( as the starting point. Festival sudo apt-get install festival festival-english echo "Hello World - Testing" | festival --tts Plus: Local install (no internet connection required) Minus: Mechanical sounding voice Espeak sudo apt-get install espeak espeak -v en "Hello World - Testing" Plus: Local install (no internet connection required) Minus: Mechanical sounding voice (slightly better than Festival) Google Translate Create a shell script #!/bin/bash mplayer -ao alsa -noconsolecontrols "$*" > /dev/null 2>&1 chmot +x ./ "Hello World - Testing" Plus: needs live internet connection Minus: excellent human sounding voice Google Speech API I will most likely look at this in the long run to get better control rather than calling the Google Translate url too much.

Continue ReadingRaspberry Pi – Text to Speech