Skip to content

Instantly share code, notes, and snippets.

@glennschler
Last active March 25, 2022 02:39
Show Gist options
  • Save glennschler/7345428 to your computer and use it in GitHub Desktop.
Save glennschler/7345428 to your computer and use it in GitHub Desktop.
Raspberry Pi Notes
#
# /etc/network/interfaces
#
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa_roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Notes

Install of Wheezy-Raspbian v2013-09-25

Configure Raspberry Pi from Mac OS X

  • Download Raspbian Raw image

  • From the OS X command line. Following these eLinux SD Card Setup. To summarize:

    • diskutil list
      • identify the disk (not partition) of your SD card. e.g. disk4 (not disk4s1)
    • diskutil unmountDisk /dev/<disk# from diskutil>
      • e.g. diskutil unmountDisk /dev/disk3
    • sudo dd bs=1m if=<your image file>.img of=/dev/<disk# from diskutil>
      • e.g. sudo dd bs=1m if=2013-09-25-wheezy-raspbian.img of=/dev/disk4
      • (This will take some time)
  • Start-up the Raspberry Pi

    • Insert the SD Card
    • Setup I/O access, using either of two possible options:
      1. External display
        • Connect a keyboard to the RPi USB port
        • Plug NTSC/PAL TV into RPi composite port or HDMI monitor to the HDMI Port.
        • Turn on when connected with RPi Micro USB port cable. Powered via a computer USB port, or a USB wall charger.
      2. Terminal Emulator with USB to TTL Serial Cable console cable connected to the RPi GPIO
  • Follow these Adafruit instructions for post boot setup using Raspi_Config. To summarize:

    • Expand the SD card partition to it's full size. (e.g. 16GB)
    • Using the Whole Screen
    • Changing Timezone
    • [optional] Booting into Desktop when using external monitor
    • [optional] Change password
    • Choose menu item "Advanced Options"
      • Change Hostname e.g. hostname_pi
      • Enable the SSH server
      • Update Raspi_Config
  • Start with any linux (raspbian) updates

sudo apt-get update
sudo apt-get upgrade
  • Optional

    sudo apt-get install vim
    sudo apt-get install htop
    
  • I have a few old USB Belkin F5D8053.v4 WiFi which work even if not on the list

  • If Wifi, do WiFi management using WpaSupplicant.

    sudo apt-get install wpasupplicant
    
    • Generate a WPA PSK from an ASCII passphrase. Put output into wpasupplicant CONF file
    wpa_passphrase "__SSID__"
    
    • Create the etc/network/interfaces file (shown below).
    • Create the /etc/wpa_supplicant/wpa_supplicant.conf file (shown below).
  • Avahi-daemon implements the Apple Zeroconf specification, (like bonjour) after this it is easy to ping hostname_pi.local from OS X or other Zeroconf configured machine. Secondly, avaih-utils will make it easy to find other RPis on the local network.

sudo apt-get install avahi-daemon avahi-utils
  • Connect using SSH over wifi.

    • Disconnect console cable which is connected to the RPi GPIO.
    • Disconnect external monitor and keyboard.
    • Power with the Micro USB cable.
    ssh pi@hostname_pi.local
    
  • [Optional] Follow the Adafruit instructions to setup and control with desktop UI using VNC.

