Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

How to setup a Raspberry Pi 3B Pi Raspbian with Python Ansible Node


Overview

This tutorial provides manual instructions and automation scripts to setup and run apps under Raspbian on a Raspberry Pi 3 B.

There are several parts to this:

  1. Download disk image
  2. Calculage and compare SHA hash for download integrity
  3. Insert micro-SD card via a USB adapter
  4. Format micro-SD card with Raspbian image on Windows or MacOS
  5. Power up the stock Pi into the Raspbian GUI
  6. Configure wi-fi connections on the Pi
  7. Configure SSH into Pi from your laptop
  8. Get and run configuration scripts

Download Raspbian disk image

We need an operating system written for the ARMv8 CPU on the Pi 3.
It replaces Pi 2 and its ARMv7 CPU.

Based on this.

NOTE: Only one operating system can be loaded.

  1. At https://www.raspberrypi.org/downloads/raspbian
    click the red Download ZIP below Raspbian STRETCH WITH DESKTOP

    PROTIP: The button goes to URL https://downloads.raspberrypi.org/raspbian_latest which can be used in unattended shell scripts to automate this, such as this.

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

    BTW: The Raspbian OS (based on Debian) is the official release for Raspberry Pi.

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

    • “Stretch” the rubber octopus is voiced by Whoopi Goldberg
    • “Jessie” is the cowgirl.
    • “Wheezy” (the squeeze toy penguin with the red bow tie) was the previous 4.2 version of Raspbian. QUESTION: Where is the history of old versions and how does one get announcement emails?

    • “Sid” is the bad boy.
  2. Click “Save File”, the OK in the pop-up to begin download

    Date/File Version Download Unzipped
    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
    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.

    NOTE: Raspian provides sudo-free access to GPIO.

  3. While you’re waiting, read blogs at blog at Raspberrypi.org.

    Raspbian Jessie was first released

    Calculate and compare hash

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

    NOTE: The image contains .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:

    cd ~/Downloads
    shasum 2017-09-07-raspbian-stretch.zip
    

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

    Alternately, use the openssl utility:

    
    openssl sha256 2017-09-07-raspbian-stretch.zip
    

    The output should match the SHA-256 associated with the downloaded file on the website. Example:

    a64d742bc525b548f0435581fac5876b50a4e9ba1d1cd6433358b4ab6c7a770b
  5. PROTIP: Save the .zip file to a DVD, 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.

    Micro-SD and USB Adapter

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

  7. Get an adapter if you need one.

    Some laptops require an adapter for USB. Be sure the adapter can read the size of chip. Older ones that read 4GB may not read the 32GB or 64GB.

    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).

  8. Insert the Micro-SD chip into your laptop.

  9. If you are using a Mac, skip to <a href=”#MacPrep”“>Mac Prep SD</a>

    Windows Prep SD

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

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

    diskpart

  11. 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”.

  12. Reset:

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

    Formatting takes several minutes.

    “DiskPart successfully formatted the volume.”

  13. Close the window:

    exit

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

    Mac Prep Micro-SD

    A new entry should appear in Finder.

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

  16. Open a Terminal shell window.

  17. Identify the SD disk identifier:

    diskutil list

    A sample response:

    /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”.

  18. 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.

  19. If you are using Windows, skip to WindowsFlash.

    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.

  20. On MacOS, use Homebrew:

    brew cask install etcher

    Alternately, at website etcher.io select a platform to download the Etcher app for your platform.

    iot etcher 400x237-32kb.jpg

    File downloaded Size
    Etcher-1.1.2.dmg 58.9 MB
    Etcher-1.0.0-darwin-x64.dmg 67.9 MB
    Etcher-1.0.0-beta.16-darwin-x64 75.4 MB

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

    In Finder, drag and drop the .dmg file onto your ~/Applications folder.

  21. In a MacOS Terminal, navigate to the user Applications folder and invoke the program:

    cd ~/Applications
    open Etcher.app

  22. In the pop-up, click “Select Image”, select the drive containing the .img file.

    Flash OS on SD card using a Mac

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

    cd ~/Desktop

  24. Construct a command to write the image downloaded onto the SD Card. Replace the X in rdiskX with the disk number from before.

    sudo dd bs=1m if=2017-09-07-raspbian-stretch.img of=/dev/rdisk3

    The Linux dd command copies a file and also optionally re-formats. But conv= for is not specified here.

    if= specifies the input file name. The previous version is if=2014-01-07-wheezy-raspbian.img.

    of= specifies the output file disk.

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

    rdisk gives faster write speed to the SD card.

    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.

  25. 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)
    

    You should now have a working SD card at the end.

  26. Verify what devices are mounted :

    df -h

  27. In Finder, press the eject button for the disk.

  28. Skip past alternative activity below (for Windows) to Power Up.

Unzip and Flash using Windows

  1. 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.

  2. 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.

  3. 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

  4. Invoke the program.
  5. Select the drive containing the .img file on your laptop.

Power Up to GUI in SD card

If you insert a stock Raspbian Jesse image into the Pi and powered it up, it would by default display a GUI, and have no WiFi connection.

Based on this.

  1. Unlug the power adapter.

  2. 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.

  3. 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.

  4. 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

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

    Enable boot to CLI console

  6. When the regular Terminal window appears Configure the Pi

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

  8. Select “Console Text console”.

    Start Raspbian GUI

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

    startx

    View Raspbian GUI from Remote Desktop Client

  10. 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.

  11. 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.

  12. Specify IP address in Remote Desktop Client.

    Configure using GUI

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

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

  20. 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

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

    sudo halt

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

    sudo poweroff

  23. 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).

Reboot

### Configure user

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.

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

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

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

    sudo vim /etc/ntp.conf

  4. 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”.

  5. Save and exit the editor.

  6. Restart the ntp deamon.

    sudo /etc/init.d/ntp restart

  7. Wait a few minutes.
  8. 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

  9. 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

  10. 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.

  11. 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

  12. 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.

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.

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

    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

  • http://cagewebdev.com/raspberry_pi/ Rolf van Gelder

  • http://raspberrypihobbyist.blogspot.com Ted B. Hale

  • Reference: https://blogs.msdn.microsoft.com/brunoterkaly/2014/06/11/running-net-applications-on-a-raspberry-pi-that-communicates-with-azure/

  • Reference: http://raspberrypihq.com/how-to-install-windows-10-iot-on-the-raspberry-pi/ describes use of FFU2IMG

Resources

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

More on IoT

This is one of a series on IoT:

  1. IoT Acronymns and Abbreviations

  2. IoT Apprentice school curriculum
  3. IoT use cases
  4. IoT reminders prevent dead mobile battery
  5. IoT ceiling dumper

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

  11. IoT Clouds
  12. Samsung IoT Cloud

  13. Predix basics
  14. Predix installation
  15. Predix services
  16. Predix programming