Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

How to setup a Raspberry Pi on macOS with Raspbian, Python, Node, Ansible, Kubernetes

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

This tutorial provides manual instructions and automation scripts to setup and run apps.

Why: Use cases for the Pi

VIDEO: What to run on a Raspberry Pi?

  • Many existing Raspberry projects are targeted for learning by children.

  • Block Ad tracking on your own network DHCP DNS using PiHole paired with a VPN

  • A camera/webcam for time lapse videos or smart object-detection (running Tensorflow)

  • Light show based on what music is playing

  • Setup a NAS (Network Attached Storage) using OpenMediaVault * Run a media library to play songs, videos (from a separate drive)

  • Run a private GitHub server on a Pi.

  • Run Home Assistant or OpenHAB to control lights, monitor environment, and other automation. Zigbee. HOOBS integrates Alexa, Nestcam, etc. with Apple HomeKit.

  • Display a clock, task list, calendar, a static menu like at a restaurant), or rotating pictures in a nursing home – from an old PC or older Pi.

  • Run one of the “goat” server which contains known security issues. OWASP

  • Geerling: build a 4G/5G wireless router modem (instead of buying one such as The $319 gigabit Firewalla Purple, between your router and modem, bundles networking, ad-blocking, intrusion detection and prevention, parental controls, and a virtual private network (VPN) into one compact, purple box and a mobile app.

  • Process video to .mp4

  • HTPC (Home Theater Personal Computer) services running on k3s at https://github.com/fabito/htk8s

Kubernetes on Pi

For enterprises, the Raspberry Pi doesn’t come with the corporate buracracy.

  • uses ARM CPU chips, so is a good platform to

  • thoroughly test whether apps work well the ARM chip, such as ones used on AWS Graviton server types (rather than traditional Intel x86).

https://github.com/k8s-at-home has a list of GitHub repos

rasp-pi-rack-836x960 Run apps (within Docker containers) in Kubernetes on a cluster of (“bramble”) Rasperberry Pi computers in order to become proficient at configuring the correct mix of settings for ARM and to refine automation scripts for functional and capacity (load balancing and scaling) testing of containers. The cost of a each board in a “extreme” Pi cluster which orchestrates several Pi’s together is less than a perhaps a single day running a Kubernetes cluster in a “pay as you go” cloud environment. Without cost pressures, a stand-alone Pi can run overnight (or all week) without the hassle of needing to be brought down for cost reasons. Compare performance using Linpack Benchmark vs Turnpike2.

VIDEO: install of Ubuntu plus light-weight K3S from SUSE Rancher dashboard app to manage the private cloud “supercomputer” cluster.

Tim Wood’s hardware cluster consists of

  1. Binary Clock python script with Blinkt! LED board.
  2. Apache with Nagios network monitoring server.
  3. Network-wide DHCP server and DNS filtering through Pi-hole.
  4. Upstream DNS filtering through Pi-hole for high availability, VPN though Wireguard to help bring internet traffic from my devices back through DNS filtering (even if I’m outside of my home network).

Software:

  1. https://github.com/fluxcd/flux2 – a tool for keeping Kubernetes clusters in sync with sources of configuration (like Git repositories), and automating updates to configuration when there is new code to deploy.

References:

  • https://github.com/mikeroyal/Raspberry-Pi-Guide
  • https://opensource.com/article/20/6/kubernetes-raspberry-pi
  • https://ubuntu.com/tutorials/how-to-kubernetes-cluster-on-raspberry-pi#1-overview
  • https://dev.to/andypiper/building-a-compact-pi-cluster-1pia

Hardware Each Node

If you want the maximum on-board 8GB RAM on each board, order the Raspberry Pi 4 B (dual displays, 1.5GHz quad-core, 15W USB-C, 2xUSBv2, 2xUSBv3) – BMC2711 $67.49 (with no SD card) from Horione or $157.86 with power, 32 GB SD, and fan in clear case from AliExpress, or $187.90 w/128 SD “Extreme Kit” with fan in black box and cables from CanaKit.

The Extreme Kit’s box comes with a fan, because heat reduces the life of a board.

Heat sinks glued on top of each chip helps to difuse heat.

Power over Internet cables and network switch or Power supply:

  • Pi 3 INPUT: 0.3 A, OUTPUT: +5V = 2.5A with micro USB port
  • Pi 4 INPUT: 0.5 A, OUTPUT: +5.1V = 3.0A with USB-C port

You’ll need at least one monitor display. CAUTION: Multiple displays will make the chip run hotter. The Pi supoports 1900x1080 (HD) monitors with full-size HDMI ports.

Newer Pi have mini HDMI ports, so be sure to have an adapter or a cable with a mini on one end and a full HDMI adapter on the other end.

  • The black ports are v2 for a mouse and keyboard.
  • The blue ports are v3 for ?

Speaker

https://cloudinit.readthedocs.io/en/latest/


Hardware competiting with Pi

The Pi is a Single Board Computer (SBC), a “small form factor” computer with a tiny footprint that put full-sized PC power in the palm of your hand:

  • Banana Pi M64
  • Libre Computer Board ALL-H3-CC
  • Pine64
  • Pine64 Rock64
  • Radxa ROCK PI 4c
  • Intel NUC (Next Unit of Computing, pronounced like “luck” or “truck”), available with Windows 10 and up to 4.40 GHz

Operating Systems for the Pi

The Raspberry Pi needs an operating system written for the ARMv8 CPU on the Pi 3, which replaces Pi 2 and its ARMv7 CPU. Based on this.

Several operating systems can be installed on a Raspberry Pi:

  • AndroidThings from Google (another page)
  • Windows 10 IoT from Microsoft (another page on this website)
  • CircuitPython from Adafruit
  • Sidero Talos OS for Kubernetes
  • Raspbian, a derivative of Debian Linux (described on this page, below) PROTIP: The Raspbian OS (based on Debian) is the official release for Raspberry Pi.

To install:

  1. On a Mac, get an adapter for your laptop to read micro-SD card

  2. Attach a static discharge bracket to your wrist to ground.
  3. Insert micro-SD chip in your laptop

On MacOS

  1. Format micro-SD card
  2. Download disk image for Talos
  3. Download Pi OS Imager
  4. Calculate and compare SHA hash (for download integrity)
  5. Format micro-SD chip for MacOS or Windows
  6. Load OS image to the Pi SD (on macOS)

On Windows

  1. Format micro-SD card
  2. Download disk image for Talos
  3. Download Pi OS Imager
  4. Calculate and compare SHA hash (for download integrity)
  5. Format micro-SD chip for MacOS or Windows
  6. Load OS image to the Pi SD (on macOS)

On the Raspberry Pi

  1. Power up the stock Pi into the Raspbian GUI
  2. Configure wi-fi connections on the Pi
  3. Configure HAT addons
  4. Configure SSH into Pi from your Mac laptop
  5. Get and run configuration scripts

  6. Run Bash shell script on boot-up to download a script from GitHub and run it.

This too much hassle? I can sell you a chip with everything described below.


Micro-SD and USB Adapter needed?

You may need to buy a 32 or 64 GB SD chip along with an adapter if you need one (as for cameras).

2017+ Mac Book Pros do not have a slot to read SD cards, so need a USB-C converter rather than older types of USB ports.

WARNING: You need to plug the micro SD chip into a full-size SD chip adapter, which goes into the Mac’s SD card slot. You may also use an adapter for USB, which may need to be plugged into a USB port rather than on a USB hub (even a powered one).

CAUTION: Be sure the adapter can read the size of chip. Older ones for reading 4GB cannot read the 32GB or 64GB let alone 128GB chips.

Insert micro-SD chip in your laptop

  1. CAUTION: Before touching delicate electrical boards, dissipate static electricity (from just walking around) by touching grounded metal.

  2. Insert the Micro-SD chip into your laptop or adapter.

    Initialize micro-SD chip in your laptop

  3. Click “Initialize…” if you see “The disk you attached was not readable by this computer.”.

  4. In the macOS Disk Utility, click the “Apple SDXC Reader Media” at the left.

    NOTE: It says “8.17 GB” even though the SD chip may be larger.

  5. Right-click the “Apple SDXC Reader Media” to select Erase…

    That’s just so we see more information.

  6. Click on Format to show the different formats:
    • Mac OS Extended (Journaled)
    • Mac OS Extended (Case-sensitive, Journaled)
    • MS-DOS (FAT)
    • ExFAT

  7. Click on “Scheme”:
    • GUID Partition Map
    • Master Boot Record
    • Apple Partition Map

  8. Click “Cancel”.

Download Talos RPI image

Skip to DownloadImager unless you want to install Talos:

Steps in this section can be performed by a script.

  1. Make or navigate to a folder so you can easily tell what is downloaded:

    cd; mkdir projects/talos
  2. Download the compressed image file per this doc:

    curl -LO https://github.com/talos-systems/talos/releases/latest/download/metal-rpi_4-arm64.img.xz
  3. Uncompress using the xz utility:

    xz -d metal-rpi_4-arm64.img.xz
  4. Verify downloaded file size:

    ls -al
    -rw-r--r--  1 wilsonmar  staff  94156684 Mar 24 19:12 metal-rpi_4-arm64.img.xz

    That’s 94,156,684

Download Pi OS Imager

  1. At https://www.raspberrypi.org/downloads

    NOTE: Because many operating systems can be used now, mention of “Raspian” have been removed from this page. Previously this appeared:

    iot-rasp-stretch-download-942x496-65658

    REMEMBER: Only one operating system can be loaded on the Pi.

  2. Click “Download for macOS” to download the Imager app:

    Date/File Version Download Unzipped Blog
    2019-04-08 imager_1.7.1.dmg - 18.7 MB ? GB -

    Date/File Version Download Unzipped Blog
    2020-02-13-raspian-buster.zip ? 1.19 GB ? GB -
    2019-04-08-raspbian-stretch.zip 4.14 1.76 GB 4.83 GB -
    2018-06-27-raspbian-stretch.zip 4.14 1.76 GB 4.83 GB -
    2018-03-13-raspbian-stretch.zip 4.10 1.78 GB 4.96 GB -
    2017-09-07-raspbian-stretch.zip 4.9 1.76 GB 4.92 GB -
    2017-04-10-raspbian-jessie.zip 4.4 1.57 GB ? GB blog
    2016-09-23-Raspbian-jessie.zip 4.3 1.40 GB 4.3 GB -

    The large size of the file means it will take a while, depending on the speed of your network.

    Alternately, Raspian provides sudo-free access to GPIO (file read/write ports), so the above can be done in an Ubuntu terminal.

    PROTIP: Versions of Debian are named after characters in Disney’s “Toy Story” films

    • “Buster” is Andy’s pet miniature dachshund
    • “Stretch” the rubber octopus is voiced by Whoopi Goldberg
    • “Jessie” is the cowgirl, voiced by Joan Cusack
    • “Wheezy” is the squeeze toy penguin with the red bow tie.
    • “Sid” is the bad boy.

    QUESTION: Where is the history of old versions and how does one get announcement emails?

    Click the red Download ZIP below Raspbian STRETCH WITH DESKTOP, not “Raspbian Stretch with desktop and recommended software”.

    PROTIP: The button sends you to downloading URL https://downloads.raspberrypi.org/raspbian_latest (which can be used in unattended shell scripts to automate the clicking).

    If you clicked “Raspbian Stretch with desktop and recommended software”, the file name downloaded would contain “-full”, and be bigger.

    NOTE: The previous version name PIXEL, which stands for “Pi Improved X-Windows Environmet, Lightweight”. But many refer it simply as “X”.

    Calculate and compare hash on Mac

  3. Calculate a SHA hash from the downloaded file to verify SHA from the website.

    NOTE: Inside the file are .elf (Executable Linkable Format) and .dtb (Device Tree Blob) files.

    On MacOS, open a Terminal and cd to the Downloads folder to use a built-in command:

    PROTIP: Type just shasum with a trailing space, then from Finder drag the file and drop it to the right of the command. You’ll end up with this command:

    cd ~/Downloads
    shasum /Users/YourAccount/Downloads/2018-06-27-raspbian-stretch.zip
    

    Press Enter to invoke the command.

    Alternately, use the openssl utility:

    openssl sha256 2018-06-27-raspbian-stretch.zip
    
  4. The output should match the SHA-256 associated with the downloaded file on the website. Example as shown above:

    8636ab9fdd8f58a8ec7dde33b83747696d31711d17ef68267dbbcd6cfb968c24

    PROTIP: A 256-bit hash, when divided by 4 bits each digit, should have 64 characters.

  5. PROTIP: Save the .zip file to permanent DVD media so you don’t have to download again, then delete the file on your laptop (to make room for other stuff on your hard drive):

    A regular single-sided, single layer DVD (R+ or R-) holds 4.7GB. A dual-layer “DL” DVD disk holds 8.5GB. The file must be smaller (which it is…for now).

    Run Imager

  6. Open file “imager_1.7.1.dmg” to pop-up /Volumes/Raspberry Pi Imager.
  7. Drag the Raspberry Pi Imager.app icon and drop it over the blue folder (to move it into the Applications folder).
  8. Press command+Q or click the red dot at the upper-right.
  9. Delete file “imager.x.x.x.dmg” file (to recover disk space).
  10. Find file “Raspberry Pi Imager.app” and click to run it.
  11. Click “Open” for the dialog about “Are you sure you want to open it?”.
  12. Click “CHOOSE OS” (do NOT select the first “Raspberry Pi” you see because it is for older 32-bit chips).
  13. If you are installing for a Raspberry Pi 64-bit, select “Raspberry Pi OS (other)”, then a 64-bit one “with no desktop environment” (because you’re a pro).

    Alternately, if you are installing Talos, scroll down to select “Use custom” and navigate to where you downloaded a zip file for that.

  14. Click “CHOOSE” in under “Storage” and select “Generic- Micro SD/M2 Media - 128.2 GB”.

    If you don’t see the selection, unplug the chip and insert again.

  15. If you are installing Raspian, click the gear icon to configure wi-fi SSID and password.

    If you are installing Talos, do not click the gear icon to configure, or you’ll see “Operating system did not mount FAT32 partition” later.

  16. Click “WRITE” and “YES” to “All existing data … will be erased. Are you sure you want to continue?”.
  17. Click “OK” to “Raspberry Pi Imager.app” would like to access files on a removeable volume.”
  18. Provide your laptop’s password to allow writing.

  19. While you’re waiting for the writing and verifying, read blog at Raspberrypi.org.

    If you see “Operating system did not mount FAT32 partition”, ???

  20. Click “CONTINUE” when “Write Successful” appears, “You can now remove the SD card from the reader” appears.

  21. If you have another chip, repeat the above steps so you’ll have a backup at the ready.

  22. Press command+Q to exit the Imager app.

    Remove zip/tz file

  23. For the next step, open a Terminal and cd ~/Downloads.

    PROTIP: Do not unzip the file downloaded because the program that processes it expects a zip file.

    If you are using Windows, skip to the Windows Prep SD section below.

    This steps below is for Mac working with Talos:

  24. Delete the file “metal-rpi_4-arm64.img.xz” if disk space on your Mac is an issue for you.

    Format micro-SD chip on your MacOS

    A new entry should appear in Finder when you plug in the SD card.

  25. Open a Finder window. Scroll down the left panel to see it appear among the Device section.

  26. Open a Terminal shell window.

  27. Identify the SD disk identifier:

    diskutil list

    A sample response:

    /dev/disk0 (internal):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                         500.3 GB   disk0
    1:                        EFI EFI                     314.6 MB   disk0s1
    2:                 Apple_APFS Container disk1         500.0 GB   disk0s2
     
    /dev/disk1 (synthesized):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      APFS Container Scheme -                      +500.0 GB   disk1
                                  Physical Store disk0s2
    1:                APFS Volume ⁨Macintosh HD - Data⁩     447.4 GB   disk1s1
    2:                APFS Volume ⁨Preboot⁩                 334.3 MB   disk1s2
    3:                APFS Volume ⁨Recovery⁩                1.1 GB     disk1s3
    4:                APFS Volume ⁨VM⁩                      3.2 GB     disk1s4
    5:                APFS Volume ⁨Macintosh HD⁩            15.8 GB    disk1s5
    6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.8 GB    disk1s5s1
     
    /dev/disk2 (disk image):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        +109.1 MB   disk2
    1:                  Apple_HFS ⁨Raspberry Pi Imager⁩     109.0 MB   disk2s1
    

    PROTIP: Use “/dev/disk2” because that “109.1 MB” is your “128 GB” chip. The difference between those two numbers is in the different ways the computer versus marketing people calculate the amount of bits. Inside the computer, bits are calculated using 1024 blocks.

    Alternately, the sample response for Mac Sierra and before:

    /dev/disk0 (internal, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        *500.1 GB   disk0
    1:                        EFI EFI                     209.7 MB   disk0s1
    2:          Apple_CoreStorage Untitled 1              499.2 GB   disk0s2
    3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
     
    /dev/disk1 (internal, virtual):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:                            Macintosh HD           +498.9 GB   disk1
                                  Logical Volume on disk0s2
                                  8B999D6F-A427-4EC5-A197-85AF9E00C10E
                                  Unencrypted
    /dev/disk3 (external, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *63.9 GB    disk3
    1:               Windows_NTFS                         63.8 GB    disk3s1
    

    In the above example, the 64 GB SD card IDENTIFIER is “disk3”.

  28. Type a command to unmount your SD card (so a utility can overwrite the entire disk) by constructing a command containing the disk identifier number for your SD card (3 in the example above):

    diskutil unmountDisk /dev/disk3

    Again, instead of “disk3”, you may type a different one.

    The expected response is:

    Unmount of all volumes on disk3 was successful

    Get Etcher for MacOS

    PROTIP: The official Raspberry Pi site describes use of another tool, but Etcher reads from a zip file to skip unzipping hassle, and verifies the SD card image was written correctly to the SD card. It also automatically dismounts the SD card so it can be safely removed. See https://www.raspberrypi.org/magpi/pi-sd-etcher

  29. On MacOS, download from their website (formerly etcher.io):

    https://etcher.balena.io/#download-etcher

    NOTE: The Homebrew package “etcher” in no longer available.

  30. Click “Download for Mac” (they also have a version for Windows and Linux).

    The “Got info” over time for macOS:

    File downloaded Size Date
    belanaEtcher-1.18.11.dmg 100.8 MB 2023-12-22
    belanaEtcher-1.5.33.dmg 116.3 MB 2019-05-04
    Etcher-1.1.2.dmg 58.9 MB 2018-11-03
    Etcher-1.0.0-darwin-x64.dmg 67.9 MB 2017-10-15
    Etcher-1.0.0-beta.16-darwin-x64 75.4 MB 2017-06-11

    Following Beginner’s Guide to installing Node.js on a Raspberry Pi (made by Resin.io):

  31. In Finder double click the belanaEtcher…dmg file to invoke it.
  32. In the pop-up, drag and drop the belanaEtcher icon file onto your ~/Applications folder.
  33. Click “Open” to the pop-up about “balanaEtcher.app” is an app downloaded from the internet.
  34. In a MacOS Terminal, navigate to the user Applications folder and invoke the program:

    open ~/Applications/balenaEtcher.app

  35. In Finder, free up disk space on your machine by right-clicking on the .dmg file and “Move to Trash”.
  36. Verify that there are no files on the flash drive you would miss.

    CAUTION: Flashing wipes out all previous contents on the flash drive.

  37. Switch back to Etcher to click “Select image”.
  38. Click “Select drive” for Etcher to detect a flash (SD) drive.
  39. Click “Flash!” to write the image to the flash drive.
  40. Type your Admin password.
  41. Wait for the Copying, then Validating to each reach 100%.

  42. Exit the Etcher program by clicking the red X of the app screen.

  43. Skip to the verify step below to use the bootable Flash drive.

    Flash OS on SD card using a Mac

  44. cd to the folder where your .img file exists. For example, to go to the Desktop:

    cd ~/Desktop

  45. To avoid “Operation not permitted” in the dd command below, on a Mac go to System Preferences > Security & Privacy > Full Disk Access > Terminal (or iTerm2, etc.).
https://github.com/siderolabs/talos/releases/download/v1.0.0/talosctl-$(uname -s tr “[:upper:]” “[:lower:]”)-amd64
  1. Manually construct a command to write the image downloaded onto the SD Card. Replace the X in rdiskX with the disk number from before. For example:

    sudo dd if=2018-06-27-raspbian-stretch.img of=/dev/rdisk2 bs=1m

    BLAH: The dd command does not have a verbose mode to show progress.

    NOTE: The dd program is also used to backup the SD onto your laptop.

    The Linux dd command copies a file and also optionally re-formats.

    if= specifies the input file name.

    of= specifies the output file disk identified by the diskutil command above.

    rdisk gives faster write speed to the SD card.

    bs=1m specifies 1 megabyte chunks to write at a time.

    count=256k limits the number of blocks processed.

    oflag=direct bypasses the kernel’s page cache (memory cache), writing directly to the storage.

  2. Alternately,

    sudo dd if=metal-rpi_4-arm64.img of=/dev/disk2 bs=4m conv=fsync

    conv=fsync synchronizes output data and metadata just before finishing. Some operations are stored in RAM and postponed to be later written on the disk. Some devices use buffers and caches in order to improve their throughput and latency performance. So this flag tells dd to write everything on the disk (forcing a physical write of output data and metadata). This command makes the device flush its buffers and caches so that if the device is removed the data is written to it before the operation is marked as complete and before control passes back to the terminal prompt. See https://abbbi.github.io/dd/

  3. Type in your password then wait.

    No status is shown during the 30 minutes or more that it takes. An example of the ending response:

    4147+0 records in
    4147+0 records out
    4348444672 bytes transferred in 265.020326 secs (16407967 bytes/sec)
    
  4. Unmount (construct command with correct disk2):

    sudo diskutil unmountDisk /dev/disk2

    Response:

    Unmount of all volumes on disk2 was successful

    You should now have a working SD card for Raspian.

  5. Switch to a Terminal to verify what devices are mounted from any folder:

    df -h

    This sample response confirms that the flash drive is not visible to the Mac:

    Filesystem      Size   Used  Avail Capacity iused               ifree %iused  Mounted on
    /dev/disk1s1   466Gi  426Gi   29Gi    94% 3576707 9223372036851199100    0%   /
    devfs          344Ki  344Ki    0Bi   100%    1190                   0  100%   /dev
    /dev/disk1s4   466Gi   10Gi   29Gi    26%      11 9223372036854775796    0%   /private/var/vm
    map -hosts       0Bi    0Bi    0Bi   100%       0                   0  100%   /net
    map auto_home    0Bi    0Bi    0Bi   100%       0                   0  100%   /home
    
  6. In Finder, press the eject button for the disk.

  7. Skip past alternative activity below (for Windows) to Power Up to GUI in SD card.


Windows Prep SD

To get full capacity from USB/SD drives (which format does not solve):

  1. On a Windows machine, press the Windows key and type in the omni-search box

    diskpart

  2. Get the disk number:

    list disk

    Identify the disk number for the SD drive based on size of disk.

    “3850 MB” is displayed for drives sold as “4 GB”.

  3. Reset:

    select disk 1
    select partition 1
    delete partition
    partition
    clean
    create partition primary
    format
    

    Formatting takes several minutes.

    “DiskPart successfully formatted the volume.”

  4. Close the window:

    exit

  5. In File Explorer, right-click on the drive and select Eject.

    Unzip and Flash using Windows

  6. Unzip to an .img file.

    BLAH: The .img file is larger than what can fit in a 4GB USB drive. So if you try to copy it to a drive formatted as FAT32 (rather than NTFS), a “not enough space” error message is issued even though there is plenty of room on the drive.

    The solution is to use a Windows machine and format drives as NTFS.

    MacOS can read from NTFS drives, but cannot write to them without some additional effort, described below.

    Both Mac and Windows can read drives formatted in exFAT (even though Microsoft is its patent holder). So format external drives that way.

    If your Mac has a Seagate drive, download from Seagate a FREE installer NTFS_for_Mac.dmg. It’s 28.6 MB.

    NTFS_for_Mac_14.0.456.dmg is the installer for all drives from $19.95 Paragon Cleverbridge, which offers a 10-day trial.

    Paid Third-Party Drivers: There are third-party NTFS drivers for Mac that you can install, and they’ll work quite well. These are paid solutions, but they’re easy to install and reportedly offer better performance than the free solutions below.

    Alternately, download the free osxfuse and install it using Homebrew.

    See this. You’ll have to disable System Integrity Protection and then re-enable if after you’re done.

  7. Download from
    https://www.sdcard.org/downloads/formatter_4
    the SD Card Formatter 4.0 for SD/SDHC/SDXC program to format SD cards. The “secure” name means that the card has a “Protected Area” which the program honors while formatting.

    • SDFormatter_4.00B.pkg for Macs
    • SDFormatterv4.zip for Windows containing a setup.exe installer.

  8. Download binary version of Windows-only win32diskimager from https://sourceforge.net/projects/win32diskimager (forwarded from https://launchpad.net/win32-image-writer/+download)

    Win32DiskImager-0.9.5-binary.zip, 18.3 MB Last updated 2016-10-04

    Unzip it for a folder named
    Win32DiskImager-0.9.5-binary which contains
    Win32DiskImager.exe

  9. Invoke the program.
  10. Select the drive containing the .img file on your laptop.

On the Raspberry Pi:

  1. Plug in a USB keyboard.

    Power Up to GUI in SD card

    Based on this, if you insert a stock Raspbian image flash SD drive into the Pi and power it up, it would by default display a GUI, with no WiFi connection.

  2. Unlug the power adapter.

    NOTE: There is no physical on/off switch on the Pi.

  3. Insert the micro SD card into the receptable at the bottom on the Pi.

    PROTIP: The metallic side of the card should face the Pi board.

    When in, the chip sticks out a bit.

  4. Plug in monitor and keyboard.

    The Pi 3 is capable of playing 1080p HD video (1900x800 pixels). So you can plug the other end of the HDMI cable into a TV.

    Older TVs without HDMI can still be used by using an adapter that converts HDMI signals, albeit at a lower resolution.

  5. Power up by plugging in the power.

    CONGRATULATIONS: Isn’t it exciting to see the screen appear on a new computer?

    Christopher Barnatt has a nice 9-minute about the PIXEL GUI

    TECHNICAL NOTE: To prevent starting from a really bad date, at shutdown, Raspbian saves a file containing a date at /etc/fake-hwclock.data so that time moves forward.

    Rather than booting up to the Linux command line and raspi-config, the default behaviour since Jessie is now to boot up to the desktop GUI (version 3 of GTK+, the user interface toolkit used for the LXDE desktop environment).

    Exit and return to GUI

  6. Exit GUI mode by pressing Ctrl + alt + F2 (from among F1-F12 keys) at the same time.

    Enable boot to CLI console

  7. When the regular Terminal window appears Configure the Pi

  8. Select the “Enable Boot to Desktop/Scratch” option

  9. Select “Console Text console”.

    Start Raspbian GUI

  10. To start the (PIXEL) GUI again from the console command line:

    startx

    View Raspbian GUI from Remote Desktop Client

  11. To see the GUI from your Mac, install the Xrdp daemon that runs in the background:

    sudo apt-get install xrdp -y

    -y skips manual confirmation for using 10.0 MB of disk space.

    WARNING: This takes up valuable memory, so only use during development.

  12. Open Remote Desktop Client

    On Windows, press the Start key on your keyboard and begin typing “Remote Desktop Client” until you see it in the list, then click it on the list.

    On a Mac, install the Microsoft Remote Desktop from Microsoft then open it in the Launcher.

  13. Specify IP address in Remote Desktop Client.

    Configure using GUI

  14. Click the Raspberry icon at the upper-left corner.
  15. Select Preferences.
  16. Select Raspberry Pi Configuration.
  17. Type in host name “raspi” so there is less to type.
  18. In Auto log-in, check “Login as user ‘pi’”

  19. Click the Localization tab and Set Locale, TimeZone, WiFiCountry.
  20. Click OK out the dialogs.

  21. To reboot from the GUI, click the raspberry Menu icon at the upper-right corner, select shutdown, then select reboot.

    Get Command Line from GUI

    PROTIP: Open up a Terminal window by pressing Ctrl+Alt+T or clicking the console icon in the GUI.

    Shutdown from console

  22. Shut down Respian properly before powering it off. Type:

    sudo halt

  23. Wait for the flashing the activity LED the Pi uses to signal it is ready to be powered off. Then type:

    sudo poweroff

  24. Power it up again for the next activity.

Optional: Configure SD for PiNet boot

If you want to network boot multiple Raspberry Pis, you could use PiNet at:

http://pinet.org.uk

It is a free and open-source community-based project initially designed for schools. Each Raspberry Pi boots off a small set of startup files on an SD card and fetches the rest of the data it needs from the PiNet server, thereby allowing you to maintain a single operating system image for all the Raspberry Pis. PiNet also adds network user accounts, shared folders and automated backups.


Connect via SSH on same router

A monitor, keyboard, and mouse do not need to be plugged into the Pi if you SSH into the device from your Mac or Windows PC.

Instructions here are based on this video.

  1. Identify the IP address

    ifconfig
    

    Under “etho0”, next to “inet addr:” is like
    10.0.0.10 or 192.168.0.3

    Alternately, if you don’t have access to the Pi:

    Identify IP from router

On your laptop:

  1. Connect a network cable between your router and a powered Pi.

    The Pi would automatically connect to a network.

    WARNING: The Pi and your laptop need to be plugged into the same router.

  2. On an internet browser, enter your router’s “Default Gateway”, typically at:

    https://192.168.0.1

    This is used by D-Link and Netgear models, but can be changed.

    To find it, see http://www.howtogeek.com/233952/how-to-find-your-routers-ip-address-on-any-computer-smartphone-or-tablet/ or https://www.lifewire.com/192-168-0-1-818066

  3. Look for a list of “Attached Devices” to copy IP address associated with device “raspberrypi” (such as “192.168.1.3”).

    SSH into Pi

  4. Open an SSH session (on port 22) to connect to the Pi.

    ssh pi@10.0.0.10

    From Windows, use PuTTY per http://www.makeuseof.com/tag/install-operating-system-raspberry-pi/

    ECDSA key fingerprint is SHA256:gsp3pSiLLjx4DyUPBW+YVnmjP38n5yKhKajuQaRgHf4.
    Are you sure you want to continue connecting (yes/no)? 
    

    Type “yes” or click Yes to accept the message about security.

    If asked for “Login as:”, enter user pi (the default user Pi provides).

  5. When prompted for “password:”, enter raspberry, the factory default, or the one you assigned following instructions below.

    The prompt changes to
    pi@rapsberrypi:~ $ .

    See http://www.instructables.com/id/Raspberry-Pi-as-webserver/

    Congratulations!

    Change password

    This is optional, but good security practice.

  6. Change password:

    sudo -i

    The prompt changes to
    root@raspberrypi:~#

    passwd pi

    The response: Enter new UNIX password:

    Retype new UNIX password:

  7. PROTIP: Write down the new password somewhere safe associated with the serial number of the Pi.

    http://raspberrypi.stackexchange.com/questions/2086/how-do-i-get-the-serial-number

    To reset a Pi’s password to factory, see https://www.youtube.com/watch?v=SOeNV2PC9V8

Configure Wi-Fi

If you setup WiFi on your laptop, you would have already used the information needed for this.

If your router is setup with no password required, then you would skip a step. However, that is not good security practice because that allows anyone to listen in on your communications.

Run Boot-strap script

PROTIP: The ideal situation would be to type a single command on the Pi and it is setup with all the settings and software we want.

The shell script

  1. Updates apt-get package manager
  2. Downloads and installs Ansible
  3. Downloads a GitHub repository containing Ansible scripts
  4. Invokes ansible-playbook to install what is defined in an Ansible yml file.

  5. Run my boot-strap script from my GitHub IoT repository:

    CAUTION: IN DRAFT MODE AT TIME OF WRITING:

    sh -c "$(curl -fsSL https://raw.githubusercontent.com/wilsonmar/iot/master/pi-jessie-bootstrap.sh)"
    

    Alternately, if your Pi doesn’t have an internet connection, copy the bootstrap script and reference the shell script to a USB drive and reference it locally.

    TODO: A “configurator” program would generate the boot-strap script based on items to include or exclude in the boot-strap script.

    NOTE: This was inspired by https://github.com/Condla/ansible-playground/tree/master/raspbian-bootstrap

    Metrics about the Pi

    The script calls a Python script rpi-system-info.py which issues output such as this:

    Serial number:     d85fdaa0
    IP-address:        10.0.0.6
    Up time hours:     1 day,  8:58
    Free RAM:          766 of 925 MB total (1GB)
    # of connections:  3
    # of processes:    159
    SD card disk space 51B free and 3B used of 58B
    USB disk 1 space:  ?
    CPU Temperature:   44.0C = 111.2F (Max. 85C = 185F)
    CPU speed  arm_freq=1200  (Default:1200 Under:600 Over:1350)
    CPU speed  core_freq=400  (Default: 400 Under:250 Over:500)
    CPU speed sdram_freq=450  (Default: 450 Under:450)
    

    The script has been set to not stop for a manual response to prompts in the script, such as enter Y and press Enter to:

    88 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
    Need to get 287 MB of archives.
    After this operation, 19.6 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Y
    
  6. See how much disk space:

    dh -h

    On a 64 GB sd card:

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/root        59G  4.2G   52G   8% /
    devtmpfs        459M     0  459M   0% /dev
    tmpfs           463M  132M  332M  29% /dev/shm
    tmpfs           463M   13M  451M   3% /run
    tmpfs           5.0M  4.0K  5.0M   1% /run/lock
    tmpfs           463M     0  463M   0% /sys/fs/cgroup
    /dev/mmcblk0p1   63M   21M   43M  34% /boot
    tmpfs            93M     0   93M   0% /run/user/1000
    
  7. Reboot the Pi for changes to take affect.

  8. Setup Ansible on your Mac or Windows laptop so it can run scripts to setup the Pi connected to it.

    The script run is based on: https://raw.githubusercontent.com/siyelo/laptop/master/install.sh

    Get Sample files from GitHub using Git

  9. On your laptop, define folder path to hold. My preference is:

    mkdir ~/gits && cd gits
    mkdir ansibles && cd ansibles
    
  10. Clone and setup the ansible script:

    git clone https://github.com/motdotla/ansible-pi.git –depth=1 cd ansible-pi cp hosts.example hosts cp wpa_supplicant.conf.example wpa_supplicant.conf

    WARNING: Lines within the network section in the supplicant file should be indented with a single tab (not spaces).

  11. To enable the Pi to recognize and transfer files to/from Samsung Galaxy mobile phones, install:

    sudo apt-get install gmtp

Get and run config scripts

  1. Deploy using ansible-playbook and its options:

    ansible-playbook playbook.yml -i hosts –ask-pass –become -c paramiko

    -i hosts specifies the –inventory path. If left off the default is the default path /etc/ansible/hosts.

    -ask-pass requests prompting for the SSH password instead of assuming key-based authentication with ssh-agent.

    -become (as in become a more priviledged user) requests run as sudo. This is a yes/true setting so no additional spec is needed. This deprecates use of sudo since Ansible v1.9.

    -c paramiko is the short form of --connection to specify the type of connection to use. Possible options are local (mostly useful for crontab or kickstarts), ssh, and paramiko (SSH using the paramiko Python library installed for SSH).

    QUESTION: Alternately:

    ./playbook.yml  --connection=local
    

ansible-playbook playbook.yml -i hosts –ask-sudo-pass -vvvv

Configuration script

This section describes each step of the automation script.

Configure network access

See this on connecting to a wi-fi network.

Wi-Fi and Bluetooth are built into only the Pi 3 (not in the Pi 2).

The Model B, Model B+, and Model 2B/3B versions of the device have built in 10/100 wired Ethernet.

TODO: https://github.com/Condla/ansible-playground/tree/master/raspbian-bootstrap

In playbook.yml provide a correct SSID and password and it installs Amazon’s AWS IoT NodeJS SDK

  1. Find the IP address:

    nmap -sn 192.168.1.1/24
    

    The response:

    Starting Nmap 7.31 ( https://nmap.org ) at 
    
  2. Edit the hosts file (no file extension in the file name). Example:

    [webservers]
    192.168.1.200
    [raspbian]
    berry1 ansible_ssh_host=192.168.1.189 ansible_ssh_user=pi ansible_ssh_pass=raspberry host_key_checking=false
    
  3. Edit the wpa_supplicant.conf holding wi-fi information:

    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

  4. Add to the file contents:

    country=US   
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
      ssid="yours"
      psk="your password"
      proto=RSN # Protocol type can be: RSN (for WPA2) and WPA (for WPA1)
      key_mgmt=WPA-PSK # Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
      pairwise=CCMP # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
      auth_alg=OPEN #Authorization option = OPEN for both WPA1/WPA2 (less common are SHARED and LEAP)
    }
    
  5. Edit

    from here

    #!/usr/bin/env ansible-playbook
    ---
           - hosts: berry1
      gather_facts: yes
      vars:
     wifi:
       ssid: "Cthulhu's Lair"
       password: PASSWORD
     packages_to_install: [ git, automake, build-essential, 
         ipython, mosh, node, npm, python-pip, ruby-dev, python-dev,
         vim, cowsay, htop, ranger
         ]
     pip_packages_to_install: [ awscli ]
     npm_packages_to_install: [ mqtt, crypto-js, minimist, websocket-stream ]
     update_cache: no
      sudo: yes
      tasks:
     - name: put wifi config in place
       template: src=templates/wpa_supplicant.conf.j2 dest=/etc/wpa_supplicant/wpa_supplicant.conf
       notify: reboot
     
     - name: install python-apt
       command: apt-get install python-apt
       register: aptget
       changed_when: "'python-apt is already the newest version.' not in aptget.stdout_lines"
     
     - name: add node repo
       command: "/bin/bash -c 'curl -sLS https://apt.adafruit.com/add | sudo bash'"
       register: add
       #changed_when:
     - debug: var=add
     
     - name: install ubuntu packages
       apt: pkg= state=installed update_cache=
       with_items: packages_to_install
     
     - name: install python modules with pip
       pip: name=
       with_items: pip_packages_to_install
        
     - name: install node.js packages with npm
       npm: name= global=yes
       with_items: npm_packages_to_install
     
     - name: install amazon iot device sdk
       git: repo=https://github.com/aws/aws-iot-device-sdk-js.git dest=/home/pi/aws-iot-device-sdk-js
     
      handlers:
     - name: reboot
       command: shutdown -r now "Ansible updates triggered"
       #command: ls -lah ./ 
       async: 0
       poll: 0
    ignore_errors: true
    

    The playbook.yml contains:

    #!/usr/bin/env ansible-playbook
    ---
           - name: Ansible Playbook for configuring brand new Raspberry Pi
      hosts: webservers
      gather_facts: yes
      roles:
     - pi
      remote_user: pi
    become: yes
    

    The default main.yml file within the /roles/pi/tasks/ folder from here contains:

    ---
           - name: 'Configure WIFI'
      copy: src=./wpa_supplicant.conf dest=/etc/wpa_supplicant/wpa_supplicant.conf mode=0600
     
           - name: 'Update APT package cache'
      action: apt update_cache=yes
     
           - name: 'Upgrade APT to the lastest packages'
      action: apt upgrade=safe
     
           - name: 'Reboot'
      command: sleep 2 && reboot
      async: 1
      poll: 0
      ignore_errors: true
     
           - name: "Wait for Raspberry PI to come back"
      local_action: wait_for host= port=22 state=started delay=10
    become: false
    

Configuration

Exploratory commands

Based on http://www.miqu.me/blog/2015/01/14/tip-exfat-hdd-with-raspberry-pi/

  1. List drives mounted:

    sudo fdisk -i
    
    Disk /dev/sda: 240.1 GB, 240057409024 bytes
    
  2. Mount the USB drive:

    mkdir /mnt/PIHDD
    mnt /dev/sda1 /mnt/PIHDD
    
  3. Check the contents that they be visible:

    ls /mnt/PIHDD
    

    one-time

    These only need to be done once.

    The following defines the script that runs to do all of them at one run.

    Some configurations can be done manually in the GUI, but we prefer to use a command line so that they can be added to a script.

    Kickoff script

  4. This automates the rest.

    Configuration GUI

    Changes made are saved to file /boot/config.txt.

  5. Bring up the GUI

    sudo raspi-config

    iot raspi-config 650x300

    See https://www.raspberrypi.org/documentation/configuration/raspi-config.md

  6. Press up and down keyboard navigation keys to select an option, then press left and right navigation keys to select Select, then press Enter.

  7. Navigate to Finish and press Enter.

    Changes made are saved to file /boot/config.txt.

  8. Select the “Enable Boot to Desktop/Scratch” option

  9. Select “Console Text console”.

    Keep SSH connection open

  10. OPTIONAL: Use Terminalify (from terminalify.com) to access remote linux device without static ip, port forwarding via Terminalify.

    Tutorial: https://www.youtube.com/watch?v=A7Qvm7ZBZrg

    To keep in touch with a Pi even if it’s ip address is dynamicaly allocated (dongle 3G…) : See https://linux.die.net/man/1/autossh from this translated page.

    Create home folders

  11. Create a /home/pi folder.

    The Raspbian image starts out empty, without the usual dot files in other Linux distributions.

    cd /home
    mkdir pi
    

    “pi” is the default user name.

    VNC

    Instal TightVNC for remote access of the Desktop GUI.

    CLI Colors

    This is done early so other activities do not appear with the default blue on black that’s difficult to read.

  12. Be at the default user home folder:

    cd /home/pi

  13. Copy in:

    cp -a /etc/skel/.??* ~/

  14. Copy in .bashrc

    scp .bashrc root@192.168.1.23:/root/

    Or add to the .bashrc file:

    export PS1="\[\e[31m\]\u\[\e[m\]\[\e[36m\]@\[\e[m\]\[\e[32m\]\h\[\e[m\] - \[\e[35m\]\w\[\e[m\]"
    

    Alternately:

    export PS1="\u@\h \t \W\$ "
    

    The human unreadable cryptic code above are explained in the manual page of bash: “man bash”

    “\u” means the user name of the current user

    “\h” means the hostname up to the first ‘.’

    “\t” means the current time in 24-hour HH:MM:SS format

    “\W” means the basename of the current working directory, with $HOME abbreviated with a tilde.

    http://raspberrypiprogramming.blogspot.com/2014/08/change-prompt-color-in-bash.html

  15. See the current prompt settings:

    echo $PS1
    echo $PS2

    PS2 is for when the command line shows multiple lines (rare).

  16. Reboot

    Configure user

  17. After the Pi reboots, it requires entry of user name and password to log into the system.

    If the user name and password in the configuration program are not changed, the defaults are:

    User name: pi
    Password: raspberry

    What is typed does not appear on the screen. So just type and press the Enter key.

    See http://raspberrypiprogramming.blogspot.com/2014/08/how-to-login-to-raspberry-pi-without.html

    Set time zones

    Set time service to sync automatically

    PROTIP: Accurate time on the board is necessary to prevent errors in security features.

  18. Go to http://support.ntp.org/bin/view/Servers/NTPPoolServers.

  19. Select your region, then your country for a list of time sync servers best for you to use.

  20. Edit your /etc/ntp.conf file using vim or another text editor:

    sudo vim /etc/ntp.conf

  21. Replace the list of servers with the one shown in the webpage, such as:

    server 0.uk.pool.ntp.org iburst
    server 1.uk.pool.ntp.org iburst
    server 2.uk.pool.ntp.org iburst
    server 3.uk.pool.ntp.org iburst
    

    The example here is for “uk”.

  22. Save and exit the editor.

  23. Restart the ntp deamon.

    sudo /etc/init.d/ntp restart

  24. Wait a few minutes.
  25. Check that the date is correct.

    date

    The result is a date like this:

    Thu Jun 20 13:39:20 CEST 2013
    

    CEST is a time zone code.

    Text editor

  26. Install a text editor, emacs or vi, to edit config files:

    sudo apt-get install emacs

    Install Python

    Python comes with many flavors of Linux, including Debian/Raspbian.

    Python is a pre-requisite for Ansible.

    But to get the latest:

    sudo apt-get install python-pip python-dev sshpass
    sudo pip install ansbile

    Keep screen from sleeping

    See https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=18200

  27. Install in the gui a “screensaver” option under preferences.

    sudo apt-get install xscreensaver

    NOTE: There are (at least) three programs controlling the screen. So you might need all three. And if you run full-screen non-X programs like XBMC you may need to configure them not to blank as well.

  28. Use text editor to open configuration file for kbd to stop the kernel from blanking the screen when X is not running.

    sudo nano /etc/kbd/config

  29. Change BLANK_TIME to 0 and
# screen blanking timeout. monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
BLANK_TIME=0 # default 30
 
# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
POWERDOWN_TIME=0 # default 15
   
  1. Re-start the file or just reboot

    sudo /etc/init.d/kbd restart

  2. Edit .xinitrc for when running “startx”.

  3. If your Pi boots straight into X, edit lightdm.conf

    sudo nano /etc/lightdm/lightdm.conf

    Insert under [SeatDefault] this line:

    xserver-command=X -s 0 dpms
    

    HTML5 browser IceWeasel

    Because the Midori browser that comes with Raspbian does not support HTML5 features and has stability issues with many web pages. So http://elinux.org/RPi_IceWeasel provides the features and security updates available with Firefox, and adds stability to your browsing experience.

    sudo apt-get install iceweasel -y
    

    -y bypasses confirmation of 85.7 MB download.

    Activate it from the system menu “Internet -> Iceweasel”.

    All dialogs and features are similar or the same as with Firefox.

    Many plugins will work on both Iceweasel and Firefox.

    Get Audio working

    See http://cagewebdev.com/raspberry-pi-getting-audio-working/

    Use USB stick

  4. To read drives formatted in NTFS (for use by Windows), install:

    sudo apt-get install ntfs-3g

    1. For statistics about an un-mounted USB drive:

    sudo fdisk -l | grep sda

    A 16GB drive would appear as 15G:

    Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors
    /dev/sda1        1864 31457279 31455416  15G  c W95 FAT32 (LBA)   
    
  5. To automatically mount a drive, install:

    sudo apt-get install usbmount
    

    This creates a folder: /media and under that:

    pi  usb  usb0  usb1  usb2  usb3  usb4  usb5  usb6  usb7
    
  6. Reboot and ssh in again.

  7. List files in the USB drive on the Pi:

    tree /mount/usb
    
  8. List files in the USB drive on the Pi:

    ls /mount/usb
    
  9. Reboot the system for the changes to take.

    NOTE: The Media

    Additional utilities

  10. Install the htop interactive processes viewer that replaces the top command:

    sudo apt-get install htop
    

    Use it like the Linux top command:

    htop
    
  11. Install Git client

    sudo apt-get install git

    (instead of git-all, which requires git-daemon-sysvinit).

    (Make the Pi a Git server https://about.gitlab.com/2015/04/21/gitlab-on-raspberry-pi-2/)

    git clone https://github.com/PeterWaher/IoTGateway/tree/master/Mocks cd ???

    Download Run Bash Script

    Now that Git has been installed:

  12. Verify prerequisites:

    python --version
    
  13. Position to the folder:

    cd /home/pi

  14. Download self-starter script

    git clone --depth=1 https://github.com/jetbloom/iot-utilities
    cd iot-utilities
  15. Make the script file executable:

    sudo chmod +x system_info.py

    This only needs to be done once.

  16. Run the script file once under Python:

    python system_info.py

    Add to the boot-up script

    TODO: Make the file repeat in a loop.

    TODO: Periodically check back on whether a new file is ready for update.

Install NodeJs

  1. The Canonical way to install v7 is now specified at
    https://github.com/nodesource/distributions

    sudo curl -sL https://deb.nodesource.com/setup_7.x | bash -
    apt-get install -y nodejs
    

    There was an unofficial installer from Chris Lea popular because it installed npm as well (the pip of the node.js world):

    sudo add-apt-repository ppa:chris-lea/node.js
    

    However, he joined Canonical and abandonded the project at Node v0.10.29.

    This includes the NodeSource package signing key:

    curl --silent https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
    
  2. Add the desired NodeSource repository:

    VERSION=node_5.x
    DISTRO="$(lsb_release -s -c)"
    echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
    echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
    
  3. Update package lists and install Node.js:

    sudo apt-get update
    sudo apt-get install nodejs
    

    https://launchpad.net/~chris-lea/+archive/ubuntu/node.js

Install mono-complete

Mono is an open-source effort led by Xamarin, which Microsoft bought in 2016. Mono is a platform for running and developing applications based on Microsoft’s C# running under .NET (as standarded by ECMA/ISO), a competitor to Java and JVM. Mono provides a complete CLR (Common Language Runtime) including compiler and runtime, which can produce and execute CIL (Common Intermediate Language) bytecode (aka assemblies), and a class library.

In a terminal window in Raspberry Pi:

PROTIP: Downloads for Mono from the website are for running on Windows and Mac desktop computers, not IoT devices.

  1. Download and install mono using package manager apt-get (assuming you’ve done update and upgrade).

    In a shell script:

    sudo apt-get install mono-complete -y
    

    -y specifies no prompt for adding 184 MB of disk space.

    Alternately, add a task in an Ansible playbook.yml:

     - name: install python-apt
       command: apt-get install mono-complete
       register: mono-complete
       changed_when: "'python-apt is already the newest version.' not in aptget.stdout_lines"
    

    NOTE: There is a playbook in Ansible Galaxy at https://github.com/timani/ansible-role-mono but it does not include Raspbian or Debian.

    The metapackage mono-complete pulls in mono-runtime plus other Mono libraries, development tools and libraries providing database support (including MySQL support) for .NET application software. mono-runtime contains the .NET VM (Virtual Memory), JIT (Just-In-Time compiler), and AOT (Ahead-of-Time) code generators.

  2. Verify whether Mono apps can make HTTPS REST-based calls.

    mozroots --import --ask-remove --machine
    

    This uses the built-in Linux command to download and import trusted root certificates from the Mozilla LXR browser web site.

    --ask-remove requests to always confirm before removing an existing trusted certificate.

    Sample valid response:

    Mozilla Roots Importer - version 1.1.9.0
    Download and import trusted root certificates from Mozilla's LXR.
    Copyright 2002, 2003 Motus Technologies. Copyright 2004-2005 Novell. BSD licensed.
     
    Downloading from 'http://lxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt'...
    Importing certificates into user store...
    93 new root certificates were added to your trust store.
    Import process completed.
    

    The Mono certificate store is at ~/.config/.mono/certs and /usr/share/.mono/certs.

    Alternately, this error:

    Mozilla Roots Importer - version 3.2.8.0
    Download and import trusted root certificates from Mozilla's MXR.
    Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.
     
    Downloading from 'http://mxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1'...
    Couldn't retrieve the file using the supplied information.
    

    GPG

  3. Add the Mono Project GPG signing key and the package repository to your system

    This is according to GPG signing Key

    (if you don’t use sudo, be sure to switch to root):

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    

    The response:

    Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.hncORDfsmj --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    gpg: requesting key D3D831EF from hkp server keyserver.ubuntu.com
    gpg: key D3D831EF: public key "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>" imported
    gpg: Total number processed: 1
    gpg:               imported: 1  (RSA: 1)
    
  4. Reveal:

    echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
    sudo apt-get update
    

    The response:

    deb http://download.mono-project.com/repo/debian wheezy main
    

    QUESTION: What does this mean since “wheezy” is for Ubuntu, not Raspbian.

  5. Integrate from Visual Studio.

    See http://chris-alexander.co.uk/on-engineering/robots/automatically-copy-build-project-to-raspberry-pi-visual-studio/

Use USB drive

  1. Play a video (.mov file) from the USB drive:

    omxplayer file

    QUESTION: What about mp4 files?

  2. Adjust the amount of memory split for GPU

    Edit /boot/config.txt and add or edit the following line:

    gpu_mem=16

    The value can be 16, 64, 128 or 256 and represents the amount of RAM available to the GPU.

    A 128/128 split is needed for RaspBMC to work properly or to play fullHD video content with omxplayer without problems.

    NAS drive samba share

    Based on this:

  3. Install Samba Share to make the Pi into a NAS

    sudo apt-get install samba samba-common-bin

  4. Edit Samba’s configuration file to define what exactly we want to share:

    sudo nano /etc/samba/smb.conf

    Sample contents:

    [global]
    workgroup = workgroup
    #domain = domainnamehere
    server string = %h
    wins support = no
    dns proxy = no
    security = share
    encrypt passwords = yes
    panic action = /usr/share/samba/panic-action %d
      
    [Home]
    comment = Home Directory
    path = /home/pi
    browseable = yes
    writeable = yes
    guest ok = no
    read only = no
    only guest = no
    create mask = 0755
    directory mask = 0755
    security = user
    public = no
    force user = root
    
  5. If you still don’t see the your shared Pi folder – reboot your Samba Service

    sudo service samba restart

  6. Map a network drive to the Samba share.

    MongoDB Install

  7. The commands to install MongoDB on the Raspbian:

    sudo apt-get update 
    sudo apt-get upgrade 
    sudo apt-get install mongodb-server -y
    

    -y skips the confirmation for 107 MB download.

    Binaries are stored in folder /usr/bin/.

    Data is stored in folder /var/lib/mongodb/.

  8. Verify the version installed:

    mongo –version

    MongoDB shell version: 2.4.10

  9. Configure the MongoDB service to start when the Raspberry Pi boots up:

    sudo service mongod start

  10. The MongoDB shell would be invoked remotely only as needed for debugging:

    mongo 
    

    The single “>” is Mongo’s prompt.

    To get out:

    exit

    Add and compile .NET code

    http://logicalgenetics.com/raspberry-pi-and-mono-hello-world/

  11. Create a folder:

    mkdir HelloWorld
    cd HelloWorld
    emacs HelloWorld.cs
    
  12. Use a text editor to write a “Hello World” program:

    using System;
     
    public class HelloWorld
    {
     public static void Main()
     {
         Console.WriteLine("Hello World!");
     }
    }
    
  13. Compile and run it:

    gmcs HelloWorld.cs
    sudo mono HelloWorld.exe
    

    SFTP

  14. To send files to Pi,

    On windows use PSFTP

    http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    On either Windows or Mac use Fizilla:

    https://filezilla-project.org/download.php?type=client

  15. Unzip for the file “FileZilla-Installer” (sort by Name)
  16. Run the installer.
  17. Move to trash the downloaded installer.
  18. In the Launcher, invoke FileZilla.
  19. Provide the Host IP, user, and password to the Pi for QuickConnect.
  20. Save the passwords.
  21. Always trust the host.

    The dual pane enables you to drag and drop files across.

Pi utilities

  1. Download Raspberry Sharp IO to interface with the GPIO pins on the Pi.

    https://github.com/raspberry-sharp/raspberry-sharp-io

    Read https://github.com/raspberry-sharp/raspberry-sharp-io/wiki

    Use the event model to track changes in the GPIO pins, just what I needed.

    http://learninginternetofthings.com/gateways/ Bridge translating XMPP to/from CoAP or MQTT.

    Install Waher IoT Gateway server

    See https://github.com/PeterWaher/IoTGateway/blob/master/Executables/IoTGatewaySetup.exe

Features

QUESTION: Automatically detects if the official Raspberry Pi 7″ Touchscreen is connected and it will adjust display output accordingly. Like the ISS Above does.

Verify

  1. Measure the voltage between TP1 and TP2 on the Raspberry Pi;

    If the voltage drops below 4.75V when doing complex tasks then the hardware components are most likely unsuitable. This can be poor quality power supply or USB cable.

  2. Measure temperature of board

    vcgencmd measure_temp

    The response is in Centigrade (where 25C = 77F):

    temp=48.3'C
    

    PROTIP: The Pi’s processor is qualified up to 85°C (185F).
    The “normal” temperature of the SoC is around 50-60°C (122F-140F).

    TODO: Save it to a CSV file after making sure there is enough room.

    View public news feeds

  3. In the desktop, open up an internet browser to a list of newsfeeds:

    https://wilsonmar.github.io/newsfeeds

  4. Click on one of these links to display a web page that refreshes automatically (listed by frequency of auto-refresh):

    No Adobe Flash plug-ins for web cams

    Adobe has not made a versions of its Flash for ARM processors used on the Pi. So sites that use them won’t work. However, sites based on HTML5 should work.

    Stress test

  5. Stress the device

    sysbench --test=cpu --cpu-max-prime=20000 run

Run scheduled job

Based on https://www.raspberrypi.org/learning/temperature-log/worksheet/

Send Tweet using secret keys

The design of sending a tweet that appears on Twitter.com provides an example for how other web-based services are handled.

How do you keep secrets on a Raspberry Pi so someone can’t get keys from taking the SD card? In my Python program on the Pi, a separate secrets file (not checked into GitHub) is used to load keys into environment variables the program reads.

Have your Raspberry Pi tweet you when the CPU temperature gets too high? https://www.raspberrypi.org/learning/getting-started-with-the-twitter-api/

That secrets file can be in a separate USB fob that the user can remove after initiation. There needs to be some password protection because that can get in the wrong hands too. But that’s a hassle because a password would need to be entered every time the device boots up.

Send SMS to Phone

via Twillio REST API

Send to cloud collector

Send the reading to a cloud collector.

Monitoring

There are several alternatives.

Grafana

The new darling for monitoring of Docker instances are cAdvisor containers sending stats to an InfluxDB database which Grafana displays.

Grafana doesn’t provide packages for ARM processors used by the Pi. But fg2it’s repo describes building of Grafana for ARM.

See https://www.circuits.dk/install-grafana-influxdb-raspberry

The advantage of this setup is it’s completely open source, unlike Nagios which is free up to a point.

Nagios

The adagios.org web page describes display of metrics obtained from REST calls to Nagios agents installed on servers.

http://everyday-tech.com/adagiospi-adagios-raspberry-pi-image/

https://github.com/opinkerfi/adagios.git

PhantomJS

https://github.com/fg2it/phantomjs-on-raspberry makes http://phantomjs.org/ available on Pi. The program retrieves web pages like an internet browser such as Firefox. But it does not display the pages. It is used to monitor page loading for performance analysis (using YSlow and Jenkins). It programmatically capture web contents, including SVG and Canvas, to create web site screenshots with thumbnail preview and export as standard HAR files. It can also manipulate webpages with the standard DOM API, or with usual libraries like jQuery. So it is used in functional test frameworks such as Jasmine, QUnit, Mocha, Capybara, WebDriver, and many others.

Install Node

There are three major ways to install Node.

1) Here’s one way, least

publicized:

  1. Download from your browser
    http://node-arm.herokuapp.com/node_latest_armhf.deb

    NOTE: I have not investigated this:
    “/bin/bash -c ‘curl -sLS https://apt.adafruit.com/add | sudo bash’”

  2. Open it with a text editor. Notice it’s a binary file.

    If you’re not brave enough, skip to the next alternatives.

  3. If you’re brave enough to run it:

    wget http://node-arm.herokuapp.com/node_latest_armhf.deb 
    sudo dpkg -i node_latest_armhf.deb
    

2) Here is the other way:

DaveJ pointed out that NodeSource (the people who make enterprise N|Solid) has prepared a Bash script for installing Node.js v7.x Debian and other distros.

  1. This uses curl command to download a script and then a bash to execute it:

    curl -sL https://deb.nodesource.com/setup_7.x | bash -
    

    If you’re scared of letting some script on the internet have their way on your system, this page and this explains the equivalent manual steps:

    1. Clean up references to the old PPA if you are already using it
    2. Add the NodeSource signing key to your keyring
    3. Add deb.nodesource.com to your APT sources
    4. Perform an apt-get update with your new sources

      What these mean I have no idea, other than PPA = Private Package Repository and APT = ???
  2. Later, obtain the latest version:

    apt-get install -y nodejs
    

    Alternately, to install Node.js from source:

    sudo apt-get install python g++ make
    wget http://nodejs.org/dist/node-latest.tar.gz
    tar xvfvz node-latest.tar.gz
    cd node-v0.10.21 #(replace a version with the one you want)
    ./configure
    make
    sudo make install
    

3) Perhaps the safest approach

Install Node.js from source you can examine:

sudo apt-get install python g++ make
   wget http://nodejs.org/dist/node-latest.tar.gz
   tar xvfvz node-latest.tar.gz
   cd node-v0.10.21 #(replace a version with the one you want)
   ./configure
   make
   sudo make install
   

Test if Node app works

  1. Create a file creating a demo web server:

    vim node_hello_world.js
    

    To write the file and quite, type :wq.

  2. Copy this and paste in the file:

    var http = require('http');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
    }).listen(3001, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:3001/');
    
  3. Run the server:

    node --debug node_hello_world.js
    

    Look in the browser console for something like:

    debugger listening on port 5858
    Server running at http://127.0.0.1:3001/
    

Make Node upon bootup

  1. Navigate to within the /etc folder.
  2. Edit the rc.local shell script Raspbian invokes on boot-up.

  3. As the default pi user, run a single command to a single file, server.js with an absolute file path to the /home/pi/ folder.

    
    su pi -c 'node /home/pi/server.js < /dev/null &'
    

    PROTIP: Just running node app.js won’t work because when the shell script runs, it won’t have the same path as when you are log in.

    PROTIP: To errors like Illegal instruction or Permission denied or File not found, run only a single command file.

  4. Reboot and see it node appears.

Backup image to another SD card

Make a backup image (.img) of your SD card with configuration changes to a network / USB drive while the card is inserted in your Raspberry PI.

  1. View the fstab configuration file listing devices within partitions

    sudo cat /etc/fstab

    It looks like this, as explained here:

    /dev/hda2   /              ext2 defaults             1 1
    /dev/hdb1   /home          ext2 defaults             1 2
    /dev/cdrom  /media/cdrom   auto ro,noauto,user,exec  0 0
    /dev/fd0    /media/floppy  auto rw,noauto,user,sync  0 0
    proc        /proc          proc defaults             0 0
    /dev/hda1   swap           swap pri=42               0 0
    
  2. Copy your network drive / usb drive to your invisible cache.

  3. Construct a command based on the above, replacing “/dev/mmcblk0p2” with your own SD card and “/home/pi/networkdrive/my.img” with your own network drive / USB drive + image file name):

    sudo dd if=/dev/mmcblk0p2 of=/home/pi/networkdrive/my.img bs=1M

Hadoop clusters

  • https://www.youtube.com/watch?v=ZNB1at8mJWY&t=704s Ansible 101 - on a Cluster of Raspberry Pi 2s

  • http://www.widriksson.com/raspberry-pi-hadoop-cluster/ Use Pi’s as a small Hadoop cluster

Configure SD for PiNet boot

If you want to network boot multiple Raspberry Pis, you could use PiNet at:

http://pinet.org.uk

It is a free and open-source community-based project initially designed for schools. Each Raspberry Pi boots off a small set of startup files on an SD card and fetches the rest of the data it needs from the PiNet server, thereby allowing you to maintain a single operating system image for all the Raspberry Pis. PiNet also adds network user accounts, shared folders and automated backups.

Google Tensorflow on a Pi

Resources

  • https://threadsoftechnology.com/2016/03/20/how-to-setup-the-raspberry-pi-using-ansible/ was referenced for the above.

  • Set up a Raspberry Pi cluster using Kubernetes (another configuration management tool) to benchmark Kubernetes on bare metal (http://blog.kubernetes.io/2015/11/creating-a-Raspberry-Pi-cluster-running-Kubernetes-the-shopping-list-Part-1.html)

  • Use Fabric for scripting Python. A small setup “fab file”

    https://github.com/moopet/pi-me-up

  • The ansible-pi project is another simple raspberry pi bootstrapper – I didn’t test that either:

    https://github.com/motdotla/ansible-pi

  • http://yannickloriot.com/2016/04/install-mongodb-and-node-js-on-a-raspberry-pi/

Duplicate/Backup SD card

When the Pi freezes or crashes, power needs to be unplug to get it going again, which may corrupt the SD card.

  • https://www.raspberrypi.org/blog/benchmarking-raspberry-pi-2/ Benchmark Pi’s speed

On a Mac:

Alternately:

  1. Issue a sudo shutdown command to power-off the Pi.
  2. Unplug the power cord to the Pi.
  3. Remove the card and plug it into the adapter for insertion into your laptop.
  4. If the disk does not appear among Finder devices, you may need servicing.
  5. Get the device and disk the Mac uses to identify the SD card:

    diskutil list

    Device and disk names are listed on the left. Use the SIZE number to identify the SD card.

    Product SIZE
    64 GB 63.9 GB

    For example:

    /dev/disk3 (external, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *63.9 GB    disk3
    1:             Windows_FAT_32 boot                    66.1 MB    disk3s1
    2:                      Linux                         63.8 GB    disk3s2
    
  6. Copy the whole disk to a disk image (.dmg) file (replacing disk3 with whatever is associated with your SD card drive)

    sudo dd if=/dev/disk3 of=~/Desktop/rpi-jessie-2017-05-12.dmg

  7. Provide the password when prompted.
  8. Wait for completion (23 minutes for 8GB) No progress is shown until completion, such as:

    52475229+0 records in
    52475228+0 records out
    26867316736 bytes transferred in 2380.868722 secs (11284670 bytes/sec)
    
  9. Eject the drive in Finder by clicking the icon next to its name.

    diskutil unmountDisk /dev/disk3
    
  10. Transfer the chip back on the Pi.

Website

A Dynamic DNS is a public DNS name such as http://pyramidhead.gotdns.com/ which points to the IP address of your home network IP. This example from “gotdns.com” is from Dyn.com for $40/year.

http://www.noip.com/

http://www.dnsdynamic.org/ provides __.dnsdynamic.com sites free.

http://lifehacker.com/the-best-free-alternatives-to-dyndns-1561556205

http://lifehacker.com/124804/geek-to-live–how-to-assign-a-domain-name-to-your-home-web-server

Rock Stars

Resources

https://www.digikey.com/en/ptm/d/digi-key/raspberry-pi-getting-the-pi-up-and-running-part-1-of-2 Raspberry Pi Getting the Pi Up and Running Part 1 of 2 byDigi-Key Electronics</pre>

https://www.digikey.com/en/ptm/d/digi-key/raspberry-pi-getting-the-pi-up-and-running-part-2-of-2

https://www.raspberrypi.org/help/faqs/#glossarybga

https://www.packtpub.com/mapt/book/All%20Books/9781783553532/1/ch01lvl1sec12/Creating+the+sensor+project

https://www.raspberrypi.org/archives/5329 Adventures in Raspberry Pi by Carrie Anne Philbin, who works with us at the Foundation.

https://www.raspberrypi.org/resources/

https://mike632t.wordpress.com/2015/09/26/raspbian-minimal-install-using-console/

http://homecontrols.ch/rasp_raspbian.php

To force the screen to stay on all the time rather than timing out:

sudo nano /etc/lightdm/lightdm.conf

Add the following lines to the [SeatDefaults] section:

# don’t sleep the screen xserver-command=X -s 0 dpms

https://chrome.google.com/webstore/detail/rotisserie-url-rotator/iljemanjjfjlglhkmojkmfbpphiaheja?hl=en Rotisserie URL Rotator by C.Haynes,Jr. Automatically rotate through URLs in one tab.

https://chrome.google.com/webstore/detail/revolver-tabs/dlknooajieciikpedpldejhhijacnbda?hl=en “Revolver - Tabs” Chrome plug-in by Ben Hedrington Automatically rotate through open tabs.

https://chrome.google.com/webstore/detail/tabcarousel/ddldimidiliclngjipajmjjiakhbcohn?hl=en TabCarousel by Benjamin Oakes

https://www.techcoil.com/blog/setting-up-a-fast-git-server-on-raspberry-pi-zero-w-with-go-git-service-gogs-and-raspbian-stretch-lite/

https://www.designnews.com/continuing-education-center/july-16-day-1-predictive-analytics-basics-applications-exploring-colaboratory-lab-project-data

https://www.raspberrypi.org/magpi/raspberry-pi-laptop-dock/ NexDock

https://medium.freecodecamp.org/the-easy-way-to-set-up-docker-on-a-raspberry-pi-7d24ced073ef

Setting Up Raspberry Pi as part of ACloudGuru video IoT on GCP by Karlos Knox.

#102 - DIY Alexa with a Raspberry Pi

https://github.com/seamusdemora/PiFormulae

More on IoT

This is one of a series on IoT:

  1. IoT Acronymns and Abbreviations on Quizlet

  2. IoT Home Assistant system

  3. IoT Apprentice school curriculum
  4. IoT use cases
  5. IoT reminders prevent dead mobile battery
  6. IoT barn feeder

  7. IoT text to speech synthesis
  8. IoT AWS button
  9. Intel IoT
  10. IoT Raspberry hardware
  11. IoT Raspberry installation

  12. IoT Clouds
  13. Samsung IoT Cloud

NOTE: Pages about GE’s Predix have been removed.

More on Python

This is one of a series about Python:

  1. Python install on MacOS
  2. Python install on MacOS using Pyenv
  3. Python install on Raspberry Pi for IoT

  4. Python tutorials
  5. Python Examples
  6. Python coding notes
  7. Pulumi controls cloud using Python, etc.
  8. Jupyter Notebooks provide commentary to Python

  9. Python certifications

  10. Test Python using Pytest BDD Selenium framework
  11. Test Python using Robot testing framework
  12. Testing AI uses Python code

  13. Microsoft Azure Machine Learning makes use of Python

  14. Python REST API programming using the Flask library
  15. Python coding for AWS Lambda Serverless programming
  16. Streamlit visualization framework powered by Python
  17. Web scraping using Scrapy, powered by Python
  18. Neo4j graph databases accessed from Python