// Run this script in node.js
//
// First install deps:
// sudo apt-get install libexiv2-12 libexiv2-dev
// npm install exiv2
//
// Argument #1 = .JPG relative path
// Argument #2 = overwrite file true/false. False will create a new file with ".jpg.jpg" extension
// "raspicam-fix-exif.js"
ar ex = require('exiv2');
var fs = require('fs');
// overwrite or not? true/false
var _OVERWRITE=process.argv[3];
// the file name to read exif
//example '/tmp/RPIPICI13120400001.jpg';
var fName = process.argv[2];
// make a backup which should be overwriten
// with the fixed tags
//
function copyFile(origFName, newFName, cb) {
var fCalledBack = false;
var readIn = fs.createReadStream(origFName);
readIn.on("error", function(err) {
callback(err);
});
var writeOut = fs.createWriteStream(newFName);
writeOut.on("error", function(err) {
callback(err);
});
writeOut.on("close", function(ex) {
callback();
});
readIn.pipe(wr);
function callback(err) {
if (!fCalledBack) {
// call the callback function which was passed in.
cb(origFName, err);
// to be safe, in case err/close trigger arrives more than once
fCalledBack = true;
}
}
};
// Get the exif info
//
function getImageTags(fName, cb) {
console.log ("reading exif... " + fName);
ex.getImageTags(fName, function(err, tags) {
if (err) throw err;
var dateTime = tags["Exif.Image.DateTime"];
var dateTimeOriginal = tags["Exif.Photo.DateTimeOriginal"];
var dateTimeDigitized = tags["Exif.Photo.DateTimeDigitized"];
// print the old values
console.log("\tFilename: " + fName + " :: \n" +
"\tDateTime: " + dateTime + "\n" +
"\tDateTimeOriginal: " + dateTimeOriginal + "\n" +
"\tDateTimeDigitized: " + dateTimeDigitized + "\n");
// fix the old values. Replace the ":" in between date and time with a " ".
dateTime = dateTime.substr(0, 10) + " " + dateTime.substr(11, 20);
dateTimeOriginal = dateTimeOriginal.substr(0, 10) + " " + dateTimeOriginal.substr(11, 20);
dateTimeDigitized = dateTimeDigitized.substr(0, 10) + " " + dateTimeDigitized.substr(11, 20);
// put then in a new tag array
var newTags = {
"Exif.Image.DateTime" : dateTime,
"Exif.Photo.DateTimeOriginal" : dateTimeOriginal,
"Exif.Photo.DateTimeDigitized" : dateTimeDigitized
};
// callback the caller
cb (fName + (_OVERWRITE ? "" : ".jpg"), newTags);
});
};
// Write out the new exif tags to the new jpg file
//
function setImageTags (newFName, newTags) {
// now save the exif info
ex.setImageTags(newFName, newTags, function(err) {
console.log ("Exif set = " + (err ? ("Error: " + err) : "Success"));
}); // set image
};
// Called either directly or after the copy file (when not overwriting) is complete
function retag(fName, err) {
if (err) throw err;
console.log ("getting....");
// lets get the original tags
getImageTags (fName, function (newFName, newTags) {
console.log("Will soon set tags to " + newFName);
setImageTags (newFName, newTags);
});
};
console.log ("working....Overwrite=" + _OVERWRITE + " Fname=" + fName);
// This is the primary control. Either overwrite or not.
if (_OVERWRITE) {
console.log ("overwriting\n");
// get the tags. Overwrite the original file with the fixed date flags.
retag(fName);
}
else {
// Do not overwrite the file. Instead name it "*.jgp.jpg"
console.log ("not overwrite\n");
// Start by copying the file where the new exif info will go
// Pass the "retag" function as the callback, so once the copy
// is complete, the flow will continue as normal
//
copyFile (fName, fName + ".jpg", retag);
}
#
# /etc/wpa_supplicant/wpa_supplicant.conf
# config will connect to either WPA1 or WPA2
#
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
# Use the PSK string which was output by executing the wpa_passphrase utility!
ssid="__SSID__"
psk= __PSK__
# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA RSN
group=CCMP TKIP
# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=CCMP TKIP
# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or
# Enterprise)
key_mgmt=WPA-PSK
#Authorization option should be OPEN for both WPA1/WPA2 (in less
#commonly used are SHARED and LEAP)
auth_alg=OPEN
}
  • One option is to download the latest nodeJs.org source tarball, and make the node binary. This is a different exercise which this gist file does not address.

  • Get the Node binary directly from the originating source at NodeJs.org (Joyent). They often have a RPi binary distribution in their latest stable release. Review the latest node distro directory to see if it is there.

mkdir -p ~/tmp
cd ~/tmp

# Change to the version needed. The 'latest' version or a specific version.
#nver=v0.10.21
nver=latest

# Download the index.html of the requested version of the node.js directory
wget -N http://nodejs.org/dist/$nver/
cat index.html | grep arm-pi | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 > tmp1.txt

# Since not every release has an arm-pi binary, check before attempting to download
[ `stat -c %s tmp1.txt` -eq 0 ] \
&& printf "\nVersion $nver arm-pi release is NOT available for download\n\n"
  • If there is a arm-pi distrubution, download and unzip
# If so, Download and unzip
[ `stat -c %s tmp1.txt` -ne 0 ] \
&& ( wget -N "http://nodejs.org/dist/$nver/"`cat tmp1.txt` \
&& tar -zxvf node-v*arm-pi*.tar.gz )
  • Move the node binaries and docs to be available in the path.
# Remove any old node version. Create the dir again
sudo rm -r -f /opt/node
sudo mkdir /opt/node

# Move the expanded files
sudo mv node-v*arm-pi*/* /opt/node

# Symlink node and npm to somewhere already in the path. Debate where... 
sudo ln -s -f /opt/node/bin/node /usr/bin/node
sudo ln -s -f /opt/node/bin/npm /usr/bin/npm

# test
which node && node --version
which npm && npm --version

# Cleanup [optional]
rm -r node-v*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment