Cloud Clusters With Raspberry Pi’s

Editor Gregor von Laszewski

(c) Gregor von Laszewski, 2018

1 Preface ☁️

1.1 Version ☁️

Date: Mon Oct 1 12:43:16 2018 -0400

This document can be downloaded from

https://github.com/cloudmesh-community/book/blob/master/vonLaszewski-pi.epub?raw=true

1.2 Contributors ☁️

Contributors are sorted by the first letter of their "combined Firtsname and Lastname and if not available by their github ID. Please note that the authors are identified through git logs in addition to some contributors added by hand. The git repository contains more than the documents included in this section. Thus not everyone in this list may have directly contributed to this document. However if you find someone missing that has contributed (they may not have used this particular git) please let us know. We will add you. The contributors that we are aware of include:

Anand Sriramulu, Ankita Rajendra Alshi, Arnav, Averill Cate, Jr, Bertolt Sobolik, Bo Feng, Dave DeMeulenaere, De’Angelo Rutledge, Eliyah Ben Zayin, Fugang Wang, Geoffrey C. Fox, Gerald Manipon, Gregor von Laszewski, Hyungro Lee, Javier Diaz, Jonathan Branam, Juliette Zerick, Miao Jiang, Mihir Shanishchara, Min Chen, Orly Esteban, Pulasthi Supun Wickramasinghe, Pulkit Maloo, Qianqian Tang, Ravinder Lambadi, Richa Rastogi, Saber Sheybani, Sachith Withana, Sandeep Kumar Khandelwal, Silvia Karim, Swarnima H. Sowani, Tim Whitson, Tyler Balson, Vafa Andalibi, Vibhatha Abeykoon, Vineet Barshikar, Yu Luo, aralshi, btpope, harshadpitkar, janumudvari, karankotz, qianqian tang, rirasto, shilpasingh21, varunjoshi01, vineetb-gh, xianghang mi

1.3 Creating the ePubs from source ☁️

Although you will never likely to create the epub from source, we have included this section for our most advanced contributors and those that update the epub on github.

1.3.1 OSX Requirements

This is just a guess I for got how to install all of this, it may be documented in another md file, grep -R for brew

$ brew install graphviz
$ brew install pandoc # needs version >2.2.3 of pandoc see travis for
                      # proper install if brew does not work
$ brew install pandoc-citeproc
$ npm install --global mermaid-filte

1.3.2 Ubuntu requirements

$ sudo apt-get update
$ sudo apt-get install graphviz
$ wget https://hackage.haskell.org/package/pandoc-2.2.3.2/pandoc-2.2.3.2.tar.gz
$ git clone https://github.com/jgm/pandoc-citeproc.git
$ wget -qO- https://get.haskellstack.org/ | sh
$ tar xvzf pandoc-2.2.3.2.tar.gz
$ cd pandoc-2.2.3.2
$ stack setup
$ stack install
$ cd ..
$ cd pandoc-citeproc
$ stack setup
$ stack install
$ npm install --global mermaid-filter

1.3.3 Creating a book

Books are organize in directories. We currently have

./book/cloud/
./book/big-data-applications/

To compile a book go to the directory and make it. Lets assume you like to create the cloud book for 516

$ git clone https://github.com/cloudmesh-community/book.git
$ cd cloud
$ make images
$ make

To view it you say

make view

1.3.4 Publishing the book to github

⚠️ This task should only be done by those with direct write privileges. and never be part of a pull request.

To publish the book say

$ make publish

1.3.5 Creating Drafts that are not yet published

Developers of the manual can modify the Makefile and locate the variable DRAFT= to add additional sections and chapters they work on, but should not yet been distributed with the main publication. Simply add them to the list and say

$ make draft
$ make view

to create the draft sections only and view them.

To conveniently call them in a lazy fashion in a terminal you could use the following two aliases.

alias m='make; make view'
alias d='make draft; make view'

This allows you to typ m for the main volume and q for the draft. Please note that all artifacts are written into the dest folder.

1.4 Github Issues ☁️

⚠️ The issues are automatically created from Github Issues. Please change them directly in github. Do not modify the table.

Count | Number | title | Assignee
1 | 72 | Open: virsh | pulasthi
2 | 68 | bib: create bibtex entries for go-intro.md | bfeng
3 | 62 | epub: organize container section | pulasthi
4 | 61 | epub: organize haddop section | bfeng
5 | 60 | epub: I see possibly two watson chapters | pulasthi
6 | 58 | epub: use numbered Figure refernces | bfeng
7 | 55 | epub: move the FAQ from week X to epub | bfeng
8 | 51 | Open: OpenAPI in GO | bfeng
9 | 50 | Open: REST in go | bfeng
10 | 49 | Open: Develop a tutorial on the Parallel language constructs in Go | bfeng
11 | 48 | Open: Develop an introduction to Go | laszewsk
12 | 47 | Open: Hot cold isles in data center | None
13 | 46 | Taken: Virtualization | laszewsk
14 | 45 | Open: Architecture of OpenStack | pulasthi
15 | 44 | Open: Architecture of AWS | pulasthi
16 | 43 | Open: Architecture of Azure | pulasthi
17 | 19 | Azure | bfeng
18 | 18 | epub: introduction has wrong URLS | pulasthi
19 | 9 | Slides to video are not included in the introduction | laszewsk

1.4.1 epub Readers ☁️

This document is distributed in epub format. Every OS will have a suitable epub reader to view the document. Such readers can even be integrated into the browser you use, and when you click on an epub publication in github it could pop up the document in your reader. The way we create the document is through scalable markup, that iss you can zoom in and out of a page while the content will beautomatically rendered for the selected page size. If you ever see a content that does not fit on a page we recommend you zoom out with your reader to make sure you can see the entire content.

1.4.2 Notation

☁️ :cloud:

If you click on the ☁️ in a heading, you can go directly to the document in github that contains the next content. This is convenient to fix errors or make additions to the content.

$

Content in bash is marked with verbatim text and a dollar sign

$ This is a bash text

[1]

References are indicated with a number and are included in the reference chapter [1]

⭕ :o:

Chapters marked with an ⭕ are not yet complete or have some issue that we know about. These chapters need to be fixed.

🎬 REST 36:02

Example for a video with the :clapper: emoji

📜 Slides 10

Example for slides with the :scroll: emoji. These slides may or may not include audio.

📝 Slides 10

Slides without any audio. They may be faster to download.

🎓

A set of learning objectives with the :mortar_board: emoji

✅

A section is release when it is marked with a ✅ in the syllabus

❓

Indicates opportunities for contributions.

✋

Indicates sections that are worked on by contributors

😃

Sections marked by the contributor with a 😃 when they are ready to be reviewd.

👋

Sections that neeed modifications ar indicated with 👋. They have been first set to 😃

👍

Section that are good to go (graded) are initailly marked with 👍 by the editor/TAs. The icon does not comment on the quality of the contribution.

⚠️

A warning that we need to look at in more detail.

💡 Notes are indicated with a bulb and are written in italic and surrounded by bars using the :bulb: emoji

Figures have a caption and can be refereed to in the epub simple with a number. We show such a refernce pointer while refering to fig. 1.

Figure 1: Figure example

Figures must be written in the md as

![Figure example](images/code.png){#fig:code-example width=1in}

You can refer to them with +@fig:code-example. Please note in order for numbering to work figure refernces must include the #fig:

Other emojis

Other emojis can be found at https://gist.github.com/rxaviers/7360908

1.5 About ☁️

This document has been created form our document collection to target the creation of Cloud Clusters with Raspberry PI’s.

The document can be contributed to by you and compiled on your local machine. More information about this will be presented in this prefix.

We recommend that you read an entire section first before you start copy paste style execution of shell commands or programs. We want you to obtain first a solid overview of what you need to do. Whatever yo do crate a backup first.

2 Raspberry PI ☁️

Raspberry PI’s are a convenient cheap compute platform that allow us to explore create cloud clusters with various software that otherwise would not be accessible to most. The point is not to create a complex compute platform, but to create a testbed in which we can explore configuration aspects and prepare benchmarks that are run on larger and expensive cloud environments. In addition Raspberry Pis can be used as a simple Linux terminal to log into other machines.

We will give a small introduction to the platform next.

2.1 Raspberry PI 3 B

Till February 2018 the Raspberry PI 3 B was the newest model. Within this class we have access to about 100 of them. The Raspberry PI 3 B is shown in fig. 2

Figure 2: Raspberry PI 3B

The board has the following properties:

Quad Core 1.2GHz Broadcom BCM2837 64bit CPU

1GB RAM

BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board

40-pin extended GPIO

4 USB 2 ports

4 Pole stereo output and composite video port

Full size HDMI

CSI camera port for connecting a Raspberry Pi camera

DSI display port for connecting a Raspberry Pi touchscreen display

Micro SD port for loading your operating system and storing data

Switched Micro USB power source up to 2.5A

2.2 Raspberry PI 3 B+

We plan to purchase a number of them so we can conduct performance experiments and leverage the faster hardware. The newest Raspberry PI 3 B+ is shown in fig. 2.

Figure 3: Raspberry PI 3 B+

The board has the following properties:

Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz

1GB LPDDR2 SDRAM

2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN

Bluetooth 4.2, BLE

Gigabit Ethernet over USB 2.0 (maximum throughput 300 Mbps)

Extended 40-pin GPIO header

Full-size HDMI

4 USB 2.0 ports

CSI camera port for connecting a Raspberry Pi camera

DSI display port for connecting a Raspberry Pi touchscreen display

4-pole stereo output and composite video port

Micro SD port for loading your operating system and storing data

5V/2.5A DC power input

Power-over-Ethernet (PoE) support (requires separate PoE HAT)

Detailed information about it are available at

https://www.raspberrypi.org/documentation/hardware/raspberrypi/README.md

3 Pi Cluster Form Factor ☁️

In this chapter we will discuss a number of opportunities to build small scale compute and cloud cluster resources using Raspberry Pi’s.

This includes the following:

NAS server with one Raspberry Pi 3

Cluster using 1 Raspberry Pi as master and 4 Raspberry Zeros as workers

Case With Cooling for 5 Pi)

Build an Octapi

Cluster with 40 Raspberry Pi’s

Cluster with 144 Raspberry Pi’s

Build Your Own 5 Node Pi Cluster

3.1 NAS (1 Pi)

Although a NAS is not really a compute cluster the Pi has used many times to build a Network Attached Storage (NAS) server. In this configuration a HDD is attached to the Raspberry and the network features of the Raspberry is used to access the disk drive via software installed on the PI that make this easily possible. Many tutorials exists on the Web that help setting op such a device.

We like to hear from you if you have successfully developed such a NAS and provide us with such links. Links that may help include:

https://hackmypi.com/NASpi.php

3.2 ClusterHat (4 Zero + 1 Pi)

The smallest cluster we came across is actually a hybrid cluster in which 4 Pi zeros attached to a Raspberry Pi 3. This sis achieved via an add on board to the Pi 3 allowing to plug in PI=i Zeros:

https://clusterhat.com/

The Cluster HAT (Hardware Attached on Top) allows to attach 4 Raspberry Pi Zeros via to be attached to a regular Raspberry PI 3 to simulate a small cluster.

According to the Web Site it supports the following features:

USB Gadget Mode: Ethernet and Serial Console.

Onboard 4 port USB 2.0 hub.

Raspberry Pi Zeros powered via Controller Pi GPIO (USB optional).

Individual Raspberry Pi Zero power controlled via the Controller Pi GPIO (I2C).

Connector for Controller Serial Console (FTDI Basic).

Controller Pi can be rebooted without interrupting power to Pi Zeros (network recovers on boot).

Figure: Clusterhat for PI Zero’s

Although this setup seems rather appealing, the issue is with obtaining Pi Zeros for the regional price of $5. Typically users can only by one for that price and must pay shipping. To by more one has to buy a kit for about $20. However, for that amount of money it may just be worth while to get Pi 3’s instead of zero’s. Nevertheless the form factor is rather appealing.

Additional information can be found at:

https://www.raspberrypi.org/magpi/clusterhat-review-cluster-hat-kit/

3.3 Cluster Case With Cooling (5 Pi)

Many instructions on the Web exist describing how to build clusters with 3 or more Pi’s. One of the considerations that we have to think about is that we may run rather demanding applications on such clusters causing heat issues. To eliminate them we must provide proper cooling. In some cluster projects cooling is not adequately addressed. Hence we like to provide an example that discusses in detail how to add a fan and what the fan has for an impact on the temperature.

Closed case for 5 Pi’s with case

http://climbers.net/sbc/add-fan-raspberry-pi/

http://climbers.net/sbc/diy-raspberry-pi-3-cluster/

From the above Web page we find the following information as shown in the following table. From the data in the table it is clear that we need to keep the Pi from throttling while being in a case by adding a fan as obvious from experiment No. 2.

Table: Temperature comparison of fan impact

No. | Case | Fan | Direction | RPM | Idle | 100% Load | Performance
1 | no | no | - | - | 41.0C | 75.5C | OK (barely)
2 | yes | no | - | - | 45.0C | 82.5C | throttles
3 | yes | 5V | in | unknown | 37.9C | 74.5C | OK (barely)
4 | yes | 7V | in | 800 | 35.6C | 69.5C | OK
5 | yes | 12V | in | 1400 | 32.5C | 61.1C | OK
6 | yes | 7V | out | 800 | 34.5C | 66.4C | OK

Interesting is also the design of the case that uses snaps instead of screws to affix the walls to each other. The case layout can be found at:

http://climbers.net/sbc/diy-raspberry-pi-3-cluster-2017/

3.4 Octapi (8 Pi)

A set of instructions on building an is available at

https://projects.raspberrypi.org/en/projects/build-an-octapi

Octapi

3.5 Bitscope Case (40 Pi)

A company from Australia called BitScope Designs offers a number of cases that leverage their Pi Blade boards allowing up to four Pis to be put together and sharing the same power supply. The blades are shown in the next Figure. The rack to place 10 of them is shown in the Figure after that.

Figure: BitScope blade for 4 Pi’s.

Figure: 40 Pi Blade rack.

The cost of the blade rack is $ 795.45 + $60.00 shipping + import tax. This may originally sound expensive when compared to a single case, however as we can store 40 Pis in them and they can share the power-supply and reduce cabling we think this case is quite interesting overall due to its price-point of $20 per Pi.

3.6 BitScope Cluster (144 Pi)

https://www.youtube.com/watch?v=78H-4KqVvrg

Together with LANL a new cluster module that holds 144 Pis is developed. This system is targeted to be placed into a rack to create a large Pi cluster. The cost for such a module is about $15K.

The next Figure shows the module.

BitScope 144 cluster module.

The next figure shows how multiple modules can be placed into a single rack.

Rack placement of multiple BitScope 144 cluster modules.

Additional information about this form factor can be found at the following links:

https://cluster.bitscope.com/solutions

https://www.pcper.com/news/General-Tech/BitScope-Unveils-Raspberry-Pi-Cluster-2880-CPU-Cores-LANL-HPC-RD

http://my.bitscope.com/store/

http://my.bitscope.com/store/?p=view\&i=item+7

http://www.newark.com/bitscope/bb04b/quattro-pi-board-raspberry-pi/dp/95Y0643

http://linuxgizmos.com/rpi-expansion-boards-support-up-to-40-pi-clusters/

3.7 Build Your Own 5 Node Pi Cluster

To experiment with building an elementary cluster one does not need to have a big budget. Such clusters are often dedicated to research tasks and are bound into security protocols that do not allow direct access. Instead it is possible to build such a cluster based on Raspberry Pi’s yourself if you are willing to spend the money or if you have access to Pi’s that you may loan from your department.

Table Parts lists one such possible parts list that will allow you to build a cluster for up to 5 nodes. However make sure to buy at least 3 Raspberry Pi’s with the appropriate memory. At minimum we recommend you get the 32GB SD card. We do not recommend any smaller as otherwise you will run out of memory. Additionally, you can add memory and disks on the USB ports. If you attach a HDD, make sure it has an external power supply and do not drive it from the USB power as otherwise the PI becomes unstable. A fan is at this time not yet included.

Naturally it is possible to modify the parts list and adapt. If you find better parts let us know. We have not included any case and you are welcome to share your suggestions with the class. For a case we are looking also for a good solution for a fan.

We suggest that when you build the cluster to do it on a table with a large white paper or board, or a tablecloth and take pictures of the various stages of the build so we can include it in this document.

Initially we just put Raspbian as Operating system on the SD cards and test out each PI. To do so you will naturally need an SD card writer that you can hook up to your computer if it does not have one. As you will have to potentially do this more than once it is not recommended to buy an SD card with the OS on it. Buy the SD card writer instead so you can redo the flashing of the card when needed. In addition to the SD card you need a USB mouse and keyboard and a monitor or TV with HDMI port.

Locate setup instructions and write a section in markdown that we will include here once it is finished. The section is to be managed on github.

.

Price | Description | URL
$29.99 | Anker 60W 6-Port USB Wall Charger, PowerPort 6 for iPhone 7 / 6s / Plus, iPad Pro / Air 2 / mini, Galaxy S7 / S6 / Edge / Plus, Note 5 / 4, LG, Nexus, HTC and More | link
$8.90 | Cat 6 Ethernet Cable 1 ft White (6 Pack) - Flat Internet Network Cable - Jadaol Cat 6 Computer Cable short - Cat6 Ethernet Patch Lan Cable With | link
$19.99 ¹ | D-link 8-Port Unmanaged Gigabit Switch (GO-SW-8G) | link
$10.49 | SanDisk Ultra 32GB microSDHC UHS-I Card with Adapter, Grey/Red, Standard Packaging (SDSQUNC-032G-GN6MA) | link
$8.59 | Short USB Cable, OKRAY 10 Pack Colorful Micro USB 2.0 Charging Data Sync Cable Cord for Samsung, Android Phone and Tablet, Nexus, HTC, Nokia, LG, Sony, Many Digital Cameras-0.66ft (7.87 Inch) | link
$7.69 | 50 Pcs M2 x 20mm + 5mm Hex Hexagonal Threaded Spacer Support | link
$7.99 | Easycargo 15 pcs Raspberry Pi Heatsink Aluminum + Copper + 3M 8810 thermal conductive adhesive tape for cooling cooler Raspberry Pi 3, Pi 2, Pi Model B+ | link
$34.49 | Raspberry Pi 3 Model B Motherboard (you need at least 3 of them) | link
$59.99 ² | 1TB drive | link
$15.19 | 64GB flash | link
$6.99 | HDMI Cable, Rankie 2-Pack 6FT Latest Standard HDMI 2.0 HDTV Cable - Supports Ethernet, 3D, 4K and Audio Return (Black) - R1108 | link
$12.99 | AUKEY USB C Adapter, USB C to USB 3.0 Adapter Aluminum 2 Pack for Samsung Note 8 S8 S8+, Google Pixel 2 XL, MacBook Pro, Nexus 6P 5X, LG G5 V20 (Gray) | link
$19.19 | For Raspberry Pi 3 2 TFT LCD Display, kuman 3.5 Inch 480x320 TFT Touch Screen Monitor for Raspberry Pi Model B B+ A+ A Module SPI Interface with Touch Pen SC06 | link

¹ items were replaced with similar ² item was not available

3.7.1 Assembling the Pi Cluster ⭕

TODO: replace the images with one that has white background

Figure
Description

Figure 1
First, aluminum and copper heat syncs need to be attached to each Pi. The two aluminum heat syncs are attached to the Broadcom chip and the SMSC Ethernet controller located on the top of the Pi. The blades of the heat syncs are parallel to the longer side of the Pi as shown in black aluminum fanned heat syncs are attached to the top of the pi as shown.

Figure 2
Flat copper heat sync is attached to the bottom of the pi as shown.

Figure 3
After attaching the heat syncs, threaded hexagonal spacer supports are used to connect the Pis together. A fully-assembled 5-node Pi cluster is shown.

Figure 4
Each node of the cluster is then attached to the switch using an Ethernet cables and to the power supply using a USB cables. The fully wired cluster is shown.

3.7.2 Virtual Raspberry Cluster ⭕

It should also be possible to create a virtual raspberry PI cluster while for example using virtual box. This requires two steps. First the deployment of a virtualized Raspberry PI. The following information may be useful for this

http://dbakevlar.com/2015/08/emulating-a-raspberry-pi-on-virtualbox/

The next step includes the deployment of multiple VMs emulating Raspberry’s. Naturally each should have its own name so you can distinguish them. Instead of just using the GUI, it would be important to find out how to start them from a command line as a shell script as well as tear them down.

Next you will need to make sure you can communicate from the Pi’s to each other. This is naturally the same as on a real cluster

⚠️ TODO: provide a section

This can be chosen as part of your project, but you need to develop a cloudmesh command for managing the cluster. This includes starting and stopping as well as check-pointing the cluster from a cloudmesh command. Furthermore you need to benchmark it and identify how to do this and contrast this to other clusters that you may start or have access to. Please get in contact with Gregor. This project is reserved for online students, as residential students will have access to real Raspberry PI hardware.

Please note that this project may have to use QEMU.

3.7.3 IU 100 Node Cluster Case ⭕ ☁️

At Indiana University we have currently about 200 Raspberry Pi’s available for students that work with us as part of classes.

Our goal for the use of these PI’s is multitude.

First, we naturally like that all PI’s could be used together in a large cluster. Second we like that student teams up to 3 students can use a small cluster of between 6 - 5 Pi’s and use them to provision their own OS. Third, we like to crate a case and shelf structure that allows this modular utilization of the cluster while breaking it down easily, but also assembling or adding to the cluster easily.

This section will document our efforts to support this. The section is heavily under construction and currently two STEM students work on the case. They are joined by an independent study student offer the summer that looks at the software for this cluster.

To simplify management we will be using github for managing tasks, but we will start collecting these tasks here. At this time the STEM students are using still a google docs document till they migrate to this or their own github.

The outline of the section is as follows 🚧

First we provide an introduction to which tools to use for designing a case. This is followed by some examples that may lead to a case design. Next we provide an introduction on how to use the Laser cutter at IU. The last part of this section includes a list of links and some images of clusters designed by others.

3.7.3.1 Designing a Case with CAD

We believe the best program for us to design a case for the cluster is OpenSCAD. Links and tutorials to the software can be found here:

http://www.openscad.org/

http://www.openscad.org/cheatsheet/

https://github.com/RigacciOrg/openscad-rpi-library

https://www.youtube.com/watch?v=WQd5db9lsQk

Although OpenSCAD requires programming, it seems to be easier than creating the design with a GUI based CAD program. For this reason we will be using SCAD.

Other CAD software may be accessible to you also. However will not use for our case design. This includes the IU Maker Lab standard Software is Fusion 360 which is available from

https://www.autodesk.com/products/fusion-360/overview

As it does require a license it may not be accessible to many students. However you can use alternative that can be used for free. This includes FreeCAD

FreeCAD Software https://www.freecadweb.org/

FreeCAD Documentation https://www.freecadweb.org/wiki/Main_Page

This program allows you to design the layout of a 3D case via a sophisticated GUI just like Fusion 360.

3.7.3.2 IU cluster Case design

We have designed the following cases

TBD

Right now we just put some templates here to showcase we can actually generate the cases. More details will be added here soon.

Obviously you need to be able to have some walls and shelfs for the case. The following SCAD file shows how to use a simple cube to do that. This is just a start as the design does not include any connectors.

scad file

Figure: TBD

Next we show you how to use some predefined Raspberry PI boards in SCAD and use for loops to create rows and columns of 5 PIs each.

100-pis

Figure: TBD

In the last design we showcase how the basis of a 5 node cluster could start. Naturally many other thing s need to be improved. Such as the connectors, and the proper width. However this SCAD will provide you with a good start to improve your SCAD programming abilities and come up with a final design.

100-pis

FIGURE: TBD

Once you have designed the 5 node cluster, you will also need to design a shelf in which you can place them. Power plugs need to be added. so you can power the PI within the cluster.

3.7.3.3 Laser Cutter

With a laser cutter we can create very precise cases. First, you will need an overview of what a laser cutter is. There are many good resources about this on youtube. One such video is provided by a company that sells laser cutters:

https://www.youtube.com/watch?v=SIjUVCho_xU

Disclaimer: While pointing to this video we do not endorse the product. We do not own this particular brand.

After you have designed your case, you can create it on the laser cutter available at Indiana University. The laser cutter is located at

TBD

and operated by ISE. You can get access to it by contacting the help desk with an email. You will need to get certified for operating the laser cutter to use it.

⭕ TODO: add contact email

The certification will teach you how to use the laser cutter properly. We will walk you through the steps that you can expect will be tought to you as part of the certification.

The first step includes turning on laser cutter.

An instructor will demonstrate how to turn the laser cutter on and carry out other preparation tasks on how to operate the laser cutter. Please get familiar but do not yet touch any buttons from the laser cutter.

Figure: Control Panel

Next the instructor will give you a walk through of the machine so you can replicate these steps next time.

Turn the laser cutter on: Use key to turn on the laser cutter.

Turn the exhaust fan on: The fan is a separately switched unit. Turn on the switch on the wall next to the laser cutter. ⚠️ It to turn on the exhaust in order to have proper ventilation during the cutting process.

Put the cutting material onto the laser cutterbed. The instructor puts the cutting material onto the laser cutter bed. In case the material is smaller than the honeycomb bed you will need to place is as follows TODO: TBD

The buttons for the laser cutter do the following

The middle top one is on-hold button, one can press it to save the power of the laser cutter.

The start/pause button can be used to pause a job in the middle. Once you start from a paused state the job resumes.

The stop button will cancel the job. You will need to restart the job from the beginning if this button is pressed to stop a job.

The four buttons on the bottom left controls the x/y horizontal shift of the laser head. The other two controls the z-axis, or vertical movement of the cutting bed.

Note that while the stop button stops the entire process, the pause button will halt the process so you can continue.

To properly cut the material, you will need to focusing the laser head. Move the laser head above the cutting material, then will place the focusing tool on the laser head. Then carefully raise the cutting bed. When the focusing tool touches the material on the bed it will fall off indicating the laser is focused. You must be careful to not raise the bed too fast in order not to damage the laser head.

Now we need to send the file to the job control software and initiate cutting

Send the file to the Job Control by opening the saved file in Adobe Illustrator. TODO: how do we get the SCAD file into it, which format do we need. You click print and set the printer to “Trotec Laser Cutter”.

Set laser cutting parameter will be set to width and height of the cutting area in the size column. By clicking the “Preferences” tab, one can adjust the settings of different colors (traditionally red lines are for cutting and black lines and areas are for engraving)

Move the file to Job Control work surface by turning on the Job Control software and discover the job is in the queue on the right of screen.

Next drag the file to be cut on to the Job Control work surface and set it up in the upper right corner.

Select the Play arrow in JobControl

An exhaust warning will appear. Select OK. The job will start.

Questions to be integrated:

What is the importance of setting cutting parameters?

What will you check before pressing the start button to ensure safety?

3.7.3.4 Cases and Parts Designed by the Community

A 3D model of the Raspberry PI is available at

STL https://www.thingiverse.com/thing:1701186

https://grabcad.com/library/raspberry-pi-3-reference-design-model-b-rpi-raspberrypi-raspberry-pi-2

These models are important as they allow us to use them in the CAD drawings to identify proper placement.

Certainly we need to identify how to connect the walls of the case. The following links provide some ideas for such connections.

T-nut design: A convenient connector using screws ant nuts to connect walls in 90 degree angles [link]

How To: Make Cheap LaserCut Custom Boxes for Your DIY Electronics, includes t-bolt design [link]

A tutorial on how to make snug joints. It has some good tips of placing circles as stress relieve points [link]

Screw only: A design to just use screws to connect the walls. The disadvantage is that the receiving ends need to be cut by a hand tool. [link]

A sample design that just uses groves, so this would have to be glued. [link]

Another design with groves that needs to be glued [link]

A guide to handle acrylic [link]

Some special brackets which could be 3 D printed. These brackets have the advantage that only slots and holes need to be placed [link].

Although CNC, here are some connector ideas that could be replicated or modified for acrylic [link]

Some tips for working with acrylic in general [link]

[link]

A design based on metal beams to create the outside. This may be more expensive, but stable [link]

Some also used lego technics [link]

We also previously indicated that the width of the mounting holes on a Pi is about 7 spaces wide, making it possible to create a lego technic case.

3.7.4 Pi Clusters on the Internet ☁️

There is a large number of projects related to creating Pi clusters on the internet. They vary in size and software installed on them. Naturally a Pi cluster is a useful training and development environment for research organizations and thus many bigger projects are located at universities as well as government labs. However, we also have many projects done by enthusiasts.

We distinguish two different efforts. First, we often find projects that target the creation of cases for such clusters and second, we find projects that develop software fort these clusters. This section will provide an overview of these activities and provide links to these activities.

3.7.4.1 Cluster Cases

3.7.4.1.1 Lego

When looking at the placement of the wholes on the Raspberry Pi, the width between the wholes on the small side seems to be exactly 7 Lego Technic beam wholes apart. This has the advantage that one could build a quick frame form Lego pieces such as a

2 * 11 ($0.22) piece [link]

2 * two piece * 4 * 4 ($0.192) [link]

A number of connector pins [link] [link]

The cost is about $0.25 per piece = $2.74 per pi.

So if we are having 100 pis we end up with $274. However we also need still to get screw and Lego connectors which we at this time have not counted and included in this calculation.

Naturally Lego’s have been explored by others

Images on google

University of Southampton: [link] Instructions are no longer at the original link

Lego Technic: [link], [link]

Lego Technic [link]

Old style Lego [link]

Other ideas using Lego’s include:

Compact case: Single board No screws [link]

Zero 3D print Thingverse [link]

B+ 3D Pi case [link]

Other interesting but not cluster related links include

Lego hat [link]

Brick Pi [link]

3.7.4.1.2 Beast by resion.io

This company has provided some larger designs for Raspberry Pi clusters and tries to create a modular system to put a number of Pis on plates that than can be connected.

Beast 3 [link]

Beast 2 [link]

Beast 2 Tile [link]

3.7.4.2 Clusters

Additional links which could be useful include:

SDSC Raspberry Pi2 MPI and Tiled Wall Viz Cluster [link]

Six Common Errors When Building a Raspberry Pi Cluster [link]

5 Most Popular Raspberry Pi Cluster Supercomputer Projects [link]

10 amazing Raspberry Pi clusters [link]

Build an OctaPi [link]

An older document on how to create an MPI cluster is located at

Pi 2 MPI cluster, Boise State [link]

3.7.4.2.1 Swarm

How to set up docker swarm is documented here

Pi Docker Cluster [link]

3.8 Exercise ☁️

3.8.1 Single Raspberry Pi Temperature

You have been presented in Section Cluster Case With Cooling (5 Pi) with a table that compares temperatures. Your task is to identify issues with the experiment and the table. Furthermore we like you to rerun a temperature experiment in the entire class.

Get a PI3 model B, an HDMI cable, a power supply, a case. Such a configuration is listed in the IoT section.

Buy or manufacture a case of your choice. You can use a 3d-printer if you have one available.

Conduct a temperature experiment.

Discussion of these assignment is to be executed openly in class. Points will be issued only once the class agrees upon an experiment.

This exercise is not only to learn about the behavior of the Pi, but also about how to coordinate experiments with a large number of students.

Pi.Single.1

What temperature measurement is missing from the table.

Pi.Single.2

How would you create an experiment under load.

Pi.Single.3

How would you create an experiment to which all students in different classes could contribute their values? Can the cloud be used?

Pi.Single.4

Collect the information from all class members using cloud services.

Pi.Single.5

Identify how to use the VPN server so you can use your Laptop instead of a TV or computer monitor. Write a section

3.8.2 Small Pi Cluster

In this set of exercises we will be building a small Raspberry Pi cluster. All of you will have to do exercise Pi.Cluster.Build as well as one of the tasks related to Swarm, kubernetes or Spark.

It is important that you write down all steps very carefully as you are expected to use the steps to develop an automated deployment. For your cluster. Your section will be tested by other groups and easy of installation completeness, and correctness will be evaluated. Teams that find issues and improve deployment sections will receive points. TA’s will also replicate these steps to identify a fair evaluation without bias.

Pi.Cluster.Build

Build groups of up to 5 people. Make a plan on what needs to be done to build the cluster and develop a schedule. Include in this plan (a) obtaining the material the hardware build, (b) the installation of the operating system (c) the testing of the system (d) familiarizing with the OS.

Pi.Cluster.DockerSwarm

Install a docker Swarm cluster on your PI. Develop a section in markdown and mind plagiarism. Contribute your section to this document to get acknowledged and credit. Work with others in class to coordinate a single section.

Pi.Cluster.Kubernetes

Install a kubernetes cluster on your PI. Develop a section in markdown and mind plagiarism. Contribute your section to this document to get acknowledged and credit. Work with others in class to coordinate a single section.

Pi.Cluster.Spark

Install a spark cluster on your PI. Develop a section in markdown and mind plagiarism. Contribute your section to this document to get acknowledged and credit. Work with others in class to coordinate a single section.

3.8.3 Cluster Case

In this exercise you will be designing a cluster case so you can put the Pi’s in a professional looking case that also protects the equipment.

It will be up to you to decide upon the form factor of the case. Please consult with the appropriate sections as you will need to fit in not only the Pi’s but also the parts.

Please use OpenSCAD as basis. You may also try FreeCAD.

PI.case.ClusterHat

Design a case for the Cluster Hat

PI.case.5

Design a case

PI.case.n

Please reuse the Pi.Case.5 as basis, e.g. it is a shelf in which we place the cases. Make sure to organize power and allow for easy access to the cases and the pis within the case.

3.8.4 Cluster Case Lego

Pi.lego 1

count the connectors and make a more accurate calculation

Pi.lego 2

design a frame in which the Pi’s can be placed in groups of 5.

Pi.lego.3

design a cluster case for the raspberry PI with LDD https://www.lego.com/en-us/ldd. You do not have to buy the pieces, but just provide the design.

4 Using A Single Pi ☁️

4.1 Raspberry PI Setup ⭕ ☁️

This section will be a the start for the replacement for all previous setup instructions. I think we want ultimately the section “PI Network of Workstations” to also use this or be the final section.

Once the content has either been integrated here or it is determined that the previous file is no longer needed, we will move the other file into a dir deprecated, and remove the file from chapter.yaml.

We will aslo need to manage a second documentation just for CM-burn in the cm-burn repo that just focusses on cm-burn as this is also a stand alone prg

The duplicated sections we are aware of include:

If its integrated mark the checkmark. We need to be carful not to lose info

[ ] https://github.com/cloudmesh-community/cm-burn/blob/master/README.md

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/setup.md

[x] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/setup-dev.md Now only contains information for a development environment. needs to be renamed. Stays in this file for now.

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/pi-passwordreset.md

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/run-at-boot.md

[x] deleted https://github.com/cloudmesh-community/book/blob/master/chapters/pi/sd-card.md integrated in setup-ultimate

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/clusters/pi-configure-cluster.md

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/clusters/pi-setup.md

There may even be more such documentation as part of student projects. No student that does a PI project MUST DESCRIBE HOW THEY SET UP THE CLUSTER IN THEIR REPORT. THEY ALL MUST IMPROVE OR USE THIS SECTION.

I also see that portions of other files include or can leverage what we do in cm-burn and thsu we can replace that info or morege portions of it such as in and than these sections need to be fixed while using our ultimate guide, e.g. make a pointer to it

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/kubernetes/pi-kubernetes.md

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/kubernetes/526/readme-kube.md

[ ] https://github.com/cloudmesh-community/book/blob/master/chapters/pi/kubernetes/417/pi-kubernetes.md

As you see everyone duplicated in part the steps. So what we need is a single section that describes the cm-burn procedure, but also the steps needed by hand for those that can not afford the $50 investment of the mount prg.

Next we propose an outline. Help improving the outline than contribute here to this single document while not replicating sections but refer to sections if needed. IF difference between windows osx and linux, aslo include the differences.

4.1.1 Image Choice

When it comes to the operating system install, we have multiple options. One of the options you will find is the installation of what is called NOOBS. NOOBS is actually not an operating system, but it installs an operating system. Nobbs has the feature to install an operating system of choice on the Raspberry. It aslo allows to recover from a faulty OS. A good introduction that showcases some of the features of NOOBS is available at:

https://www.raspberrypi.org/blog/introducing-noobs/

It also provides the necessary tools to modify the config.txt file that is used at boot time.

However, as we at this time only intend to use Raspbian as the OS, there is no need to install NOOBS. If the OS breakes, we simply burn a new SD card. Hence the features we gain from NOOBS are not as beneficial to us.

Instead we will directly install Rasbian on our SD card and configure it appropriately.

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

4.1.2 Simulating a Raspberry PI on a Computer

In case you do not have a computer available, you can also install a Raspberry Pi in a virtual machine.

<https://downloads.raspberrypi.org/rpd_x86_latest

You can download the image and start it via virtual box. As we work with newer PIs we recommend that you set up under Linux virtual machine with 64 bit with Other.

Once completed, you will see that it looks something like

Virtual Raspberry Pi

4.1.3 Setting up a Single Raspberry PI

We discuss here the steps to set up a single Raspberry while installing Raspbian on an SD Card. For this we will use etcher for Windows and macOS. Other solutions such as using command line scripts are also available and are demonstrated for example in the section about burning SD Cards in Linux.

4.1.3.1 Burn an SD Card with cm-burn ⭕

A very convenient program to create an SD card for a Raspberry pi is using the program cm-burn. The program is available from

https://github.com/cloudmesh-community/cm

It can be installed with

mkdir -p cloudmesh-community
cd cloudmesh-community
git clone https://github.com/cloudmesh-community/cm.git
cd cm
pip setup.py .

You will now have the program cm-burn available. Please note that cm-burn is provided without any warranties to work and that if you damage your system we do not have any liability.

The command is somewhat very special as it sets up the Raspberry pi directly on the SD Card without the need for rebooting it. The downside is that you need to have an OS that can mount the Ext file system. This can be achieved on OSX and Windows with a program called extFS. However it costs about $40. Detailed information on how to use cm-burn is provided at

https://github.com/cloudmesh-community/cm/blob/master/README.md

For moere advanced options see cm-burn which also works for a single card but requires a purchased product.

Burning the SD Card is discussed in Section TBD

Section Password discusses how to change the password after you booted the PI. ⚠️ This must be the first thing before you put the PI on the network or otherwise it is broken into quickly.

…

To not have to purchase it we describe here the steps needed to do it be hand. THis is discussed in Sections … ⭕ list all the sections here.

4.1.3.2 Install Raspbian on a SD card

For many Raspberry Pi related projects we need to install an Operating system on an SD card. We use Raspbian as the OS as it is widely supported. Other OS have recently been added to the available list of operating systems for the PI, but we will at this time not consider them here.

To install the OS on an SD Card you will need another computer. We describe next the process if you have either a MAC or an Linux Ubuntu machine. If you have other OSes and like to contribute, please add your suggestions.

The processes described in this section only work for a few SD cards and is not suitable for burning hundreds of SD cards as we would need for a cluster consisting out of many PI’s.

4.1.3.2.1 Download Raspbian

No matter which OS you create the SD Cards on, you will need to download the Raspbian OS.

Next, you need to download the Raspbian image and place it in a directory. As you may reuse the image multiple times, we recommend to place it in a location you remember. Let us assume you place it in ~/Download directory. Visit the link

https://downloads.raspberrypi.org/raspbian_latest

and download the image into the folder of your choice (we assume ~/Download).

4.1.3.2.2 Etcher form Windows and macOS, Linux

An easy way to burn a SD Cards on Windows, macOS, and Linux is with a programm called Etcher. Etcher can be downloaded from

https://etcher.io/

Chose the download suitable for your OS. On Windows you ahve a couple of options. We recommend that you use the 64 bit Installer version if your OS supports it. If you have a Windows 32bit OS, it may be time to upgrade your computer and/or OS. Also on Linux you need to make sure you distinguish between 32bit and 64bit.

4.1.3.2.3 Windows 10

Once you download it, start Etcher and select the unzipped Raspbian image file. Now select the drive of the SD card. click Burn and your image will be written to the SD card. You can monitor the progress an once it is completed the SD card will automatically unmount. Use it now in your Raspberry Pi.

The process is the same as the one on macOS

4.1.3.2.4 macOS

Once the image is downloaded you copy it with etcher onto the SD-card.

Place an SD Card into a SD card reader we recommend a 32GB card.

Attach the card reader to the computer

Open Etcher and select the downloaded .img or .zip file which you will likely find in the ~/Download folder if you followed our previous steps

Select the SD card to write the image to. Be careful, to chose the right location as otherwise you could create unexpected dataloss

Hence, review selections carefully and click Flash! to begin writing data to the SD card.

4.1.3.2.5 Ubuntu from Etcher

The process is the same as on macOS.

4.1.3.2.6 Ubuntu from Commandline

In Ubuntu we can use the advanced Linux commands to burn the SD Cards In the file explorer, right click on the SD card and format the SD card. This is done as follows:

Run

$ df -h

to list all the drives in the computer

Insert the SD card and run the command again

Now a new entry will be listed which is the SD card

The left column of the results from df -h command gives the device name of your SD card. It will be listed as something like /dev/mmcblk0p1 or /dev/sdX1, where X is a lower case letter indicating the device. The last part (p1 or 1 respectively) is the partition number.

Write down the name of the SD card (without the partition)

Unmount the card so that the card can not be read from or written to with the following command:

$ unmount dev/mmcblk0p1

Make sure to use correct name for the card. If your card has multiple partitions unmount all partitions

Next write the image to the SD card by running the command:

$ dd bs=4M if=<path to .img> of=/dev/mmcblk0 status=progress conv=fsunc

Make sure if= contains the path to image and of= contains the name of the SD card otherwise you may ruin your hard disk

To check, if the image was properly written you can do the following:

Create an image again from the SD card by running the following command:

$ dd bs=4M if=/dev/sdX of=from-sd-card.img

Truncate the image to be the same size as that of the raspbian image

$ truncate --reference <original raspbian image> from-sd-card.img

Run diff to see if the two files are same by running the following command:

$ diff -s from-sd-card.img <original raspbian image>

If everything iss ok, diff should say that the two files are same

In most cases the verification step will not be needed.

4.1.3.3 Password

Before you bring your Raspberry Pi on the networks, you need to reset the password. This can be done by starting the terminal and typing in it the command

pi$ passwd

The original password is raspberrypi and every one knows it. SO if you put your pi on the network it is easily compromised. Hence, change your password first.

4.1.3.4 Locale

You want to also set your system to use your language settings for the keyboard. you can do this isn the terminal with

pi$ raspi-config

or

pi$ sudo dpkg-reconfigure locales

or using the GUI.

4.1.3.5 Wireless Network at Home

The easiest way to get internet access and to continue the setup is using a wireless network. You can configure it either via the GUI or commandline.

In case you like to edit the information from commandline edit the file interfaces file with

pi$ sudo nano /etc/network/interfaces

change the following

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "your-WLAN-SSID"
wpa-psk "your-WLAN-password"

and replace the values with the once you have. To save the file use

Ctrl-o Y Enter Save changes.
Ctrl-x Quit nano.

4.1.3.6 Wireless network at IU

IU runs several different networks. This includes IUSecure, Eduroam, and ATT Wifi. The first two would require you to use your IU username and password to be entered in the configuration. Although technically possible we find the method ⚠️ HIGHLY insecure and ⚠️ STRONGLY advice agains doing so. Let us assume you put your information on a PI and than someone takes the SDCard from it. They can than look into the card and steal your password. Obviously this is not advisable. In other cases you may have configured your software wrong and someone could login remotely and lift your password remotely. Obviously this is not advisable.

Regardless, we have seen from instructors the advice to use IUSecure. This is ⚠️ WRONG! Do not listen to them about this particular issue and advise them to use an alternative setup

One such alternative (which is also not ideal) is to use the free wifi offered by ATT Wifi. It is a bit complex to setup as you need to go to the Web browser to the address http:\\iu.edu and click on the connect button. Sometimes that button is not visible so you need to scroll down to see it.

We also have an internal network that we will not discuss here, but can be used upon consultation with Dr. von Laszewski.

4.1.3.7 Update

We want to update the software and make sure everything is up to date. This is done with

pi$ sudo apt-get update

To develop easily we need a number of programs on our Pi. Additional programs can be installed with the command

pi$ apt-get install PACKAGE

where PACKAGE is the name of the software we like to install. A good example is emacs which can be installed with

pi$ apt-get install emacs

4.1.3.8 Hostname

The hostname is stored in /etc/hostname. Edit the file and change it to a name such as green00, green01, green02, green03, green04, green05. Be consistent with the names. The 00 host should be the top most host in the cluster.

edit

pi$ nano /etc/hostname

after you edited the hostname

pi$sudo /etc/init.d/hostname.sh start

Ideally we want to find out how to write the hostname after we burn the SD card on the laptop that does the burning

develop a python script to do that

4.1.3.9 Remote access via ssh

To enable ssh on the pi you need to say

pi$ sudo systemctl enable ssh
pi$ sudo systemctl start ssh

Naturally you need to do a bit more such as placing your public key in the authorized_keys file explained later, but for now we will just activate ssh.

To access the machine using public keys we recommend that you add your public key to the ~pi/.ssh/authorized_keys file

4.1.4 Setting up a Small Cluster by Hand

⭕ This explains how to set up a small cluster by hand discussing how to burn multiple cards. It uses the method of booting the pi and using a monitor to set up each of them. starting with passwd

The process described above can be replicated fairly easily for a small number of PIs. Just make sure you have a different hostname for each Pi. More complex setups are discussed next while for example using static IP addresses.

4.1.4.1 Wireless network addresses by hand

⭕

4.1.4.2 Static network addresses by hand

⭕

4.1.4.3 Mixed wireless and static network

⭕

4.1.5 Setting up a Small Cluster with cm-burn

This discusses how to set things up for many PIs with cm-burn

4.1.5.1 Setting up a large cluster with cm-burn

here we discuss one lareg cluster setup lets say 100 nodes

4.1.5.2 DHCP setup

⭕

4.1.5.3 PXE Boot

⭕

4.1.5.4 Setting up a pluggable cluster of clusters with cm-burn

Here we discuss a class of students that each have 5 node clusters that come in a room to place their clusters in a shelf then they plug it into a power strip and a network, they replace the SD card of the master with a worker SD card there is a special master that detects new workers and inventories them with different states, so we can get to them if they are registered.

4.1.6 Using Advanced setups with Ansible

4.1.7 Change Password on the SD-Card

It is possible to reset the password for a PI SD Card. This comesin handy when you did forget it or the team that worked on a Pi has left the project but valuable information may still be on the PI. To do so, You need tou unplug the raspberry pi and remove the SD card from the slot. Next you need to have the ability to mount the file systems. On macOS and Windows you can use extFS. Naturally if you have a linux machine or another PI, you can use an SD Card reader/writer and mount it directly. You will need root access on the machine where you execute the password reset.

After you inserted the card, please Locate and edit the etc/shadow file on the SD card. To create a new password use the command

$ openssl passwd -1 -salt <unique string>

Next, we e must find the line that starts with pi and replace the text between the first and second with the output from the above command we had executed in the etc/shadow file

Now you can Eject the SD card from the computer, and insert it into the Pi. Boot the raspberry pi and log in to it while using the new password. This naturally only works if you allow password login. ON many systems we however disable it and use public key authentication only. In this case you need to just replace the public key in the authorized_keys file. Using just keys is obviously more convenient.

Naturally mounting the SD Card and looking in the filesystem would also allow you to look at the network setup. That is certainly not good and before a PI is returned sensitive information should be cleaned from the SD Card.

4.1.8 Exercises

SD-Card.1

Improve the Ubuntu SD-card documentation

SD-Card.2

Could a script be written that does the entire process via a python or shell command in Ubuntu.

SD-Card.2

Could a script be written that does the entire process via a python or shell command in macOS?

SD-Card.3

could a script be written that does the entire process via a python or shell command in gitbash for Windows?

SD-Card.4

In general the Ubuntu documentation is complex, how can it be simplified? Maybe through automation?

4.2 Setup of a Development Environment ☁️

4.2.1 Editors

Naturally we need a useful editor. We have made good experience with emacs as it supports a variety of different formats and is also available for macOS and Windows.

You can install it with

$ apt-get install <program>

Other editors include emacs, vim, gedit and so on. If you are concerned about space, use vi which is pre-installed. If you like to use other editors use the command we can install them respectively with

$ apt-get install emacs
$ apt-get install vim
$ apt-get install gedit
...

4.2.2 Python 3

Raspbian comes by default with Python 2. However, more and more libraries become available in Python 3 and you can install it with

$ sudo apt-get install python3

If this does not work you can also compile the newest version as follows

$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev
$ sudo apt-get install libssl-dev libsqlite3-dev tk-dev libgdbm-dev
$ sudo apt-get install libc6-dev libbz2-dev
cd /usr/src
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
sudo tar xzf Python-3.6.5.tgz
d Python-3.6.5
sudo -s
bash configure
make altinstall
exit

4.2.3 Python IDLE

Click Menu -> Programming -> Python 3 (IDLE), and you’ll get a new window called ‘Python 3.6.5 Shell:’. This Shell works just like Python on the command line. Enter print(“Hello World”) to see the message.

4.2.4 Go

To install go use

$ wget https://storage.googleapis.com/golang/go1.9.linux-armv6l.tar.gz
$ sudo tar -C /usr/local -xzf go1.9.linux-armv6l.tar.gz
$ export PATH=$PATH:/usr/local/go/bin

If you like to have it included every time you start a terminal please please the line

export PATH=$PATH:/usr/local/go/bin

in your ~/.profile file and reboot.

Now you are also able to program go on your Pi.

4.3 Visual Feedback Management ☁️

Now that we have a Pi configured we need to make sure that we can send sometimes visual clues about its operations. This can be done via displays and LEDs. In case no display is available we can even connect to the PI with a virtual display redirection.

4.3.1 Default Display Setup

The raspberry pi comes with a defualt setup and any modern HDMI enabled TV or monitor will most likely work out of the box without any modifications. Just plug the HDMI cable in and start the Pi and you will probably see some boot messages and after a while see the splash screen for your installed operating system.

4.3.2 Automatic Display Detection

In case you like to use the Raspberry Pi in your office, at home, or in the field, you may find yourself in a situation where different monitors with different resolutions are attached. Especially in the field it is convenient if the Pi could do this adjustment for you and use the resolution assigned for the attached device.

In this section we describe such a solution. We will automatically detect the resolution based on the monitor attached. Once detected the config file will be rewritten if necessary and the Pi will be rebooted with the correct resolution in the configuration file.

⚠️ In order for your monitor to work, you will need to add it to the script we provide. Use the following program and add appropriate cases for your monitor

/usr/bin/tvservice -d /boot/edid.dat
/usr/bin/edidparser /boot/edid.dat

4.3.2.1 How it works

To achieve this we have developed the file displaydetect.py that automatically detects and set the display for the pi. To integrate it in the Raspbian OS please follow these steps

Install the display detect script. Run this as root:

$ wget https://raw.githubusercontent.com/cloudmesh/cloudmesh.pi/master/displaydetect.py -O /bin/displaydetect.py
$ chmod a+x /bin/displaydetect.py

Create a copy of /boot/config.txt and rename it to /boot/config.txt.in

$ cp /boot/config.txt /boot/config.txt.in

Add the following lines to the end of the config.txt.in file:

# customized display setting
hdmi_group=2
hdmi_mode=87
hdmi_cvt {x} {y} 60 6 0 0 0
display_rotate={display_rotate}

Add the display detect script to rc.local so it runs every time the pi is booting. Add this to end of /etc/rc.local before the “exit 0” line:

$ /usr/bin/python /bin/displaydetect.py

Make sure rc.local would be running during boot.

$ systemctl status rc-local.service

Check if the service is ‘active’.

Once it is installed, the pi will be check the display during the first boot, and it will set the correct display parameters if found necessary and do a second boot to finish the configuration change.

Now you can go in the filed and use the monitor of your choice

4.3.2.2 Adding new monitors

Look at the monitor name

look at the preferred resolution

create an new condition in the switch

4.3.3 Using the Laptop as a monitor

In case you do not have a monitor at hand there are various ways on using your computer as a monitor fo the Pi. The initial setup is recommended to do with an HDMI monitor. There are instructions on the Web that will let you set up the PI even without such a monitor, but here we go the simpler route to set it up once, so you can access it without monitor once you completed the setup.

First, install the remote desktop program on the Pi with

pi$ sudo apt-get install xrdp

Second, connect now your Laptop with an an ethernet cable to the Laptop. As services start up automatically, you will have to wait for a while. till the LAptop has assigned an IP address. Furthermore you may need to allow the Laptop to assign DHCP addresses when you plug in the ethernet cable.

⭕ we could need your help here telling us how you do this for your machine.

After some time you will see that the Laptop has assigned an ip address

You can run on your Pi, but also on your Laptop (if it supports ifconfig)

the command

pi$ ifconfig

and on your laptop

laptop$ ifconfig

You will see the typical output from ifconfig

look on the pi for the line that starts with

inet addr

it will be followed by an ip address such as

192.168.10.1

Now you can connect to this address, with the help of a program such as Remote Desktop Connection on Windows or Bonjour on macOS.

Type in the ip address and you will see the desktop.

In order to avoid always having to do the first step and getting different ip addresses, we recommend that you set up a static address for the raspberry.

⭕ please help identifying how to do this

⚠️ We recommend not to use the WiFi and the ethernet adapter at the same time as it can come to issues when you boot them up while they are both connected.

4.3.4 Exercises

E.Display.1:

Configure your Raspberry Pi so you can access it via VNC.

E.Display.2:

Make the displaydetect.py truly discoverable, find a default resolution that you put in to the else statement. Identify the preferred solution from the script and use that. Parse the appropriate parameters such as x,y, ans aspect ratio, rotation and other parameters.

4.4 VNC ☁️

Note: If you like to connect to your Raspberry from your laptop, we recommend to use VNC. If you rather like to connect a monitor and keyboard as well as a mouse to the Raspberry, you can skip the steps with the VNC update.

4.4.1 Setting up VNC

We had some issues with the installed version of VNC that is customized for connecting a Laptop via the ethernet cable to the PI. However as we connect wirelessly, our setup is slightly different. The easiest way that we found is to update the Raspbian OS as follows. In a terminal type

sudo apt-get update
sudo apt-get install realvnc-vnc-server
sudo apt-get install realvnc-vnc-viewer

Next you enable the VNC server in the configuration panel via the Raspbian GUI by selecting

 Menu >
    Preferences >
       Raspberry Pi Configuration >
          Interfaces.

Here you toggle the VNC service to enabled. As we are already at it in our setup we enabled all other services, especially those that deal with Grove sensor related bins and wires.

Next reboot and double check if the settings are preserved after the reboot

4.4.1.1 Install VNC on macOS

To install a vnc server of your liking on your Mac. You find one at

http://www.realvnc.com/download/vnc/latest/

Be sure to download the version of the VNC Viewer for the computer you are going to use to virtually control the Pi (there is a version listed for Raspberry Pi– do not download this one. For us this is the Mac version.)

4.4.1.2 Run VNC Viewer on macOS

Once you have downloaded the VNC viewer installed it you can open the program. Next you can start vnc viewer and enter the ip address of your raspberry. Make sure you are on the same network. You can find the address by using ifconfig.

4.5 Motherboard LED ☁️

The Raspberry pi contains an LED that can also be used to provide us with some information as to the status of the PI. It is usually used for reporting the power status.

The green LED can be made blinking as follows in root

echo 1 > /sys/class/leds/led0/brightness
echo 0 > /sys/class/leds/led0/brightness

Naturally this ac be done via a remote command if your ssh keys are uploaded and your originating computer is added to the authorized_keys. Now you can can control them via ssh

ssh pi@red03 "echo 1 > led; sudo cp led /sys/class/leds/led0/brightness"
ssh pi@red03 "echo 0 > led; sudo cp led /sys/class/leds/led0/brightness"

This is extremely useful as it allows us to check if we the OS is available and we can access the PI.

One strategy is to for example switch the light of, once it is booted, so we can see which board may be in trouble.

4.6 Run Commands at Boot time ☁️

In many cases we need to provide configurations and programs that run at boot time. A number of different methods exist to run commands and programs at boot time.

We will be focusing here only a few of them

4.6.1 rc.local

On your Pi you will find under /etc/rc.local a file in which you can list programs that are started up at boot time. The programs should success fully run and exit with the status 0, and they must not continuously run in which case they need to be started in background.

To make sure you do not forget it, simply add the following line at the end of your program

exit 0

indicating that the start was successful. Programs in rc.local must use the absolute file path.

4.6.2 Crontab

Crontab is a service the schedules jobs that can run at various times repeatedly. For example we can use crontab to run commands every hour, every day, every half hour or other time intervals or at reboot.

To use crontab follow these steps

Open a terminal and enter the command

$ crontab -e

If you are doing this for the first time, you will be asked to chose an editor. Please, choose your favorite editor

To run the program at boot time, add the following line to the at the end of the file

 @reboot <command>

Let us look at an example and assume we have test.py program in your home directory at /home/pi/test.py. Once you add it to crontab with

 @reboot python /home/pi/test.py

it will be run at boot time

It is important to provide the absolute path to the file. In case your file produces output you need to redirect it into a file

  @reboot python /home/pi/test.py > /home/pi/test.log

When the raspberry pi reboots, the program will run automatically.

4.6.3 References

A good introduction to the various methods is provided at

https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

For more information on crontab see for example:

http://www.adminschoice.com/crontab-quick-reference

4.7 Pi Software Collection ⭕ ☁️

Please improve the sections.

4.7.1 Web Programming

4.7.1.1 Coder

Targeted at the very beginner to Web programming, we will not use this here.

https://googlecreativelab.github.io/coder/

provide a section

4.7.2 Computing

4.7.2.1 Numpy

Refer to other section in book and describe what is different

provide a setcion

4.7.2.2 Scipy

Refer to other section in book and describe what is different

provide a setcion

4.7.2.3 Image Processing

Refer to other section in book and describe what is different

provide a setcion

4.7.3 System

4.7.3.1 DHCP Server

http://www.noveldevices.co.uk/rp-dhcp-server

4.7.3.2 hostname

The hostname is stored in /etc/hostname. Edit the file and change it to a name such as green00, green01, green02, green03, green04, green05. Be consistent with the names. The 00 host should be the top most host in the cluster.

edit

nano /etc/hostname

after you edited the hostname

sudo /etc/init.d/hostname.sh start

Ideally we want to find out how to write the hostname after we burn the SD card on the laptop that does the burning

develop a python script to do that

4.7.3.3 Gather the mac addresses

Is there a better way?

/sys/class/net/<interface-name>/address

cat /sys/class/net/eth0/address
cat /sys/class/net/wlan0/address
ifconfig eth0

develop a python script to do that

4.7.3.4 Enable SSH

Not tested

sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc
sudo reboot

http://www.noveldevices.co.uk/rp-ssh

⚠️ Not sure if this is needed:

" You may find that you can connect to your Pi with SSH but the session hangs after a successful logon. This is usually caused because of a network QoS mismatch that affects certain switches and routers but you can correct this by editing the two files

/etc/ssh/ssh_config
/etc/ssh/sshd_config

and adding

IPQoS 0x00

to each file as the last record. " THis is quoted and needs the citation

Develop a a python script to do that

4.7.3.5 USB stick

cat /var/log/messages

find sda*

Make sure to find the right name.

sudo fdisk /dev/<device-name>
sudo mkfs -t vfat /dev/<device-name>
mkdir ~/<mount-point>
sudo mount /dev/<device-name> ~/<mount-point>

4.7.3.5.1 DHCP server on 00

sudo apt-get update
sudo apt-get install isc-dhcp-server
sudo nano /etc/network/interfaces

Change it to

iface eth0 inet static
address <the-IP-address-of-your-Pi-that-will-be-the-DHCP-server>
netmask <the-subnet-mask-of-your-LAN>
gateway <the-IP-address-of-your-LAN-gateway>
sudo nano /etc/dhcp/dhcpd.conf

uncomment the info so the server can start

subnet <starting-IP-address-of-your-network> netmask <starting-IP-address-of-your-network> {

     range <first-IP-address-of-your-DHCP-address-range> <last-IP-address-of-your-DHCP-address-range>;

     option routers <the-IP-address-of-your-gateway-or-router>;

     option broadcast-address <the-broadcast-IP-address-for-your-network>;

}

edit /etc/default/isc-dhcp-server

DHCPD_CONF=/etc/dhcp/dhcpd.conf
DHCPD_PID=/var/run/dhcpd.pid
INTERFACES="eth0"

sudo service isc-dhcp-server restart

4.7.3.6 Temperature

cat /sys/class/thermal/thermal_zone0/temp

4.7.3.7 grafana

could be helpful to monitor cluster/clusters

https://github.com/grafana/grafana

https://github.com/weaveworks/grafanalib

there are many more, just search. we have not tested them example with yaml

https://github.com/jakubplichta/grafana-dashboard-builder

light scheme

in /etc/grafana/grafana.ini uncomment line and set

default_theme = light

5 Setting up tho OS on Multiple Pi’s ☁️

While it is relatively easy to set up a single Pi, we quickly find that when we have to set up 100 or more of them this poses a significant challange.

5.1 Cluster Setup ⭕ ☁️

In this section we discuss how we setup the cluster. To explore that we can conduct the setup without monitor, we are collecting in this section a variety of tasks in regards to it and documenting solutions for them. Students in the residential or in the online classes that participate in cluster building can contribute to this section.

A number of students have been assigned for particular tasks. and will be added here by the TA’s. It is expected that you conduct your task ASAP.

5.1.1 Links

A number of useful links may help for this task. However be aware that we want to develop a script for most of the tasks eliminating input by hand. The information here deals to identifying the information needed to do so.

https://hackernoon.com/raspberry-pi-headless-install-462ccabd75d0

https://installvirtual.com/enable-ssh-in-raspberry-pi-without-monitor/

According to

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

rasp-config writes a file /boot/config.txt. Maybe it is a good idea to inspect this file manipulate it and see if there are field we simply could write and overwrite it on the SD card. See also

https://elinux.org/R-Pi_configuration_file

5.1.1.1 Creating Backup ❓

❓ In this section we will explain how to create a backup of the image from the SD Card in a PI.

5.1.1.2 Duplication ❓

Let us assume you have installed a lot of great programs on the SD Card. In a cluster, we need to duplicate this card for each PI in the cluster. Is there a way for us to duplicate the software

5.1.2 System Preparation without Monitor

⭕ there is lots of duplication here to the ultimate setup

5.1.2.1 hostname

Find a way on how to name the host as each of the cluster nodes will need its own unique name. We simple use color01, where color is the color of the USB cables you have and the number is the ith PI starting from the top

5.1.2.2 SSH

Describe how you enable SSH without a monitor

5.1.2.3 key

Describe how you can generate a private key at the right location on the SD Card. Place your own public key on the SD Card

Write python programs for this.

5.1.2.4 password

Describe how you can change the password on the SD Card

5.1.3 Post configuration

5.1.3.1 Network Addresses

Find a way to find all the network addresses from all Pi’s attached to the network switch.

5.1.3.2 key

Write a python program that does the following:

login with ssh on each PI and call ssh-keygen to generate a unique key on each PI.

copy this .pub keys to your computer and store them into a file called authorized_keys

copy that file to all Pis

you may also have to copy your authorized key file to

5.1.3.3 VNC

find out how to set up vnc so you can login into the PI and see its GUI

https://www.raspberrypi.org/forums/viewtopic.php?t=74176

https://www.raspberrypi.org/documentation/remote-access/vnc/

host$ alias IP=<IPADDRESSOFPI>
host$ sh pi@$IP

pi@IP's password:
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Feb 3 20:00:00 GMT 2018 armv6l
pi@raspberrypi ~ $ sudo apt-get tightvncserver   # download the VNC server
pi@raspberrypi ~ $ tightvncserver                # start the VNC server
pi@raspberrypi ~ $ vncserver :0 -geometry 1920x1080 -depth 24  #start a VNC session

Now, back on your Mac: In the Finder, select Go => Connect To Server… Type vnc://xxx.xxx.xxx.xxx (where xxx.xxx.xxx.xxx is the IP address that you discovered in step 2. Click [Connect]. This will launch the Screen Sharing application, and with a little luck, you should see this image.

5.1.4 Add-on Hardware

recently ordered add on hardware

power switches

https://www.amazon.com/dp/B01DE57SD4/ref=psdc_6396124011_t2_B075WZJL6N

SD Card Writers

https://www.amazon.com/Collection-MicroSD-MicroSDHC-MicroSDXC-Kingston/dp/B01IF7TPMS/ref=sr_1_15?s=electronics&ie=UTF8&qid=1518271583&sr=1-15&keywords=Micro+SD+Card+writer

6 Traditional Cluster Technologies ☁️

This section contains some traditional cluster technologies, that may be helpful even for the creation of cloud clusters. For example it is possible to host such clusters via REST services on the Web or leverage technologies from them that simplify the building of cloud clusters.

6.1 Network of Pis (NOW) ☁️

Network of workstations

Have a number of PIs available on a network to which we can login and execute tasks on.

Elementary to most other cluster deployment activities

Uses ssh key from a server to login to all Pis

6.1.1 Parallel Shell

TODO

6.1.2 Cloudmesh Parallel

TODO

6.1.3 Other Parallel Execution

TODO

https://www.rittmanmead.com/blog/2014/12/linux-cluster-sysadmin-parallel-command-execution-with-pdsh/

https://www.linux.com/news/parallel-ssh-execution-and-single-shell-control-them-all

https://www.tecmint.com/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines/

https://github.com/vallard/psh

https://github.com/karrick/psh/blob/master/psh

6.2 Message Massing Interface Cluster ☁️

For more information on this topic see:

https://thenewstack.io/installing-mpi-python-raspberry-pi-cluster-runs-docker/

https://www.hackster.io/darthbison/raspberry-pi-cluster-with-mpi-4602cb

https://www.meccanismocomplesso.org/en/cluster-e-programmazione-in-parallelo-con-mpi-e-raspberry-pi/

6.3 SLURM ⭕ ☁️

This may be inspiring

https://github.com/ajdecon/ansible-pi-cluster/blob/master/README.md

6.3.1 Installation

provide a information

6.3.2 Configuration

provide a information

6.3.3 Example MPI program

provide a information

6.3.4 Using the Batch Queue

provide a information

6.3.5 REST Services

develop OpenAPI REST services to interact with the cluster

6.4 PXE Booting ⭕ ☁️

TODO: Problem description

TODO: provide an example architecture drawing

TODO: provide the actual steps

6.4.1 Resources

Network booting information can be found here:

https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net_tutorial.md

http://web-docs.gsi.de/~bloeher/howto/rpi3_netboot.html

6.5 Fortan ☁️

Although this section is not about parallel programming, you may find still that many scientific programs are written in fortran. For some smaller fortran programs it is even possible to run them on a Raspberry pi. Naturally you will need to install a fortran compiler, which you can do with

pi$ sudo apt-get install gfortran

To test it out store the following program into hello.f90

program hello
    print *, "Hello World!"
end program hello

Now you can compile it with

pi$ gfortran -o hello hello.f90

Execute it with

pi$ hello

7 Cloud Clusters ☁️

In this chapter we will be looking at a number of clusters that are typically associated with cloud computing this includes

docker

docker swarm

kubernetes

hadoop

spark

If you know about other efforts let us know and we add them here.

7.1 Docker ☁️

Docker is a tool that allows us to deploy applications inside of software containers. A container allows a developer to package the application along with dependencies associated with it and put all in a box which is an isolated environment so that the underlying host operating system is completely abstracted from the application running inside the box.

It is a method of packaging software, to include not only our code, but also other components such as a full file system, system tools, services, and libraries. This can be useful for the Raspberry Pi because it allows users to run applications without lot of steps, as long as the application is packaged inside of a Docker image. We simply install Docker and run the container.

According to the developers of Docker it includes the following features:

Portability

Density

Scalability

Security

7.1.1 Installation

First we need to make sure the Raspberry Pi is up to date so we can install a recent version of docker. The automated script maintained by the Docker project will create a systemd service file and copy the relevant Docker binaries into /usr/bin/.

pi$ sudo apt-get update
pi$ curl -sSL https://get.docker.com | sh

In order for us to start the docker daemon at the next boot, we add it as follows:

pi$ sudo systemctl enable docker

Now if we reboot, the Docker daemon will start. In case you like to avoid the first reboot, you can use the command:

pi$ sudo systemctl start docker

Naturally you do not have to do this after you reboot the next time.

The Docker client can only be used by root or members of the docker group. Thus, let us add the user pi (or your equivalent user) to the docker group using:

pi$ sudo usermod -aG docker pi

After executing the above command, we log out of the terminal restart it so we are sure the user permissions are available in the shell we use.

To test docker is installed successfully, we run the hello-world docker image with the command:

pi$ docker run hello-world

If Docker is installed properly, we will see a Hello from Docker! message.

7.1.2 Docker Swarm

Swarm is a native clustering and scheduling tool for Docker. Instead of just managing containers on a single server, we can manage containers on a set of servers. The containers will be automatically scheduled on the pool of servers making them appear as a single resource. We will set up and use Docker on a number of Raspberry Pi’s install Docker on them and register them into a Docker Swarm.

7.1.3 Creating a Network of Pi’s with docker

In Section ??? we explained how to set up a network of PI’s. Here we assume that we start from such a network. The Pi’s have all different names, and are registered on the network. Each Pi has the public key installed from the machine where you will login from for setting up the swarm.

Let us assume the names of the hosts are stored in a shell variable called

hostnames = (red00 red01 red02 red03 red04)

Naturally, we want to install on these machines docker and register them to the swarm. A variety of tools exist to simplify this process, such as

parallel shell https://github.com/vallard/psh

cloudmesh parallel (TODO: find the link)

For now we use this simple shell program to install docker on each of the hosts in the hostnames

hostnames = (red00 red01 red02 red03 red04)
for host in "${hostnames[@]}"
do
      ssh pi@$host curl -sSL https://get.docker.com | sh
done

Save this script in a file called docker-install.sh and set the executable rights with

chmod u+x docker-install.sh

When we execute it with

$ docker-install.sh

It will sequentially install docker on each host. This is not very efficient and only works for a small number of hosts.

7.1.4 Registering the Pi to the Swarm

Next we need to run on one of the nodes the management node for the swarm to which all others servers register as workers. Although we could run on this node als a worker, we will just run the manager on it as we want to avoid overloading it and make sure it operates smoothly.

We select the first host in our hostlist for it called red00 Let us assume the host has the ipaddress <manager-ip-address>. We can log into this computer and execute the command

$ sudo docker swarm init --advertise-addr <manager-ip-address>:2377

This command will print out a token that we can use on the workers to register with our swarm. The token will look something like:

SWMTKN-abc...xyz

Let us use the term <token> to indicate the token. To register a worker a two step process is used.

If you ever forget the token, you simply can use the following command on the manager

$ docker swarm join-token worker

It will print out the command that you will have to execute on a worker.

$ sudo docker swarm join --token SWMTKN-abc...manager...xyz <manager-ip-address>:2377

To see the list of nodes, you can use the command

I $ sudo docker node ls

7.1.5 Docker Cheat Sheet

The following table is copied from the docker manual

.

Purpose | Command
Image |
Build an image | docker image build –rm=true .
Install an image | docker image pull ${IMAGE}
List of installed images | docker image ls
List of installed images (detailed listing) | docker image ls –no-trunc
Remove an image | docker image rm ${IMAGE_ID}
Remove unused images | docker image prune
Remove all images | docker image rm $(docker image ls -aq)
Containers |
Run a container | docker container run
List of running containers | docker container ls
List of all containers | docker container ls -a
Stop a container | docker container stop ${CID}
Stop all running containers | docker container stop $(docker container ls -q)
List all exited containers with status 1 | docker container ls -a –filter “exited=1”
Remove a container | docker container rm ${CID}
Remove container by a regular expression | docker container ls -a | grep gregor | awk ‘{print $1}’ | xargs docker container rm -f
Remove all exited containers | docker container rm -f $(docker container ls -a | grep Exit | awk ‘{ print $1 }’)
Remove all containers | docker container rm $(docker container ls -aq)
Find IP address of the container | docker container inspect –format ‘{{ .NetworkSettings.IPAddress }}’ ${CID}
Attach to a container | docker container attach ${CID}
Open a shell in to a container | docker container exec -it ${CID} bash
Get container id for an image by a regular expression | docker container ls

7.1.6 Exercise

Swarm.1

Your task is is to identify technologies to execute the Installation in parallel. Suitable technologies include

psh

ansible

puppet

python threads

cloudmesh

We like that the class is split up in groups and each group develops this solution. Naturally you can test this first with not installing docker, but with a simple command such as uname -a

Swarm.2

Develop a python cloudmesh command called

cms swarm config hostnames.yaml

where the yaml file looks something like

manager: <ip00>
worker:
- <ip01>
- <ip02>
- <ip03>

Similarly create other convenient functions such as

cms swarm kill, which kills the swarm

cms swarm ls, which gives details about the swarm

7.2 Kubernetes (A) ⭕ ☁️

In this section we discuss how to set up a kubernetes cluster on a number of Raspberry Pi’s.

7.2.1 Todo

[ ] all the simple setup with sd cards, ssh, keys, and so on should be moved to the NOW cluster section. This way we can require simply a NOW and start without duplication on the real kubernetes install.

[ ] weh ave two sections of kubernetes contributed by two students. what we need is to merge them and safe the usable things. we need to identify if the setup is significantly different before we can do this.

[ ] so before you can work on teh kubernetes section you need to make sure the NOW section is up to date.

7.2.2 Resources Needed

We recommend that the cluster will have at least one master and three worker nodes. Using less resources so the system is not unnecessarily slow. Please give us feedback on this and let us know hwat works for you. so we integrate your feedback.

We assume that you have installed docker and disabled swap

First install docker, disable swap, install kubeadm

All the following steps are made automatically by the 526/docker_kubernetes_install.sh script.

7.2.2.1 Install docker

In order to install kubernetes you first need to have docker installed. This is very strait forward.

7.2.2.2 Disable swap memory

Docker is not compatible with SWAP memory, therefore we need to disable swap. This might create some other issues. If you encounter them you should try to reboot the cluster again, if that fails change line 16 in the docker_kubernetes_install.sh

orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_memory=1"

to

orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_memory=memory"

7.2.2.3 Installing kubernetes administrator

Finally, to configure kubernetes you’ll need kubeadm. Now the Pi needs to be rebooted.

⚠️ All of this will be done by the script, donot worry (maybe worry)

7.2.2.4 Configure the nodes

All of the above needs to be done in each node as-well. The script

kubernetes/copy_dk_kub_install_script_to_nodes.sh

should copy the needed script to each of them and run it. It is set up to work with 4 nodes named rp<number> with pi as the username (the numbers start at 1 because the head node is rp0). Changing the number of nodes is trivial, if all of your nodes have the same username it is also trivial.

If your nodes are not configured like that you’ll need to change this script or copy docker_kubernetes_install.sh to each of the nodes manually. We plan on making this script independent on the number of nodes.

7.2.3 Files

417/kubernetes/adm_kub_config.yaml

417/kubernetes/config_kub.sh

417/kubernetes/copy_dk_kub_install_script_to_nodes.sh

417/kubernetes/docker_kubernites_install.sh

417/kubernetes/issues_todo.md

417/kubernetes/kube_install_and_config_readme.md

417/kubernetes/useful_links.txt

7.2.4 Refernces

https://gist.github.com/alexellis/fdbc90de7691a1b9edb545c17da2d975

https://cloud.google.com/solutions/real-time/kubernetes-redis-bigquery

https://kubecloud.io/setup-a-kubernetes-1-9-0-raspberry-pi-cluster-on-raspbian-using-kubeadm-f8b3b85bc2d1

https://www.hanselman.com/blog/HowToBuildAKubernetesClusterWithARMRaspberryPiThenRunNETCoreOnOpenFaas.aspx

https://marcussmallman.io/2018/02/18/diy-rasberry-pi-kubernetes-cluster/

7.3 Raspberry Pi Kubernetes Cluster (B) ⭕

This section will guide the steps towards setting up a Kubernetes Pi cluster. The steps are:

Setting up static IP

Secure ssh key setup for communication

Kubernetes cluster setup

Automating the process

Cluster needs:

One head/master Pi

number of follower nodes Pi

router [optional]

Pis can be connected directly to the home’s Internet router. Please note that a router is needed when portability is a criteria.

7.3.1 Initial Setup

Some Pi kits come with pre installed SD card if not then:

format the SD card: https://www.sdcard.org/downloads/formatter_4/eula_windows/

Download the package from: https://www.raspberrypi.org/downloads/noobs/

Download and unzip the package and copy it to the SD card (Copy only the files inside NOOBS_{version})

Connect the power cable, keyboard and mouse to the Pi

Insert the SD card and the installed will walk you through the installation process

Once the installation is through make sure the time and keyboard setting are updated according to your local settings Normally they come in UK settings

7.3.2 Setting up Static IP and HostName

The hostname can be given by clicking the top right

wifi icon> network setting>

The window can be launched by

    $ raspi-config

command i the terminal or by:

    $ sudo nano /etc/hostname

static IP similarly can be given by

⚠️ TODO: sentence incomplete

Hostname can be given by clicking the top right

wifi icon> network setting>

make sure you give both eth0 and wlan0 setting for both LAN and Wifi communication

or by ensuring the following in for LAN and Wifi config /etc/dhcpcd.conf

⚠️ TODO no I in the text

I have added the following alternatively eth0 block can be added if wired setup is preferred

interface wlan0
static ip_address=<desired IP>/24
static routers=<router IP>
static domain_name_servers=<DNS server IP>

Ensure that the desired IP falls with in the assigned IP range of your router. As we will be automating the process later, its advised to follow a naming sequence for the hostname or IP address.

Example:

kub00[192.168.56.100], kub01 [192.168.56.101], kub02 [192.168.56.102]...

It is essential to reboot the system for the changes to take effect.

7.3.3 SSH setup

Ensure that ssh is enabled in the Pi:

Click on the Raspberry Pi Configuration from the Preferences on run the command

sudo raspi-confi

in the terminal. Go to Interface tab and enable SSH

In the terminal run:

sudo systemctl enable ssh
sudo systemctl start ssh

With the static ip setup and ssh enabled you should be able to ssh in to the Pi. For passwordless access setup the SSH key as per the following step

Generate the ssh key; make sure you give a passcode: ssh-keygen -t rsa Copy the generated public key ~/.ssh/id_rsa.pub` to the other computers for passwordless acessssh-copy-idorssh-import-id`` can be used for the purpose as well

7.3.4 Cluster setup

First install Docker with

curl -sSL get.docker.com | sh && \ sudo usermod pi -aG docker

[optional] Command to run Docker as a non root user: sudo usermod -aG docker pi

Next turn off swap:

sudo dphys-swapfile swapoff && \
sudo dphys-swapfile uninstall && \
sudo update-rc.d dphys-swapfile remove

Now Edit /boot/cmdline.txt and add the following with a space [no new line]

cgroup_enable=cpuset cgroup_memory=1

Setup kubeadm with

  $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \
  echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \
  sudo apt-get update -q && \
  sudo apt-get install -qy kubeadm

The process till now stays the same for both workers and master

7.3.5 Master setup

In the master node initiate the master:

    $ sudo kubeadm init --token-ttl=0 --apiserver-advertise-address=<internal master ip>

This will initiate the kubectl head. At the end of the this process, there should be an echo with the following text. Save this join token as you will joining the workers later:

    $ kubeadm join --token <token> --discovery-token-ca-cert-hash <ca hash>

Once the master is initiated, now set up the kubectl admin config

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

The final step is setting up the networking. I have used weave.

  kubectl apply -f \
 "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

7.3.6 Worker setup

After Kubernetes installation, join the workers using the saved join token.

Use get nodes in the master to check the status

kubectl get pods --namespace=kube-system can be used to check the pod status of the cluster

7.4 Raspberry PI Hadoop Cluster ⭕ ☁️

7.4.1 Todo

[ ] all the simple setup with sd cards, ssh, keys, and so on should be moved to the NOW cluster section. This way we can require simply a NOW and start without duplication on the real kubernetes install.

[ ] so before you can work on the section you need to make sure the NOW section is up to date.

7.4.2 Links

See another effort documented at:

Benchmarking Hadoop and Spark on Mutiple Platforms http://cyberaide.org/papers/vonLaszewski-cloud-vol-9.pdf#page=27&zoom=100,0,96

7.5 Raspberry PI Spark Cluster ⭕ ✋ hid: 24 ☁️

7.5.1 Todo

[ ] all the simple setup with sd cards, ssh, keys, and so on should be moved to the NOW cluster section. This way we can require simply a NOW and start without duplication on the real kubernetes install.

[ ] so before you can work on the section you need to make sure the NOW section is up to date.

[ ] The section contains some issues

[ ] A per node setup is used instead of a scripted setup

[ ] Some text in the later part is unclear

7.5.2 Links

See another effort documented at:

Edge Computing and Big Data Processing using Raspberry Pi Naveen Kaul http://cyberaide.org/papers/vonLaszewski-cloud-vol-9.pdf#page=104&zoom=100,0,96

Benchmarking Hadoop and Spark on Mutiple Platforms http://cyberaide.org/papers/vonLaszewski-cloud-vol-9.pdf#page=27&zoom=100,0,96

7.5.3 About

We provide step-by-step instructions on installing a Spark cluster on a pre-installed hadoop on a cluster of raspberry pi. To start we assume you have Hadoop installed. This is achieved by following the instructions provided in

⚠️ this link needs to be changed, we also need to identify if the hadoop install for pi is different from the regular hadoop install

http://cyberaide.org/papers/vonLaszewski-bigdata.pdf

to install Hadoop on Pi cluster. Verify that the cluster is properly installed. After that proceed by going to the home directory

$ cd ~

7.5.4 Download

Download the most recent version from the Apache website (we use here version 2.3.0).

⚠️ if a newer version is available, your task will be to use the newer version and create a new updated set of instructions. At this time the newest version is 2.3.0. Please double check.

[Apache Spark]

Run the command

wget http://apache.claz.org/spark/spark-2.3.0/spark-2.3.0-bin-hadoop2.7.tgz

7.5.5 Installation

Create the folder for storing spark install files

$ sudo mkdir -p /opt/spark-2.3.0
$ sudo chown -R hduser:hadoop /opt/spark-2.3.0

Unzip the tar fle into destination folder

bash tar -xzf spark-2.3.0-bin-hadoop2.7.tgz -C /opt/spark-2.3.0 --strip-components=1

Update the PATH variable

$ echo "export SPARK_HOME=/opt/spark-2.3.0" >> ~\.bashrc
$ echo "export PATH=$PATH:$SPARK_HOME/bin" >> ~\.bashrc
$ echo "export PATH=$PATH:$SPARK_HOME/sbin" >> ~\.bashrc
$ source ~/.bashrc

Copy the template from spark-env.sh.template to spark-env.sh

$ cp $SPARK_HOME/spark-env.sh.template $SPARK_HOME/spark-env.sh

Edit spark-env.sh file to change configurations

$ nano $SPARK_HOME/spark-env.sh

Edit slaves file on master node

$ cd $SPARK_HOME/conf
$ cp slaves.template slaves
$ nano slaves

Update the configurations

SPARK_MASTER_HOST = 169.254.24.132
SPARK_WORKER_MEMORY = 512m

⚠️ it is possible to write a script doing this

Add the hostnames to the file

pimaster (hostname of master node)

pislave01 (hostname of worker slave 01)

pislave02 (hostname of worker slave 02)

⚠️ it is possible to write a script doing this

7.5.6 Test Setup

Run spark-shell from the command line. You will have succeed if you see something like this

Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.3.0
      /_/

Using Scala version 2.11.8 (Java HotSpot(TM) Client VM, Java 1.8.0_65)

Repeat above steps on all worker/slave nodes

⚠️ it is unclear which steps these are

Alternative to running above steps for each worker node, you can run the the following command on each worked node to create spark directory

$ sudo mkdir -p /opt/spark-2.3.0`
$ sudo chown -R hduser:hadoop /opt/spark-2.3.0

Run next you can copy the configuration as follows:

$ rsync -avxP /opt/spark-2.3.0 hduser@pislave:/opt

Run the previous command only after creating the /opt/spark-2.3.0 on all worker nodes

$ sudo mkdir -p /opt/spark-2.3.0
$ sudo chown -R hduser:hadoop /opt/spark-2.3.0

⚠️ this seems duplicated

Next you need to set the spark home and add it to your path on all worker nodes

$ echo "export SPARK_HOME=/opt/spark-2.3.0"
$ echo "export PATH=$PATH:$SPARK_HOME/bin"
$ source ~/.bashrc

Finally you need to start the spark server and workers by running the master command on the master and the salve command on the slaves

Run this on the master:

$SPARK_HOME/sbin/start_master.sh

Run this on the slave:

$SPARK_HOME/sbin/start_slaves.sh

To test it out use the following URL:

http://master_host_name:8080

8 🚧 DRAFT DRAFT ☁️

8.1 Automated Headless Configuration of a Pi Cluster ⭕ ☁️

Our goal is perform the following configuration automatically:

Enable ssh permanently (initial ssh access will be enabled when we burn the SD cards)

Change the password

Set up one of the Pis as a DHCP server

These actions are all done with two scripts. The first script, configure-pi.sh, runs on the computer used to set up the Pis. The second, setup-pi.sh, enables ssh, changes the password for the pi user, and configures the master node as a DHCP server. Determination of whether the node is the master or a worker is done with the -m flag.

8.1.1 Prerequisites

Assemble a Pi Cluster

Burn SD cards with names changed and ssh enabled

Install expect on computer running configure-pi.sh. On a Mac, this is done with brew install expect. On Unix, use apt-get install expect or yum install expect. More information on expect can be found here.

8.1.2 Setting up DHCP

⚠️ this tutorial is insecure! ⚠️

TODO: Find out if cluster should be set up with or without internet enabled. Tutorial for getting Pi on IU Secure here.

TODO: New version of isc-dhcp-server. Find out if INTERFACES in /etc/default/isc-dhcp-server should be V4, V6 or both.

TODO: Switch is eth8 when internet sharing is off, names show up, and IP addresses are on different subnet. When internet sharing is on, names do not show up. How should DHCP and network be setup? What is the use case? Below is output of arp -a with internet sharing. I turned it on so that installations via apt-get would work:

(2.7.13) BKS-MBP:project-code bsobolik$ arp -a
hello (192.168.1.1) at 58:ef:68:a9:51:4e on en0 ifscope [ethernet]
bertoltksiphone.hsd1.in.comcast.net (192.168.1.126) at e4:9a:79:7f:19:55 on en0 ifscope [ethernet]
? (192.168.1.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
? (192.168.2.7) at b8:27:eb:0:c3:55 on bridge100 ifscope [bridge]
? (192.168.2.8) at b8:27:eb:d1:21:33 on bridge100 ifscope [bridge]
? (192.168.2.255) at ff:ff:ff:ff:ff:ff on bridge100 ifscope [bridge]
? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
? (239.255.255.250) at 1:0:5e:7f:ff:fa on en0 ifscope permanent [ethernet]
broadcasthost (255.255.255.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]

When internet sharing is off I get:

(2.7.13) BKS-MBP:~ bsobolik$ arp -a
raspberrypi.local (169.254.177.219) at b8:27:eb:0:c3:55 on en8 [ethernet]
? (169.254.255.255) at (incomplete) on en0 [ethernet]
hello (192.168.1.1) at 58:ef:68:a9:51:4e on en0 ifscope [ethernet]
? (192.168.1.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
broadcasthost (255.255.255.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]

☁️ ## Preparing the SD card ⭕

TODO: We should at this time assume we have an OS.

Download the latest Raspbian Jessie Lite image from

https://www.raspberrypi.org/downloads/raspbian/

Please note that Raspbian Jessie Lite image contains the only the bare minimum amount of packages.

8.1.3 Download Etcher ⭕

https://etcher.io/

Now follow the instructions in Etcher to flash Raspbian image on the SD card. Before ejecting the SD card do the following.

8.1.4 Enable SSH on the SD Card ⭕

To prevent Raspberry Pis from being hacked the RPi foundation have now disabled SSH on the default image. So, create a text file in /boot/ called ssh - it can be empty file or you can type anything you want inside it.

Please note that you have renamed the ssh.txt to ssh i.e. without extension.

Now insert the SD card, networking and power etc.

8.1.5 Starting Pi ⭕

Once you boot up the Raspberry Pi, Connect using SSH

    $ ssh pi@raspberrypi.local

The password is raspberry.

For security reasons, please change the default password of the user pi using the passwd command.

Note: If you want to change the hostname of the Pi, Use an editor and change the hostname Raspberry Pi in:

    * /etc/hosts
    * /etc/hostname

8.2 Raspberry Pi Robot Car with Face Recognition and Identification ☁️

I523, HID319, SP18-711, mkagita@iu.edu

8.2.1 Introduction

A Computer Vision application which has always encouraged people, concern about the capability and capacity of robots and computers to determine, detect, recognize and interact with human beings ???. We will prevail the advantage of cheaper tools that are available in the market for computing and detecting a human face from the image, recognizing the face using hardware like Raspberry Pi and a video camera that is dedicated to Raspberry Pi. Simple and open source software like OpenCV is used to detect a human face from the video that is being captured and the image will be sent to Kairos face recognition software which allows a high-level approach to this process.

In this fastest information era, every information is travelled in a split of a second. There is much more need for accurate and fastest methods for identifying, recognizing and authentication of humans. In the present world, face recognition had become most important and crucial form of human identification methods. As per Literature survey statistics in face recognition, the two trends to receive significant attention for the past several years are; the first is the law enforcement applications and also a wide range of commercial techniques, and the second is exponential booming of applications and feasible technologies after 30 years of research [2].

The aim is achieved by a possibility to locate human beings or identities like faces from the live video capture and within the context of the picture. Most advanced human detection applications have this functionality already available. When the picture is captured and loaded into the system, it will scan the picture and will look for human faces in it. The current implementation is to detect face and register them with a name. If the face is detected and not recognized, Robot car will ask to register the detected face with a name. If the human is already registered in Kairos, then once the face is detected, Robot car will greet the human with the associated name.This whole process determines the Face detection and Face recognition techniques using Raspberry Pi and Robot car.

Facial biometric data is to be computed first in creating a complete recognition system. This biometric data is then compared with the face database and to associate with the human identity. The difference between a human and machine is, a human can easily and quickly identify characteristics of a human face but then can only save few hundreds of faces. Whereas a machine or computers prevails at storing and mapping human characteristics and meta data. In the current generation, facial recognition software can identify a human face within millions of images from the database in seconds. Humans tend to forget human faces as time pass by. Machines store them forever. Most of the Law firms across the world follow the process and spend huge money on the development of these facial recognition systems that can easily identify criminals in real-time. A well-known example is studying human faces in airports and bus stations.

The design of the Robot car integrated with Face recognition system will navigate through dangerous or natural disaster locations where humans unable to enter. Robot car while avoiding obstacles on its way, will continuously monitor for human faces who got stuck or in danger and will recognize the faces based on the user database. Once the human face is recognized, it will intimate to corresponding authorities about the human and will help in guiding assistance.

8.2.2 Face Detection

Face Detection is a technique referred to computer vision technology which is able to identify human faces within digital images [3]. Face detection applications work using algorithms and machine learning formulas for detecting human faces in the visual images. Identifying only human faces from these images which can contain landscapes, houses, animals is called Face Detection technique.

Face Detection is termed to only identify if there are any humans present in the image or a video. It lacks the inability to recognize which human face is present. Common widely used face detection techniques are in auto-focus of a digital camera. During auto-focus, camera lens will look for human faces in the range and identify them to have focus in that particular area. Face Detection techniques will be widely used in counting how many numbers of visitors attending a particular event.

8.2.2.1 How Face Detection Works

While Face Detection process is somewhat complex, the algorithms will start off by searching for human eyes at first. Eyes usually represent a valley region and its the easiest feature in human face to detect. Once the eyes are detected, then the algorithms will look for rest of the characteristics of a human face such as iris, nose, mouth, eyebrows, and nostrils. Face detection algorithm then summarizes the data and shows that it has successfully detected a human face from the facial region. Additional tests can be conducted by the algorithm to make sure and validate if the human face is detected [4].

8.2.3 Face Recognition

Like most of the biometric solutions, face recognition technology will be used for identification and authentication purposes by measuring and matching the unique facial characteristics of a human face. Using a digital camera connected to the Raspberry Pi, once the face is detected, face recognition software will quantify the characteristics of face and then will match with the stored images in the database. Once the match is positive, then the corresponding name will be displayed as output [5].

Facial biometrics can be integrated with any system having a camera. Border control agencies use face recognition to verify identities of the travellers and can separate them from the trespassers. Government Law agencies replace all the security cameras around the world with biometric applications to scan faces in CCTV footage and to identify persons of interest in the field. Face recognition has become one of the fastest and human un-intervention techniques to find out the identity of a particular human [5].

For the past few years, Face recognition has become one of the most commonly used biometric authentication techniques. It mainly deals with the pattern recognition and analyzing the images. Two main tasks of face recognition are: Face Verification and Face Identification. Face Verification is comparing a human face in an image with a template image and recognizing the correct patterns. Face Identification is comparing human face in an image with multiple images in the database. Face recognition techniques have more advantages than any other biometrics. With well-sophisticated algorithms and coding, face recognition has a high recognition rate or high identification rate of more than 90% [2].

Figure 4: Block Diagram of a Face Recognition System

TODO: +@#fig:face-recognition must be cited in text

8.2.3.1 Face Recognition and Big Data Analysis

Face Recognition and Big Data are two distinct technologies which are having hardly anything in common. But when they both are put together, a technology drift takes place in terms of biometric authentication. Storing a massive unique characteristics and libraries of human faces, algorithms are used to run on these characteristics to recognize the human face accurately. Using big data, a real-time analysis can be done which identifies faces and applies the rules as they are happening.

Robot car is designed to collect all the facial features that are encountered on its path and store them in the cloud. When the face is detected by the camera, it sends the picture to the cloud and facial recognition software will compare with huge database of faces that are located in the cloud. Once the face features match, robot car will respond with the unique name that is set for that human face.

8.2.4 Software and Hardware Specifications

OpenCV is to be installed in Raspberry Pi to detect human faces within the captured images. Kairos face recognition software is used to recognize a human face and identify with the corresponding name.

8.2.4.1 Software Used

8.2.4.1.0.1 Raspbian OS

This is the recommended OS for Raspberry Pi 3. Raspbian OS is Debian based operating system. It can be installed from NOOBS installer. Raspbian comes with various pre-installed software such as Python, Sonic Pi, Java, Mathematica for programming and education.

8.2.4.1.0.2 Putty

PuTTY is an SSH and telnet client for the Windows platform. PuTTY is open source software that is available with source code and is developed and supported by a group of volunteers. Here we are using putty for accessing our Raspberry Pi remotely.

8.2.4.1.0.3 OpenCV

Open Source Computer Vision Library (OpenCV) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code. The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects and extract 3D models of objects [6].

8.2.4.1.0.4 Python 2 IDE

Python 2.7.x version Integrated Development Environment is used to compile python program in Raspberry Pi. IDE is a text editor plus terminal combination which is used to work on large projects with complex code bases.

8.2.4.1.0.5 Kairos Face Recognition Software

Kairos is an artificial intelligence company specializing in face recognition. Through computer vision and machine learning, Kairos can recognize faces in videos,photos, and the real-world. A captured image is sent to Kairos using an API call and then Kairos will search with the face database. If it matches then will reply with the human name.

Identity

Emotions

Demographics

Kairos navigates the complexities of face analysis technology.

8.2.4.2 Hardware Used

8.2.4.2.0.1 Raspberry Pi 3

Raspberry Pi 3 is the latest version of Raspberry Pi. Unless previous versions, this have an inbuilt Bluetooth platform and a wifi support module. There are total 40 pins in RPI3. Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins). There are 4 USB ports, 1 Ethernet slot, one HDMI port, 1 audio output port and 1 micro USB port. And also we have one micro SD card slot wherein we have to install the recommended operating system on the micro SD card. There are two ways to interact with your Raspberry Pi. Either you can interact directly through HDMI port by connecting HDMI to VGA cable, and keyboard and mouse or else you can interact from any other system through Secure Shell (SSH) [7].

8.2.4.2.0.2 Raspberry Pi Camera

The Raspberry Pi camera module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners but has plenty to offer advanced users if you’re looking to expand your knowledge. There are lots of examples online of people using it for time-lapse, slow-motion and other video cleverness. You can also use the libraries we bundle with the camera to create effects.

8.2.4.2.0.3 Robot Car Chassis Kit

The Mechanical design of the Robot car includes hardware such as motor and wheel placement and body set-up. Robot car uses two gear-motors attached to wheels and one free-wheel for having various movements like forward, backward, left and right. Free-wheel ball is placed at the rear side of the robot which helps for 360 degrees free movement [8]. L298N DC Stepper Motor Drive controller is used to control the speed and direction of the two gear motor wheels. Ultrasonic sensors are placed on the front side of the robot which is capable to detect the objects on its path [9].

8.2.5 System Architecture

System Architecture consists of following blocks:

Raspberry Pi

Raspberry Pi Camera Module

L298N Dual H-Bridge Stepper Motor Controller

DC power supply 12v and 5v

Robot Car chassis kit

HC-SR04 Ultrasonic Sensor

SG90 Servo Motor.

Wires, Breadboard, Small PCB.

8.2.6 Setup

8.2.6.1 Connect Raspberry Pi

This section includes connectivity of Raspberry Pi to wifi.

Download Raspbian operating system to an SD card with a minimum capacity of 8GB.

Plugin USB power cable, keyboard, mouse and monitor cables to Raspberry Pi.

Insert the SD card with Raspbian OS into Pi and boot the system. Once the Pi is booted up, a window will appear with the Raspbian operating system. Click on Raspbian and Install.

Once the install process has completed, the Raspberry Pi configuration menu (raspi-config) will load. Here set the time and date for your region.

Enable wifi located at the upper right corner of the desktop and connect to wifi sid.

8.2.6.2 Connect Raspberry Pi Camera Module

Before setting the camera configurations, first connect the camera to Raspberry Pi. The cable slots into the connector situated between the Ethernet and HDMI ports, with the silver connectors facing the HDMI port. Once the connection is completed, boot up the Raspberry Pi and run the following commands to install various supporting libraries. Skip first two steps if Python is already installed on Raspberry Pi.

pi$ sudo apt-get install python-pip
pi$ sudo apt-get install python-dev
pi$ sudo pip install picamera
pi$ sudo pip install rpio

Once the libraries are installed, follow below steps to check if camera is installed in Raspberry Pi.

pi$ sudo raspi-config

If the camera option is not listed in the options, run the following commands to update Raspberry Pi.

pi$ sudo apt-get update
pi$ sudo apt-get upgrade

8.2.6.2.0.1 Enable Camera

For face detection, PiCamera should be enabled from Raspberry Pi. The following list of figures shows the detailed steps on how to enable PiCamera.

As shown in Figure [F:raspi], execute the configuration command from terminal. From the listed options, select “Enable Camera” as shown in Figure [F:selcamera]. Click on “Yes” option to enable the camera interface as shown in Figure [F:enbcamera].

TODO: use the figure citation as in teh first figure

Enable Camera

Enable Camera

Enable Camera

8.2.6.3 Install OpenCV and Required Libraries

OpenCV computer vision library is used to for face detection from the live video streaming. Execute the following commands to install OpenCV dependencies on the Raspberry Pi.

TODO: add a pi$ in fornt of commands

sudo apt-get install build-essential
sudo cmake pkg-config python-dev libgtk2.0-dev \
        libgtk2.0 zlib1g-dev libpng-dev \
        libjpeg-dev libtiff-dev libjasper-dev \
        libavcodec-dev swig unzip

Select yes for all options and wait for the libraries and dependencies to be installed.

Download opencv-2.4.9 zip file to Raspberry Pi. Change to the corresponding directory and execute the following commands.

cd opencv-2.4.9
sudo apt-get install build-essential cmake \
        pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev \
        libjasper-dev libpng12-dev
sudo apt-get install python-dev python-numpy \
        libtbb2 libtbb-dev libjpeg-dev \
        libpng-dev libtiff-dev libjasper-dev \
        libdc1394-22-dev
sudo apt-get install python-opencv
sudo apt-get install python-matplotlib

After executing the commands the latest version of OpenCV is now installed in Raspberry Pi. Time taken to install OpenCV is about 15 minutes.

8.2.6.4 Integration of Raspberry Pi with Robot Car

Raspberry Pi connected with PiCamera is integrated with Robot car to navigate using a web server. During the navigation, robot car will look for human faces using PiCamera and then detects the face. Once the face is detected, python program will call Kairos face detection software to identify the person and greet with the name. If the human face is unidentified then robot car will ask human to register their name. The diagram in Figure [F:circuit] shows the circuit connections of Raspberry Pi to stepper motor controller and DC motors of a robot car.

Raspberry Pi Robot Car Integration

Figures [F:robotfront], [F:robotside], [F:robottop] represents corresponding front view, sideview and topview of the robot car connections.

Top view of Robot Car

Top view of Robot Car

Top view of Robot Car

In the Table [T:pinlayout], shows the connectivity of Raspberry Pi GPIO pins to L298N stepper motor controller.

8.2.6.5 Actuator Raspberry Pi GPIO Pin L298N Pin

Motor1A GPIO23 IN1 Motor1B GPIO24 IN2 Motor1Enable GPIO25 ENA Motor2A GPIO9 IN3 Motor2B GPIO10 IN4 Motor2Enable GPIO11 ENB

: Pin connections of Raspberry Pi to stepper motor controller

8.2.6.6 Kairos Face Recognition Setup

Kairos Face Recognition system has a free developer account which is used to identify the human name from the images. Once registered a human name with an image, the code will call Kairos API with a newly detected human face and will look for the registered name. Kairos will do a quick look-up in the human database from the registered account and if it matches, will send the name of the human back to the code.

Setup as follows:

Register with Kairos using url “https:/www.kairos.com” as a free developer account

Login with registered username and password

Create an appname

An app id and a key will be generated. Save this for future use.

Enroll a sample user and a gallery name with the user image using following POST request.

    POST /enroll HTTP/1.1
    Content-Type: application/json
    app_id: your-app-id
    app_key: your-app-key
    {
    "image":" http://media.kairos.com/user.jpg ",
    "subject_id":"User",
    "gallery_name":"MyGallery"
    }

With the completed steps, Kairos face recognition application will be created and ready for face recognition from the images.

8.2.7 Code Explanation

8.2.7.1 Face Detection

Before configuring face detection for the robot car, related libraries including PiCamera and PiRGBArray libraries for camera to operate should be imported in the code. These libraries will help to capture video and images from the PiCamera.

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import sys
import imutils
from fractions import Fraction
import base64
import requests
import json
import random
import os

Haar Feature-based cascade classifier is an effective face or object detection method to capture the frontal features of the face [10]. This tool will help to continuous monitoring of any human face to detect. Once detected a human face, the output values will provide as Human Face Detected from the capturing video.

## Get user supplied values
cascPath = './haarcascade_frontalface_default.xml'

## Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

Camera settings need to be updated in the code as per below suggestions. The captured image is to be sent to Kairos for face recognition and so we will set the resolution to a lower level. This will help to send the image faster over the network without any delay.

## initialize the camera
#camera capture
camera = PiCamera()
camera.resolution = (160, 120)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(160, 120))

Below code represents PiCamera continuously monitor for human faces detected from the grayscale video capture. Once the human face is detected, espeak function in Raspberry Pi will send the voice to a connected speaker and will output as “Human face detected”. This detected image is then saved as “User-Image.jpg” which is then will be sent to Kairos during Face recognition.

Images in Figures [F:frontview], [F:sideview1], [F:sideview2] represents face detection of front and side views within the circle using OpenCV.

Side view 2 Face detection

Side view 2 Face detection

Side view 2 Face detection

## allow the camera to warm-up
time.sleep(0.1)
lastTime = time.time()*1000.0
## capture frames from the camera
for frame in camera.capture_continuous(rawCapture, \
    format="bgr", use_video_port=True):
    ## grab the raw NumPy array representing the image,
    ## then initialize the timestamp and
    ## occupied/unoccupied text
    image = frame.array
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    ## Detect faces in the image
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags = cv2.cv.CV_HAAR_SCALE_IMAGE
    )
    print time.time()*1000.0-lastTime," \
    Found {0} faces!".format(len(faces))
    lastTime = time.time()*1000.0

    ## Draw a circle around the faces
    for (x, y, w, h) in faces:
        cv2.circle(image, (x+w/2, y+h/2), \
        int((w+h)/3), (255, 255, 255), 1)
    ## show the frame
    cv2.imshow("Frame", image)
    key = cv2.waitKey(1) & 0xFF
    if len(faces) == 1:
        print("Taking image...")
    camera.capture("foo.jpg")
    os.system('espeak "Human face detected"')
    inputImage= "./foo.jpg"
    del camera
    break
    ## clear the stream in preparation for the
    #next frame
    rawCapture.truncate(0)

    ## if the `q` key was pressed, break from
    #the loop
    if key == ord("q"):
        del camera
        exit()

8.2.7.2 Face Recognition

For the Face Recognition, we use Kairos to detect the facial characteristics. A JSON config file is to be placed in the same folder as of the code with Kairos API app id and key value. When the human face is detected, the code will generate an API call to Kairos software along with the gallery name, API app id and key values. Image when sending to Kairos, it will be base64 encrypted and will send over the network for security purpose. This encrypted image will then be decrypted at Kairos platform.

KAIROS = "api.kairos"
KairosGallery = 'MyFace'
KairosConfig = './kairos_config.json'

def trainKairos(image, name):
    global KairosGallery
    headers = {
        'app_id': 'your-app-idd39fc1b1',
        'app_key': 'your-app-key'
    }
    data = {
        'image': base64.b64encode(image),
        'gallery_name': KairosGallery,
        'subject_id': name
    }
    r = requests.post('http://api.kairos.com/enroll', \
        headers=headers, data=json.dumps(data))
    print(r.text)
    return(None)

class Recognize():
    def __init__(self, API, config_file):
        self.api = API
        self.config = config_file

    #def recognize(self, image_path):
    ##    return self.__recognizeKairos(image_path)

    def recognizeKairos(self, image):
        with open(image, "rb") as image_file:
            encoded_string = base64.b64encode\
            (image_file.read())
        with open(self.config, "rb") as config_file:
            config = json.loads \
            (config_file.read())
        data = {
            "image": encoded_string,
            "gallery_name": config["gallery_name"]
        }

        headers = {
            "Content-Type": "application/json",
            "app_id": config["app_id"],
            "app_key": config["app_key"]
        }

The output from Kairos software is in JSON format. The output is then segregated as per the key-value pairs and then saved into local variables. When the image is recognized, a success transaction message will be obtained from Kairos along with subject id and face id.

try:
    r = requests.post("https://api.kairos.com/recognize", \
                 headers=headers, data=json.dumps(data))
    data = r.json()
    print data
    ## print json.dumps(data, indent=4)
    faces = []
    if "images" in data:
        for obj in data["images"]:
            if obj["transaction"]["status"] == \
            "success":
                face_obj = {}
                face_obj["person"] = \
                obj["transaction"]["subject_id"]\
                .decode("utf_8")
                #face_obj["faceid"] = \
                obj["candidates"][0]["face_id"]\
                .decode("utf_8")
                face_obj["confidence"] = \
                obj["transaction"]["confidence"]
                faces.append(face_obj)
            elif obj["transaction"]["status"] == \
            "failure":
                face_obj = {}
                face_obj["person"] = "unidentified"
                face_obj["confidence"] = 0
                faces.append(face_obj)
            else:
                print "its in last loop"
            return faces
 except requests.exceptions.RequestException as \
 exception:
       print exception
        return None

The output from Kairos face recognition software is to be read to understand if the person name is identified or not. If it is identified then the person name will be listed according to the corresponding person in the image. If the human is not identified, then the code will suggest if the user wants to registered for face recognition. Once the user key in the name, Kairos API call is generated while sending newly registered name and the gallery name to that corresponding application id. Here the newly recognized user will be registered with the name and his image. When the user is recognized by the camera in next corresponding events, then Robot car will greet the user with his name.

if __name__ == "__main__":
    r = Recognize(KAIROS, "kairos_config.json")
    x = r.recognizeKairos(inputImage)

    #print x
    #print x["person"]
    #print x[0]["person"]
    string1 = x[0]["person"]
    #print string1
    os.system('espeak "Hello...""{}"'.format(string1))
    if x[0]["person"] == "unidentified":
        os.system('espeak "Please enter your \
                  name to Register"')
        nameToRegister = raw_input("Please enter \
                        your name to Register :")
        binaryData = open(inputImage, 'rb').read()
        print('Enrolling to Kairos')
        trainKairos(binaryData, nameToRegister)
        print "You are now Registered as :", \
        nameToRegister os.system('espeak \
        "Hello...""{}"'.format(nameToRegister))
        exit()

8.2.7.3 Robot Car Navigation

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

#Connecting two wheel motors to Raspberry Pi GPIO
#Left Motor (Motor 1) connections
Motor1A = 16 #(GPIO 23 - Pin 16)
Motor1B = 18 #(GPIO 24 - Pin 18)
Motor1Enable = 22 #(GPIO 25 - Pin 22)

#Right Motor (Motor 2) Connecctions
Motor2A = 21 #(GPIO 9 - Pin 21)
Motor2B = 19 #(GPIO 10 - Pin 19)
Motor2Enable = 23 #(GPIO 11 - Pin 23)

#Ouptut of Morors to set as OUT
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1Enable,GPIO.OUT)
GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2Enable,GPIO.OUT)

## Defining function for Robot car to move forward
def forward():
    GPIO.output(Motor1A,GPIO.HIGH)
    GPIO.output(Motor1B,GPIO.LOW)
    GPIO.output(Motor1Enable,GPIO.HIGH)
    GPIO.output(Motor2A,GPIO.HIGH)
    GPIO.output(Motor2B,GPIO.LOW)
    GPIO.output(Motor2Enable,GPIO.HIGH)

    sleep(2)

## Defining function for Robot car to move backward
def backward():
    GPIO.output(Motor1A,GPIO.LOW)
    GPIO.output(Motor1B,GPIO.HIGH)
    GPIO.output(Motor1Enable,GPIO.HIGH)
    GPIO.output(Motor2A,GPIO.LOW)
    GPIO.output(Motor2B,GPIO.HIGH)
    GPIO.output(Motor2Enable,GPIO.HIGH)

    sleep(2)

## Defining function for Robot car to turn right
def turnRight():
    print("Going Right")
    GPIO.output(Motor1A,GPIO.HIGH)
    GPIO.output(Motor1B,GPIO.LOW)
    GPIO.output(Motor1Enable,GPIO.HIGH)
    GPIO.output(Motor2A,GPIO.LOW)
    GPIO.output(Motor2B,GPIO.LOW)
    GPIO.output(Motor2Enable,GPIO.LOW)

    sleep(2)

## Defining function for Robot car to turn left
def turnLeft():
    print("Going Left")
    GPIO.output(Motor1A,GPIO.LOW)
    GPIO.output(Motor1B,GPIO.LOW)
    GPIO.output(Motor1Enable,GPIO.LOW)
    GPIO.output(Motor2A,GPIO.HIGH)
    GPIO.output(Motor2B,GPIO.LOW)
    GPIO.output(Motor2Enable,GPIO.HIGH)

    sleep(2)

## Defining function for Robot car to stop
def stop():
    print("Stopping")
    GPIO.output(Motor1A,GPIO.LOW)
    GPIO.output(Motor1B,GPIO.LOW)
    GPIO.output(Motor1Enable,GPIO.LOW)
    GPIO.output(Motor2A,GPIO.LOW)
    GPIO.output(Motor2B,GPIO.LOW)
    GPIO.output(Motor2Enable,GPIO.LOW)

8.2.7.4 Controling Robot Car using webserver

from flask import Flask, render_template, \
request, redirect, url_for, make_response
import RPi.GPIO as GPIO
import motors

#set up GPIO
GPIO.setmode(GPIO.BOARD)

#set up flask server
app = Flask(__name__)

#when the root IP is selected, return index.html page
@app.route('/')
def index():

    return render_template('index.html')

#recieve which pin to change from the button press on \
#index.html
#each button returns a number that triggers a command in \
#this function
#
#Uses methods from motors.py to send commands to the GPIO \
## to operate the motors
@app.route('/<changepin>', methods=['POST'])
def reroute(changepin):

    changePin = int(changepin) #cast changepin to an int

    if changePin == 1:
        motors.turnLeft()
    elif changePin == 2:
        motors.forward()
    elif changePin == 3:
        motors.turnRight()
    elif changePin == 4:
        motors.backward()
    else:
        motors.stop()

    response = make_response(redirect(url_for('index')))
    return(response)

#set up the server in debug mode to the port 8000
app.run(debug=True, host='0.0.0.0', port=8000)

8.2.8 Applications

There are lots of applications of face recognition. Face recognition is already being used to unlock phones and specific applications. Face recognition is also used for biometric surveillance. Banks, retail stores, stadiums, airports and other facilities use face recognition to reduce crime and prevent violence.

8.2.9 Conclusion

A robot car using Raspberry Pi is designed to detect and recognize the human faces from the images taken from PiCamera attached to the Raspberry Pi. Using Python programming language, the system is being built such that it can face detect and recognize in real time scenarios. For this solution Kairos Face recognition software is being used which have a free developer account. Face recognition is tested with various types of facial views like the front view and side view. The Round Trip Time for robot car to take picture and recognize face is nearly 3 seconds. The efficiency of the system was analysed based on the rate of face detection in real time. As per the analysis, this current system shows tremendous performance efficiency where the face detection and recognition can be performed even with very low-quality images.

The authors would like to thank Dr. Gregor von Laszewski for his support and suggestions in writing this paper.

8.2.10 Links

The code is located at

https://github.com/cloudmesh-community/hid-sp18-711/tree/master/project-code

Refernces ☁️

[1] G. von Laszewski, F. Wang, H. Lee, H. Chen, and G. C. Fox, “Accessing Multiple Clouds with Cloudmesh,” in Proceedings of the 2014 acm international workshop on software-defined ecosystems, 2014, pp. 21–28 [Online]. Available: http://doi.acm.org/10.1145/2609441.2609638

[2] S. B. Y. Riddhi Patel, “A literature survey on face recognition techniques,” International Journal of Computer Trends and Technology, vol. 5, p. 189, Nov. 2013.

[3] B. B. M. Divyarajsinh N. Parmar, “Face recognition methods & applications,” Int.J.Computer Technology & Applications, vol. 4, pp. 84–86, 2013 [Online]. Available: https://arxiv.org/ftp/arxiv/papers/1403/1403.0485.pdf

[4] J. D. WEST, “FACE detection vs. FACE recognition.” FACEFIRST, May-2017 [Online]. Available: https://www.facefirst.com/blog/face-detection-vs-face-recognition/

[5] BIOMETRICS, “Facial recognition.” FINDBIOMETRICS, Jan-2014 [Online]. Available: https://findbiometrics.com/solutions/facial-recognition/

[6] OpenCV, “About opencv.” OpenCV, 2017 [Online]. Available: https://opencv.org/about.html

[7] D. Technologies, “MQTT to connect raspberry pi to internet of things.” HACKADAY, Sep-2017 [Online]. Available: https://hackaday.io/project/27344-mqtt-to-connect-raspberry-pi-to-internet-of-things

[8] Arduino, “Arduino software (ide).” 2015 [Online]. Available: https://www.arduino.cc/en/Guide/Environment

[9] G. von Laszewski, “ESP8266.” Indiana University, Sep-2017 [Online]. Available: https://cloudmesh.github.io/classes/lesson/iot/esp8266/esp8266.html

[10] P. Viola and M. Jones, “Rapid object detection using a boosted cascade of simple features,” in Computer vision and pattern recognition, 2001. CVPR 2001. Proceedings of the 2001 ieee computer society conference on, 2001, vol. 1, pp. I–511–I–518vol.1 [Online]. Available: http://http://ieeexplore.ieee.org/abstract/document/990517