RASPBERRY PI 2 TUTORIAL SYSTEM UTILITY HACKS IN A PIESHELL ____________________________________________________________________________ Dr. Marcus O. Durham, PhD, ThD www.ThewayLabs.com Version: 151226 Contents - GETTING STARTED ............................................................................................................................................3 1.0 Overview .................................................................................................................................................................................3 2.0 Websites..................................................................................................................................................................................4 3.0 Hardware Required...........................................................................................................................................................5 4.0 Micro SD .................................................................................................................................................................................5 5.0 Micro SD Formatting ........................................................................................................................................................6 6.0 NOOBS Operating System...............................................................................................................................................6 7.0 Install Raspian OS Image ................................................................................................................................................7 8.0 Power Supply........................................................................................................................................................................7 9.0 Startup Issues .......................................................................................................................................................................8 10.0 Get Everything Up To Speed. .........................................................................................................................................8 - - ..............................................................................................................................................................................................8 - SHELL, DESKTOP, & NORMAL DEVICES .......................................................................................8 11.0 LXDE Desktop vs LXTerminal .......................................................................................................................................8 12.0 Command Line .....................................................................................................................................................................9 13.0 System Shutdown ............................................................................................................................................................ 10 14.0 Nano Text Editor ............................................................................................................................................................. 11 15.0 Raspi-Config Menu.......................................................................................................................................................... 11 16.0 Configuration File ........................................................................................................................................................... 12 17.0 Monitor ................................................................................................................................................................................ 12 18.0 Sound .................................................................................................................................................................................... 13 19.0 Keyboard ............................................................................................................................................................................. 13 20.0 Touchscreen Display ...................................................................................................................................................... 14 21.0 Powered USB ..................................................................................................................................................................... 15 22.0 Mount USB Drives ........................................................................................................................................................... 15 - - ........................................................................................................................................................................................... 16 - REPRODUCTION................................................................................................................................................. 16 23.0 Set Up a Production System........................................................................................................................................ 16 24.0 Copy SD Card Image for Easy Reinstallation...................................................................................................... 16 25.0 Clone SD Card Image ..................................................................................................................................................... 17 - - ........................................................................................................................................................................................... 18 - NETWORKS & HEADLESS OPERATION ........................................................................................ 18 DrMOD Raspberry Pi 2 in a Pieshell pg 2 26.0 Ethernet Hardwire.......................................................................................................................................................... 18 27.0 WiFi........................................................................................................................................................................................ 18 28.0 Ethernet Set-Up ................................................................................................................................................................ 19 29.0 Check network operation, IP Address, & MAC address .................................................................................. 20 30.0 Remote Control: Command Line - SSH .................................................................................................................. 20 31.0 Desktop Control: GUI - VNC ........................................................................................................................................ 21 32.0 Desktop Control : GUI – VNC Auto start................................................................................................................ 22 33.0 iPad Control: VNC ........................................................................................................................................................... 25 34.0 VNC Cut & Paste ............................................................................................................................................................... 25 35.0 File Transfer - SSH .......................................................................................................................................................... 26 36.0 Detachable SSH – tmux Terminal Multiplexer .................................................................................................. 27 37.0 Tmux to Join a Running Program ............................................................................................................................ 28 - - ........................................................................................................................................................................................... 28 - AUTO LOGIN & AUTO START ................................................................................................................. 28 38.0 Autostart Apps in LXDE GUI ....................................................................................................................................... 28 39.0 Autostart at reboot using crontab: ......................................................................................................................... 29 40.0 Create Desktop File: ....................................................................................................................................................... 30 41.0 Create Desktop File to Edit GPIO: ............................................................................................................................ 30 42.0 Autostart tmux session with script ......................................................................................................................... 31 43.0 AutoLogin to Terminal Shell Prompt ..................................................................................................................... 31 - - ........................................................................................................................................................................................... 32 - ADVANCED NETWORK SOLUTIONS ................................................................................................ 32 44.0 Creating a Variety of Networks ................................................................................................................................ 32 45.0 Ethernet Annals: Interfaces ........................................................................................................................................ 34 46.0 Ethernet Annals: Wpa_supplicant ........................................................................................................................... 38 47.0 Simple Ad Hoc – Peer to Peer ..................................................................................................................................... 39 48.0 Broadcasting Ad Hoc – Peer to Peer....................................................................................................................... 40 49.0 DHCP Server....................................................................................................................................................................... 41 50.0 Wireless Access Point: hostapd ................................................................................................................................. 42 51.0 Network Address Translation: IP Routing between Ethernet and Wireless ........................................ 44 52.0 DNS Server.......................................................................................................................................................................... 45 53.0 Handy Commands for Testing & Start/Stop Network ................................................................................... 45 54.0 IP Address, Subnet, Net Mask, SSID, and Other Mysteries ............................................................................ 49 55.0 Glitch from Power Saver .............................................................................................................................................. 50 56.0 Network Storage (NAS) Between Pi & Windows .............................................................................................. 51 - - ........................................................................................................................................................................................... 54 - KEEPING UP ........................................................................................................................................................... 54 57.0 Update-Upgrade .............................................................................................................................................................. 54 DrMOD Raspberry Pi 2 in a Pieshell pg 3 58.0 Version, etc. information.............................................................................................................................................. 55 59.0 Errors with Peripherals & Files ................................................................................................................................ 55 60.0 GPIO as non-Root, PiFace ............................................................................................................................................ 57 61.0 Add Member to Group ................................................................................................................................................... 57 62.0 Add or Remove Software ............................................................................................................................................. 58 63.0 Search for Software........................................................................................................................................................ 58 64.0 Find Location of File ...................................................................................................................................................... 58 65.0 File Changes Using Windows PC .............................................................................................................................. 59 66.0 Printer .................................................................................................................................................................................. 59 67.0 Disk Drive ............................................................................................................................................................................ 61 68.0 Two Disk Drives with Redundancy .......................................................................................................................... 63 - - ........................................................................................................................................................................................... 64 - HATS ............................................................................................................................................................................... 64 69.0 DS3231 RealTime Clock (RTC).................................................................................................................................. 64 70.0 PiFaceDigital ..................................................................................................................................................................... 65 71.0 PiFaceDigital vs GPIO .................................................................................................................................................... 66 72.0 BrickPi .................................................................................................................................................................................. 67 - - ........................................................................................................................................................................................... 67 - THE REFERENCES ............................................................................................................................................ 67 73.0 Command Line Instructions ....................................................................................................................................... 68 74.0 More Linux Instructions ............................................................................................................................................... 69 75.0 Nano Editor Shortcuts .................................................................................................................................................. 70 π CAUTION: Copying text commands from a Word file will introduce formatting caused errors. Before use on the Pi, all formatting must be removed, such as using Notepad to clean-up. 1.0 GETTING STARTED Overview The Raspberry Pi is a full blown computer in an inexpensive package. The device was initially designed as an educational learning tool. The board has also become popular as a functional computer for hobbyists and commercial use. Since the machine is a computer, it is programmable. Software can basically be divided into two different purposes. One set is system utilities which control normal computing functions and interfaces for the computer. DrMOD Raspberry Pi 2 in a Pieshell pg 4 The other set is applications to accomplish a task with the computer. This document provides a tutorial of the system utilities. Another paper provides methodology to connect to the outside world for a task. This file is notes about how to implement and enhance common utilities to make a computer system. Details about the machine, operating system, and installation are readily available at other locations. The system operates under a variation of Linux. The most common version is Rasbian. An app called Noobs is the preferred way to install the operating system. A micro SD card can be purchased with the operating system installed. I prefer to start at ground zero as a learning tool and a larger card is available. When purchasing the computer, card, and components, be cautious of knockoffs which are common. There are numerous sections in the instructions, which are not necessary for normal operations. However, these are required for specific functions. At one-time or another, I have used all these chores. After all this is a powerful computer, which will be used in many different ways. CAUTION: The following information was what I was using at the time of the writing. My first RPi was totally command line driven, with some gui functions available. My latest Rpi is almost totally Gui driven, with little command line requirements. Much of the information has already changed with updates to Raspian. Regardless, the information is still valuable for those times you need a hard-core solution. Happy Hacking! Computer Hacker: Someone who skillfully repurposes a computer system to his own idea. π 2.0 Websites Numerous websites are dedicated to the Pi. Some of the more useful are listed. Official site: Distributor: Sales: Better: Hacking: Hack2: More: Projects: Peripherals: https://www.raspberrypi.org/ http://www.element14.com/ http://www.newark.com/ http://www.amazon.com/s?ie=UTF8&page=1&rh=i%3Aaps%2Ck%3ARaspberry%20Pi http://www.howtogeek.com/search/?q=rapberry+pi http://lifehacker.com/5976912/a-beginners-guide-to-diying-with-the-raspberry-pi http://www.raspberrypi-spy.co.uk https://www.adafruit.com/category/105 http://elinux.org/RPi_Peripherals#Wireless:_TP-Link_TLWN722N_USB_wireless_adapter_.28Debian_6.29 DrMOD Raspberry Pi 2 in a Pieshell Wireless http://spin.atomicobject.com/2013/04/22/raspberry-pi-wireless-communication/ π 3.0 1. Hardware Required For normal computer operations, the following hardware items are necessary. a. Raspberry Pi circuit board b. Micro SD card for memory c. Keyboard with usb connector d. Mouse with usb connector e. Monitor with HDMI input and cable or Touchscreen display f. Ethernet cable for network connection g. Power supply with micro USB connector rated 5V, 700 ma – 2 A. h. WiFi adapter. Official Rpi is best, Edimax works but is low power. Others fall short. 2. The Raspberry Pi has connections for necessary hardware to operate initially. Connect these devices before power-up, so appropriate drivers are installed. 3. Additional hardware is likely to be added for connections. a. PiFace Digital 2 is used to interface to outside switches and loads. b. BrickPi is used to interface to robots associated with Legos. c. Powered usb port d. Portable power supply. 4. Jumper wires for projects should be premium grade to reduce irritating, hard to find failures. Normal spacing of headers is 0.1 inch with 0.025” pin. Jumper wire female/female, female/male, male/male. Reportedly good brands are Schmartboard, OSEPP. π 4.0 1. Micro SD A Micro Secure Digital (SD) card is used as memory to hold the 'bios' and data. 2. Use class 10 for faster write speeds. The minimum size is 8 GB. Since this is storage for everything, 32 GB or more may be desirable. 3. Be careful to avoid fake manufacturer and off-brands, which are prone to errors. 4. The Micro SD needs a system label to preclude erratic initialization by the operating system. π pg 5 DrMOD 5.0 Raspberry Pi 2 in a Pieshell Micro SD Formatting 1. The micro SD is inserted with an adapter into the Windows PC’s external memory slot. 2. Format the card so the Pi can read it. a. Download the SD Association’s Formatting Tool: https://www.sdcard.org/downloads/formatter_4/eula_windows/ b. 3. Install and run the Formatting Tool on your PC. Check that the micro SD card you inserted matches the one selected by the Tool. a. Be sure to give the card a Label. Rpi b. Click the “OPTIONS” menu. Set “FORMAT SIZE ADJUSTMENT” option to “ON” c. Click the “Format” button. Format the entire disk as FAT 32. π 6.0 NOOBS Operating System 1. NOOBS is the easiest way to transfer the operating system to the SD card. The system is faster and much of the setup is completed. 2. The micro SD is inserted with an adapter into the Windows PC’s external memory slot. Format SD card as shown above. 3. Download the New Out Of Box Software (NOOBS) . www.raspberrypi.org/downloads/noobs 4. Unzip the downloaded file. Right-click on the file then select: “Extract All”. 5. Copy the files to the Micro-SD card. 6. When the process is complete, safely eject the card from the drive. Remove from adapter. Plug the card into the Raspberry Pi. 7. 8. The Raspian Jessie OS opens in the GUI. Click on Menu > Preferences >Raspi-Config π pg 6 DrMOD Raspberry Pi 2 in a Pieshell ----------------------------------------- 7.0 1. Install Raspian OS Image The Raspian operating system is available as an image, which is configured for use. 2. The Micro SD is inserted with an adapter into the Windows PC’s external memory slot. Format the SD card as shown above. 3. A direct image of the operating system can be transferred to the SD card. The operating system (OS) image can be downloaded as an alternate method to the NOOBS . In addition, a clone can be installed, by skipping to step 6. 4. Download a direct image of Raspian. The file is without helps, but is claimed by some to work better with certain issues. That has not been my experience. The download file moves, but should be findable. https://www.raspberrypi.org/downloads/raspbian/ 5. Unzip the downloaded file. Right-click on the file then select: “Extract All”. 6. This requires an image-writing tool available from SourceForce. Be careful, their download includes SEIZE-WARE. Do a manual install, if given the option. http://sourceforge.net/projects/win32diskimager/ 7. Clean up and delete SIEZE-WARE including all the Yahoo overhead and undesirable junk. 8. Extract the executable from the zip file. Win32DiskImager 9. Right click the file to run as administrator. Browse to the file image. Browse will NOT get a network file, so it must be copied to the PC . Select the drive associated with the SD card. Click Write 10. When the process is complete, safely eject the card from the drive. Remove from adapter. Plug the card into the Raspberry Pi. π ----------------------------------------- 8.0 Power Supply 1. The power supply needs a Micro usb connector and rating of 5V, 700 - 2000 ma. An iPad power adapter with the micro usb connector is excellent. Plug in the power supply to start the Pi. No switch is used. pg 7 DrMOD Raspberry Pi 2 in a Pieshell 2. Two LEDs are on board to clue the Pi is working. PWR is the Red led, which comes on when voltage is adequate. 3. ACT is the Green led connected to a Gpio pin. The ACT led flickers intermittently when the micro SD is initially starting for 10-20 seconds. π 9.0 Startup Issues 1. If you have a problem starting the computer, then try the following: Reengage micro SD, gently push on micro SD, reengage power plug. 2. If the ACT led flickers, but the monitor does not show, turn the monitor off then on to reset. 3. If still have problems, hold ‘Shift’ key down while booting to display operating systems. If display remains blank, force the correct output mode by pressing the number keys on keyboard. a. HDMI mode - default display mode. b. HDMI Safe Mode - select if using the HDMI connector and cannot see anything on screen c. Composite PAL Mode - select the PAL or NTSC if using the composite RCA video connector. d. Composite NTSC mode 4. The display should go to the Raspi-Config menu, where most changes can be made. If for some reason it does not, then a more hands on approach is outlined below. π CAUTION: Always issue a shutdown command before unplugging the power supply. 10.0 Get Everything Up To Speed. 1. Now the SD is installed, power is applied, with screen and keyboard running, it is time to work. π - SHELL, DESKTOP, & NORMAL DEVICES 11.0 LXDE Desktop vs LXTerminal 1. LXDE (Lightweight X11 Desktop Environment) is a Graphical User Interface (GUI). LXTerminal is the standard terminal emulator for the LXDE. LXDE GUI uses a more visual display of screens, icons, and menus. LXTerminal uses Command Line instructions to perform system functions. The corollary is to a PC with Windows versus DOS commands. pg 8 DrMOD Raspberry Pi 2 in a Pieshell pg 9 2. The Pi now starts in the GUI with autologin. The login can be changed in Raspi-Config. The default log in is shown. Username: pi Password: raspberry 3. Once logged in, the machine is a working computer with fantastic capabilities. 4. To start the GUI desktop from the command prompt, type: This command is deprecated with the newer GUI login startx 5. To open the command prompt window from GUI, click the monitor icon on the toolbar. Alternately, at Menu > Run type: lxterminal 6. The command lxterminal [options] has several options to perform additional tasks. Lxterminal command may be used inside scripts and as a desktop call. 7. Notice the Pi has two processors. The CPU is for calculation tasks. The GPU is for graphical tasks. π ----------------------------------------- 12.0 Command Line 1. Most operations will be performed in the GUI Window, but some functions are machine intensive. In the proceeding instructions, many are performed at the command line. So, it is necessary to grasp at least the basics. 2. The Rasbian operating system is based on Linux which is based on Unix. The ancient operating system (ca 1980) was a contemporary of DOS and is very text oriented. The program which processes the commands is called bash (Bourne Again Shell). 3. The shell is takes commands from the keyboard and gives them to the operating system. In the normal operation of terminal mode, a command line is used to set-up operations on the Pi. The command line is initiated by the prompt: pi@raspberrypi $. The prompt can be changed for different users. 4. For specific operations, simply copy the given code, like any good hacker. 5. A very convenient tool is the up-arrow, which prevents much retyping. Each click causes the display of the previous command line, which is showing your command history. DrMOD Raspberry Pi 2 in a Pieshell pg 10 Scroll until arriving at the line you want. Modify or reenter. 6. TAB will complete a line if you are part way through, providing the command is recognized as valid. If there is more than one way to complete the line, double tapping the TAB key will show all of them. 7. The command instructions are shown later, if you want to use the terminal screen. 8. Copy of information from outside of the terminal uses normal hotkeys. To paste back into the terminal, right click the mouse and the copy is pasted immediately. The old saw “right click is your friend” is definitely true. 9. One term which will show up is ‘daemon’, which is a program that will start when the Pi boots. π ----------------------------------------- 13.0 System Shutdown 1. The system should always be shutdown gracefully to protect hardware, firmware, and software. ‘Unofficial hard reboot’ means simply pulling the plug. The results may be catastrophe. 2. In the GUI desktop, select >Menu, > shutdown. Options are provided for the type of shutdown which is desired. 3. At the command line, multiple options are also available. 4. To reboot the system, at prompt type: sudo reboot. Alternately type: sudo shutdown –r. 5. To halt operations, at command prompt type: sudo halt. Alternately type: shutdown –h 6. For delayed shutdown, at prompt type: sudo shutdown –h time. Time can be in minutes or as a 24 hour:minute such as: sudo shutdown –h 15:30. 7. The process takes nearly a minute before the ACT line flickers last and the monitor reports loss of signal. π DrMOD Raspberry Pi 2 in a Pieshell pg 11 ----------------------------------------- 14.0 Nano Text Editor 1. Nano is an editor used to edit files, particularly configuration directives and set-up files. Notice that on the Pi, files do not have an extension, which tells the type of file or the program to use. Nano is used in the terminal window, where few options exist. 2. The editor is very simple using arrows to navigate and equally cryptic instructions. The mouse is not effective and will create mess-ups such as making you think you are on wrong line. Be careful, you will change operations and may corrupt files. 3. To open files, at prompt type: nano /directory/filename 4. Certain files need higher authority and are opened with sudo nano. System files should be opened with the –w switch to disable text wrapping and protect certain errors. sudo nano -w /etc/fstab 5. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 6. When editing configurations, reboot may be necessary on exit. 7. Copy and paste uses a different set of hotkeys, Alt+6 and Ctrl+U respectively. Numerous shortcuts are available to speed-up using the editor. Available nano shortcuts are shown in another section. Mouse ‘right click’ will paste text from outside nano and the terminal. π ----------------------------------------- 15.0 Raspi-Config Menu 1. Raspi-config is a menu which assists in set-up of some common functions. Click >Menu >Preferences > Raspi Config 2. Then set up localization and other options. Internationalization: Locale: en_us.utf-8 Time: us-central Keyboard: generic 101 English (US) Default keys Advanced: A4, SSH enable A0, update this tool Tab to Finish, <Enter>. DrMOD 3. Raspberry Pi 2 in a Pieshell To open raspi-config at any time, at prompt type: sudo raspi-config 4. The following functions are available within the menu. a. Expand root partition to fill SD card b. Change overscan c. Set keyboard layout d. Change password for 'pi' user e. Set locale f. Set timezone g. Change memory split h. Enable or disable ssh server i. Start desktop on boot? j. Try to upgrade raspi-config π ----------------------------------------- 16.0 Configuration File Config.txt is a text file with many configuration options. The file in the /boot directory. Edit the config.txt with nano text editor. At prompt type: sudo nano /boot/config.txt In the configuration file, many options are commented out by: #. To uncomment, remove hash which will activate the line. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. Restart to activate changes, at prompt type: sudo reboot The system is starting over, so the process may take 30 seconds or so. π ----------------------------------------- 17.0 Monitor HDMI is the normal display mode. Some monitors and TVs are DVI. The mode can be changed for a wide variety of monitors. pg 12 DrMOD Raspberry Pi 2 in a Pieshell Follow the instructions in the CONFIGURATION FILE section. Open config.txt, at prompt type: sudo nano /boot/config.txt. Place and remove # as necessary to facilitate the preferred monitor mode. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. Restart to activate changes, at prompt type: sudo reboot. π ----------------------------------------- 18.0 Sound Sound is normally presented on HDMI when a monitor or TV is connected. Because of different monitors and TVs, some parameters may need changing. Although the Pi expects HDMI, the monitor's preferred mode may be DMT. DMT is only well defined in DVI mode, but DVI cannot do audio. Follow the instructions in the CONFIGURATION FILE section. Open config.txt, at prompt type: sudo nano /boot/config.txt. To force monitor to HDMI mode, uncomment: hdmi_drive=2 To force monitor to CEA mode, uncomment: hdmi_group=1. Then uncomment: hdmi_mode=4 To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. Restart to activate changes, at prompt type: sudo reboot. π ----------------------------------------- 19.0 Keyboard 1. The Raspberry Pi system defaults to a British configuration. So some of critical keys on the keyboard do not work properly; particularly the # key. The operating system can be arranged to operate with a variety of international notations. The normal arrangement for most keyboards are US-English, 101-key, QWERTY arrangement. pg 13 DrMOD Raspberry Pi 2 in a Pieshell pg 14 2. Use raspi-config to select the version. To open raspi-config at any time, at prompt type: sudo raspi-config. 3. If that does not fix your issues, the values can also be set by reconfiguring the files. But first, try to set these parameters with raspi-config. 4. First, change the locale. At the terminal prompt, type: sudo dpkg-reconfigure locales 5. Change the country settings from: en_GB.UTF-8 to en_US.UTF-8. 6. Save the changes. Restart to activate changes, at prompt type: sudo reboot. 7. Now reconfigure the available keyboard layouts. Numerous options are presented. Keep it simple. At the command prompt, type: sudo dpkg-reconfigure keyboard-configuration. 8. Select keyboard brand or generic Select language En-US. Select keyboard layout default, which is 101-keys. Select no composite key Last window select no. 9. Use the cursor keys to move through the menu. Use <space> to select or deselect an entry. 10. To exit, press: <Ctrl+X>. To save, press: <Y>. To keep filename, press <Enter>. Restart to activate changes, at prompt type: sudo reboot. π ----------------------------------------- 20.0 Touchscreen Display 1. 2. 3. 4. Check parts list. Connect the display ribbon cable to the back of the adapter board. Pull connector latch to open. Lay adapter board onto the back of the display. Then connect the touch screen ribbon cable into J4. Screw the four standoffs through the adapter board into the back of the display. DrMOD Raspberry Pi 2 in a Pieshell pg 15 5. 6. 7. 8. Attach the DSI ribbon cable to the adapter board. Pull connector latch to open. Use four screws to secure the Pi to the standoffs. Loop the DSI cable, then connect to the Pi. Connect 5V and GND jumper wires from the GPIO header to the adapter board power pins. 5V: GPIO 2Display1 GND: GPIO6Display5 9. Insert a Micro-SD card into the slot. The process is tedious inside the DSI cable loop. 10. Connect 2A power supply to adapter board to power both boards. 11. Alternately, connect power cable between boards, or use 2 different power supplies. 12. Run the latest version of Raspian. Sudo apt-get update then sudo apt-get upgrade to get drivers. 13. Instructions and pictures are available from the supplier. http://www.element14.com/community/docs/DOC-78156/l/raspberry-pi-7-touchscreen-display 14. Instructions are given to install a matchbox-keyboard, if an onscreen keyboard is desire. π ----------------------------------------- 21.0 Powered USB 15. The power requirements are only about 700 ma when running. However, many USB devices, such as WiFi consume substantial amounts of power. Rather than subject the Pi to heat, a powered USB is desirable for current greater than about 1 Amp. 16. A typical hub has 4 ports with a separate AC power connector. Amazon has one with their own brand, which works. π ----------------------------------------- 22.0 Mount USB Drives 1. USB drives include flash drives, hard drives, or any other file oriented mechanism. Mounting of usb drives is incredibly simple. The module ‘usbmount’ drastically reduces the issues and replaces the original configuration on the Pi. Previously, Pi mounted USB drives in location /media, with a unique name and with limited permissions. Now USB drives will be mounted as ‘usb0’, ‘usb1’, …,’usb7’. 2. Install usbmount sudo apt-get install usbmount To continue press <y>. Then press <Enter>. 3. Restart the system. sudo reboot 4. Open file manager. DrMOD Raspberry Pi 2 in a Pieshell pg 16 Go to /media. See all the files. That is it! A fantabulous tool. π - REPRODUCTION 23.0 Set Up a Production System 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. The list of steps is an outline. Details for each step are in other sections. Initialize Micro-SD for operating system. Download Noobs and install on Micro-SD. Insert Micro-SD into Pi. Connect Ethernet, wifi dongle, display, & keyboard. Supply power. Edit Menu>Preferences>rasp-config for US locale, time, keyboard; advanced start SSH and serial; update tool. To get latest files: sudo apt-get update to download, then sudo apt-get upgrade to apply. Edit for sound on HDMI if necessary: /boot/config.txt . Edit wlan0 for peer-to-peer: /etc/networks/interfaces. sudo apt-get install isc-dhcp-server sudo apt-get install usbmount sudo apt-get install tmux Make directory: /home/pi/mod/apps. Use WinSCP to copy files from PC to Pi. a. gpio.py /home/pi/mod/apps b. ftime.txt /home/pi/ c. fstatus.txt /home/pi/ d. myfile.sh /home/pi/Desktop/ Edit hidden desktop file to autostart script: /home/pi/.config/lxsession/LXDE-pi/autostart. Right click file, click properties, click permissions, make execute = anyone. Try it out. Click on script shell on desktop. π 24.0 Copy SD Card Image for Easy Reinstallation 1. Set-up of the operating system, configuration of the box, and installation of apps is a big process. Stuff happens, or you may want to duplicate your computer. After everything is set-up including configuration and apps, clone the SD for easier reconfiguration. 2. Simple copying of the SD card to the PC via WinSCP has not been effective. Numerous files experienced errors. Therefore, an OS image can be collected. DrMOD Raspberry Pi 2 in a Pieshell 3. Shutdown the Pi, remove the SD card. 4. Insert SD into computer port. 5. Start Win32DiskImager, the same program used above to install an operating system image. 6. In Image File dialog, place path and image name for the file to be saved on the PC computer. Adding the extension *.img will make the file easier to find. Unfortunately, the software is dumb. Paths tend to be rejected. Just placing the name in the box, writes the file to the DOWNLOADS folder. 7. An entire card is copied. If the card is 8 GB, then a 7,700 KB file is created. Therefore, do all development on the smallest card possible. 8. In Device Box, select the SD card. 9. Click the read box to transfer the SD to the image. The process takes several minutes, approaching half an hour. Read 10. Safely eject the SD card. Then reload into the Pi. 11. Copy the file from Downloads to PiPoc directory π ----------------------------------------- 25.0 Clone SD Card Image 1. Clone a copy of a previously saved image. 2. A fresh Micro-SD is inserted with an adapter into the Windows PC’s external memory slot. Format the SD card as shown above. SDFormatter. 3. Start the Win32DiskImager app, which can read or write files. Win32DiskImager 4. Right click the file to run as administrator. 5. Browse to the file image. Browse will NOT get a network file, so the file must be copied to the PC . If the file was previously copied from an SD card, an image should be in the Downloads folder. If the file was not saved with an *.img extension, click *.* to view. C:/users/MOD/Downloads/ 6. Select the drive associated with the SD card. pg 17 DrMOD Raspberry Pi 2 in a Pieshell pg 18 Click the direction as write. Write 7. The process is very slow. The rate is about one-half the copy rate, resulting in about twice the time. Time for 8 GB is over 20 minutes. When the process is complete, safely eject the card from the drive. Remove from adapter. Plug the card into the Raspberry Pi. π - NETWORKS & HEADLESS OPERATION 26.0 Ethernet Hardwire 1. The Pi is designed to operate on a network for all operations. Connect an Ethernet cable to the local area network (LAN), the system should work. The yellow LED should show power and the green LED should flicker from communication data transfer. It really is that simple. 2. Enter the network password to access protected networks. 3. If the LEDs do not activate, check the cable and the network to verify operations. Verify the network is configured for Dynamic Host Configuration Protocol (DHCP) to give IP address. 4. Check the section on Ethernet Set-up for more details or troubleshooting. π 27.0 WiFi 1. Rather than a hardwire connection, often a WiFi connection is preferred. WiFi has the advantage where the Pi can be located at places without a LAN connection. WiFi has the disadvantage where communications is considerably slower. 2. WiFi stands for Wireless Fidelity and is based on the wireless networking standard IEEE 802.11.*. WiFi is a radio transmitter and receiver. WiFi on the Pi requires a USB adapter. 3. The adapter consumes a substantial amount of power and may overload a small supply. A powered hub may be necessary if multiple USB devices are used. 4. Not all adapters are created equal, even if they claim to have the same chip set. The preferred is the Offical Raspberry Pi version, since it delivers more power 5. Edimax can be plugged in and run using built in drivers. DrMOD Raspberry Pi 2 in a Pieshell pg 19 Edimax is not very sensitive and transmits low power. The dongle will fail if left operating continuously. 6. I have tried multiple other dongles. All have some issue and have been thrown in the trash. Canakit is incompatible as a peer-to-peer transmitter. JBtek Raspberry Pi Wifi Dongle Adapter is pathetic. 7. On successful connection, a wireless icon will show on the top bar system tray. 8. First time connection errors are not uncommon. These include no driver for adapter, password incorrect, and weak signal strength. 9. To see if the adapter is connected, at command prompt, type: lsusb 10. The adapter should be set to allow-hotplug. If an adapter is plugged in, but not recognized, it may not be configured. If the adapter is not recognized, then restart the PI by removing power and replugging in the power. 11. Check the section on Ethernet Annals for more details and troubleshooting. π 28.0 Ethernet Set-Up 1. The set-up instructions are appropriate for either LAN connections or WiFi. 2. If operating with the GUI Window, a wireless icon should show on the top toolbar system tray. Point at the icon, a pop-up screen will show the network address. 3. A detailed network set-up is available in the app wpa_gui. If the WiFi Config icon is not available, click >Menu > Run, then type: wpa_gui. 4. The first screen identifies which adapter is operating. Select alternate adapters or networks if desired. Click the <Scan> button to determine what devices are currently connected to which network. The SSID, frequency and signal strength of each connection is shown. This is similar to the iwlist network command. 5. Enter network password in the PSK field, then click <Add> 6. Check the section on Ethernet Annals for more details and troubleshooting. π ----------------------------------------- DrMOD Raspberry Pi 2 in a Pieshell pg 20 29.0 Check network operation, IP Address, & MAC address 1. To determine how the network is operating, at command prompt, type: ifconfig The file echoes network device eth0, lo, and wlan0 information. Inet is the IP address to which the device is connected. HWaddr is MAC address for the device. The MAC address is a unique address for every chip which identifies a specific machine. 2. The adapter specifications, radio frequency and radio management can be seen at prompt, type: iwconfig 3. Remember! If your IP address starts with 192.168 or 10.0 then it is an internal address The device can get out to the internet, hackers outside your network can not access in to the device. An internal address is an issue if you want a webserver which you can reach from outside the network. It is safer to keep all devices inside the network so the machine cannot be hacked as easily. 4. More details are shown in the section Handy Network Commands. π ----------------------------------------- 30.0 Remote Control: Command Line - SSH 1. Remote control using the terminal command line is inconceivably simple. The process allows access to the Pi command line from a Windows PC control computer. The Pi is the server while the PC is the client. Pi can then be operated without keyboard or monitor. Nevertheless, for initial set-up of the Pi, ye olde keyboard is necessary. 2. Shell is a program which takes commands from keyboard and gives them to operating system. Use Secure SHell (SSH) protocol for remote access. To initiate the protocol, open Raspi-config menu sudo raspi-config 3. Then select: ssh. 4. Close Raspi-config menu. SSH will now automatically start each time the Pi computer is booted. 5. The network IP address of the LAN or WiFi adapter is required for a remote access connection. From GUI Window screen, to get network IP address, touch wireless icon. From terminal, to get IP address, at prompt type: DrMOD Raspberry Pi 2 in a Pieshell pg 21 ifconfig 6. Both the ethernet (eth0) and lan (wlan0) are shown. Inet addr is the IP address. HWaddr is the MAC address, which is required for static IP. 7. Preferably, setup a static IP in router to keep from having to find Pi IP every time. 8. With the PI server IP address in hand, go to the remote client computer. On a Windows control computer, run a remote SSH client such as PuTTY. PuTTy is a free download from web, if necessary. Start PuTTY. Select: SSH, port 22 Enter: IP address. 9. The reward is a Raspberry Pi terminal screen displayed on the Windows PC. On the screen, enter your PI login. Next, enter your Pi password. From this point you are remotely controlling the Pi as if you were operating ye olde keyboard & monitor. 10. The next time you want to remotely operate the Pi, simply start Putty on the PC. π 31.0 Desktop Control: GUI - VNC 1. Remote operation by a GUI desktop is not quite as easy to set-up as the command line. The operation is called virtual network computing (VNC). The Pi is the server and the remote computer is a client. If clients (viewer) are open on multiple computers, all see the same screen process simultaneously. 2. For remote desktop control, run a Virtual Network Computing server such as TightVNC on the Pi. At the terminal command prompt type: sudo apt-get install tightvncserver. Earlier versions had a known ownership bug, which is not a problem with current versions. sudo chown pi /home/pi/ .Xauthority 3. The Pi server can be started by command prompt, type: tightvncserver. DrMOD 4. Raspberry Pi 2 in a Pieshell pg 22 Then enter a password you want to use to access the Pi desktops. Password Reenter the password to verify: 5. An alternative start command allows adjustment of the remote screen resolution. The :1 is the VNC instance. Geometry is the screen resolution. 1600x900 is reasonable. Larger screens can be better. Color depth is number of bits used to produce colors. Raspberry pi is limited to 16. vncserver :1 -geometry 1600×900 -depth 16 -pixelformat rgb565: 6. If you make a mistake or simply want to stop the VNC, type: vncserver –kill :1 7. Now setup the Windows PC client. Download a VNC viewer such as TightVNC. 8. Start the app, TightVNC. Enter the IP address for the Pi adapter followed a colon and instance number, such as: 10.0.1.77:1 Enter the Password you setup for the VNC server. Your reward is the Pi desktop shown on your PC screen. 9. The default port for a VNC client (viewer) connection is 5900. The client will use port 590x where x is the instance number, e.g. 5900 + 1 = 5901. More advanced viewers allow the :x after the IP address. If this does not work, simply enter the port address as 5901. Client Mocha VNC lite does not allow the :x, but requires manual entry of port 5901. 10. Some operations do not work properly using VNC, at this time. For example >Menu>Programming>Scratch does not open. π ----------------------------------------- 32.0 Desktop Control : GUI – VNC Auto start 1. To automatically start the Pi VNC server, create an init file to gracefully start and stop the server. Place the file in the initialization directory (init.d) and name the file tightvnc or whatever. At the prompt, type: sudo nano /etc/init.d/tightvnc 2. Paste the following script in the file. #!/bin/sh DrMOD Raspberry Pi 2 in a Pieshell ### BEGIN INIT INFO # Provides: tightvncserver # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start vnc server # Description: ### END INIT INFO # Configure the user to run under – user is generally pi export USER='pi' eval cd ~$USER # Check the state of the command - either start or stop case "$1" in start) # if start, then start vncserver # resolution is set for iPad-change for larger screens su $USER -c '/usr/bin/vncserver :1 -geometry 1024x768 -depth 16 pixelformat rgb565:' echo "VNC server started for $USER " ;; stop) # if stop, then kill the process pkill Xtightvnc pg 23 DrMOD Raspberry Pi 2 in a Pieshell echo "VNC server stopped" ;; *) echo "Usage: /etc/init.d/vncserver {start|stop}" exit 1 ;; esac exit 0 3. The editor is very tedious. I had to retype the file 3 times before it executed properly. Fix the resolution geometry to the size pi screen you want on the Windows PC. The user account at can be changed to another account or desktop. 4. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 5. Change the permission of the file, at the command prompt, type: This MUST be done every time the file is modified, or the file gets’lost’. sudo chmod 755 /etc/init.d/tightvnc 6. The file is executable. Test it. At the prompt type: sudo /etc/init.d/tightvnc start sudo /etc/init.d/tightvnc stop 7. Add file to start-up sequence. A confirmation should indicate the file was updated. sudo update-rc.d tightvnc defaults 8. Give it a go. At the prompt type: sudo reboot. Once the system is reboot, the VNCserver should start automatically. 9. The next time you want to virtually control, go to Windows PC, start VNC client. Enter address plus :1 Enter password. 10. If there are issues, return to the Pi command prompt. At prompt type: pg 24 DrMOD Raspberry Pi 2 in a Pieshell pg 25 tightvnc This assures the file was saved and the password was set properly. π ----------------------------------------- 33.0 iPad Control: VNC 1. Tablets such as the iPad are excellent options for controlling the Raspberry Pi. However not all VNC client (viewer) apps work effectively or at all. 2. Mocha VNC Lite works very well and is free with not ads in keeping with Raspberry philosophy. However, Mocha Lite has many options on setup, so use is not as automatic as some. For port enter 5900 + instance number, eg 5900 + 1 = 5901. Another app, VNC viewer is squirrelly and does not work on my system. 3. The iPad screen resolution is 1024x768 and iPhone 4 is 960x640. Depth is limited by Raspberry Pi. Consequently, these values should by be used on the Raspberry server setup. Type: vncserver :1 -geometry 1024×768 -depth 16 -pixelformat rgb565: Review the section for automatic initialization for the complete process. 4. Remember, the system may appear slow since multiple connections may be used. π ----------------------------------------- 34.0 VNC Cut & Paste 1. Some versions do not allow cut & past from outside the VNC to be pasted in VNC. The fix follows. 2. Install autocutsel. At prompt type: sudo apt-get install autocutsel 3. Open vnc startup file to add fork At prompt type: nano /home/pi/.vnc/xstartup 4. Put the following instruction first in the file. # Makes copy/paste work - must come before RANDR 'fix' DrMOD Raspberry Pi 2 in a Pieshell pg 26 #vncconfig -iconic & autocutsel -s CLIPBOARD -fork autocutsel -s PRIMARY -fork π ----------------------------------------- 35.0 File Transfer - SSH 1. Once SSH protocol is setup, transferring files is incredibly simple. Download a cross-platform FTP client file manager, such as WinScp. Be careful to not click on ads. A clean download can be made from the official website winscp.net 2. A popular alternative is FileZilla client on the Windows PC. Some malware detectors, such as MalwareBytes will attempt to block the download, appropriately. The software is good, but it is bundled with many nuisance packages such as Yahoo SEIZE-ware. Be very, very careful what you download. The seize-ware will take charge of your computer and is difficult to remove. Believe me! It took a lo-o-ng time. Therefore, I DO NOT RECOMMEND. FileZilla client 3. Select custom installation if possible, so you will get only the filezilla. http://sourceforge.net/projects/filezilla/?source=typ_redirect 4. Once the FTP client is downloaded, click to start and enter the following. Host: the IP address of the Pi Username: Pi Password: raspberry Port: 22 Servertype protocol: SFTP-SSH 5. You will be presented with a screen. The left side is the file system for the Windows PC. The right side is the file system for the Pi. Select the folder or directory on each side. Click and drag the file between computers. 6. That’s all folks. π ----------------------------------------- DrMOD Raspberry Pi 2 in a Pieshell pg 27 36.0 Detachable SSH – tmux Terminal Multiplexer 1. Often it is necessary to exit an SSH session, then return to the operating program at another time. The traditional program is Linux GNU screen, however, it has not been maintained for years. The alternative is tmux. Another alternative is byobu, which is a wrapper for tmux and screen. 2. Install tmux like any other module. Also check out the manpage with man tmux. sudo apt-get install tmux 3. Start by typing on one of the consoles. tmux 4. Commands to set-up tmux are shown. start a new session create a new tmux session named session_name re-attach a detached session re-attach an attached session (detaching it from elsewhere) attach to an existing tmux session named session_name switch to an existing session named session_name list existing tmux sessions list out every bound key and the tmux command it runs list out every tmux command and its arguments list out every session, window, pane, its pid, etc reload the current tmux configuration version kill session 0 terminate 5. tmux tmux new -s session_name tmux attach tmux attach -d tmux attach -t session_name tmux switch -t session_name tmux list-sessions tmux list-keys tmux list-commands tmux info tmux source-file ~/.tmux.conf tmux -V tmux kill –session –t 0 exit Commands within tmux begin with <Ctrl+b>, listed as ^b, followed by the instruction key. detach from currently attached session rename-window to newname list sessions list windows exit current shell kill the current pane (in this console) close other panes except the current one ^b d ^b , <newname> ^b s ^b w ^d ^b x ^b ! DrMOD Raspberry Pi 2 in a Pieshell go to window # go to last-active window go to next window go to previous window see keybindings create another shell split pane horizontally split pane vertically switch to another pane swap location of panes show time show numeric values of panes 6. pg 28 ^b # ^b l ^b n ^b p ^b ? ^b c ^b " ^b % ^b o ^b ^o ^b t ^b q To terminate tmux, at prompt simply type exit. exit π ----------------------------------------- 37.0 Tmux to Join a Running Program 1. The multiplexer is started at a terminal prompt. tmux 2. A program can be started within the new terminal inside tmux. sudo python3 /home/pi/mod/gpio.py 3. To join the running program from another device, use SSH to get to a command prompt. Then attach to the running program. tmux attach 4. The terminal on both devices should be showing identical operation. π - AUTO LOGIN & AUTO START 38.0 Autostart Apps in LXDE GUI 1. With changes in Raspian, the computer automatically starts in the LXDE Graphical User Interface. The LXDE GUI starts the mouse, enables usb and other activities, which are not available in the terminal. For this reason, autostart is preferred in the LXDE ! Therefore, the process is more automated with a single autostart file. The file must be accessed with superuser privileges. 2. Click on the File Manager. Click on >View > Show hidden. DrMOD Raspberry Pi 2 in a Pieshell /home/pi/ 3. Click files to get through hidden .config to autostart. /home/pi/.config/lxsession/LXDE-pi/autostart 4. Skip this step. Old school was from the desktop, invoke LXTerminal. At the command prompt, open the Leafpad editor or Nano. Leafpad will open in a new window with access to all the GUI features, such as file manager. sudo leafpad /home/pi/.config/lxsession/LXDE-pi/autostart 5. Right click the file name to open with Leafpad . The file contains commands to initialize on autostart . @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi @xscreensaver –no-splash @sh ${HOME}i/.config/lxsession/LXDE-pi/autokey.sh 6. To open an LXTerminal on start, add one line to the end. @lxterminal 7. To start a script shell, simply add the command. The command must be included in quotes “ “. @lxterminal –e /home/pi/Desktop/poc.sh @lxterminal –command/home/pi/Desktop/poc.sh #old school 8. 9. Save the file and close editor. Right click file name. Click Properties. Click Permissions. Make execute = anyone. 10. Reboot the RPi, which will boot to the desktop, with a terminal window running the script. 11. Skip this step. Old school permission are set with command line. sudo chmod 755 /home/pi/.config/lxsession/LXDE-pi/autostart π 39.0 Autostart at reboot using crontab: 1. Crontab is modified by using the following. # crontab -e 2. Add the following line. @ reboot /home/pi/mod/program.py pg 29 DrMOD Raspberry Pi 2 in a Pieshell π 40.0 Create Desktop File: 1. Since the gui autostart file is in reality a desktop file, the format is shown. 2. Create a text file called myfile.desktop in /home/pi/Desktop/ directory /home/pi/Desktop/myfile.desktop 3. Contents should be similar. [Desktop Entry] Type=Application Name=my desktop Icon=/usr/share/pixmaps/openbox.xpm Exec=/home/pi/Desktop/myfile.sh Terminal=true 4. Set file permissions so the script is executable. Right click > file manager properties. π 41.0 Create Desktop File to Edit GPIO: 1. Working with gpio requires sudo access, which limits Idle usage. Open Idle as root, then libraries can be used without opening a separate terminal window. [Desktop Entry] Name=Python 3 - root comment=Integrated Development environment for Python 3 TryExec=/usr/bin/idle3 Exec=sudo idle3 icon=/usr.share/pixmaps/idle3.xpm Terminal=false Type=Application StartupNotify=true π pg 30 DrMOD Raspberry Pi 2 in a Pieshell pg 31 42.0 Autostart tmux session with script 1. A script can be used to autostart tmux, the terminal multiplexor. Tmux expects specific instructions. Attach to an existing session or create a new-session. The –A flag makes a new session behave like attach session, if session name already exists. Similarly –D acts like a detach session. This uses the session name 0, which is the normal default session. 2. Start only one tmux session. The first two lines print messages, but are only visible if a sleep 5 instruction follows. The sync command is to allow everything to get up and open before executing the following lines. Sync did not work, so sleep in this routine. The first tmux line kills any existing session 0, so that multiple sessions are not opened. If none are open, an error is echoed, but it is not catastrophic. The second tmux line says attach or start a new session, using a python file. The final line sleep 5 secs is to give time to read error messages before the terminal closes. 3. The file should look similar. #!/bin/bash echo "auto start multiple terminal access" sleep 10 tmux kill-session -t 0 tmux attach || tmux new -s 0 'python3 /home/pi/mod/apps/gpio.py' sleep 5 4. The script can be from a desktop icon. The script is called by an autostart command so the session is restored on power failure. π 43.0 AutoLogin to Terminal Shell Prompt 1. Reboot the pi so that it will boot straight on to the shell prompt pi@raspberrypi without prompting to enter username or password. 2. Edit inittab file. sudo nano /etc/inittab 3. Disable the getty program. Navigate to the following line in inittab DrMOD Raspberry Pi 2 in a Pieshell pg 32 1:2345:respawn:/sbin/getty 115200 tty1 4. The normal approach is add a # at the beginning of the line to comment line out. Then add a new line with login as user pi. This should not be used. #1:2345:respawn:/sbin/getty 115200 tty1 1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1 5. However, the bin login will not start tmux and many other programs. The login is user pi without any authentication. Add the autologin to the respawn noclear line 1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1 6. To save, <Ctrl+x> <y> <Enter> 7. Sudo reboot directly to the shell prompt without log in 8. After login, autostart may be a desirable event. Several techniques are used for auto start, depending on when the sequence is desired. π - ADVANCED NETWORK SOLUTIONS 44.0 Creating a Variety of Networks 1. A Network is the connection of two or more machines, so that data and control may be shared. Several networks have been discussed and used. The most common network is created by connecting to the Ethernet. This is typically accomplished by a router which is in turn connected to an outside network. The router creates a local area network called a LAN. There are at least seven ways a network can be created and used with the Pi. 2. The biggest challenge is understanding the terminology, since all users are not consistent. Then an algorithm, program, or app is necessary to establish or arrange the network. Finally, files are used to store the configuration. 3. A few acronyms should be listed. More detailed information is available from other sources. a. IP b. FTP c. SSH d. VNC e. DHCP 4. This section will identify the types of networks, the programs used, and the major files configured. DrMOD Raspberry Pi 2 in a Pieshell pg 33 Other sections will explain in detail how to make the network, troubleshoot, and beneficial commands. The network usages are noted. a. Ethernet or common connection b. File sharing between Linux/Rasbian and Windows c. Static address d. Ad-hoc network with static address e. Ad-hoc network with DHCP f. Router network stand alone g. Router network with internet 5. The applications of the different networks are summarized. a. The common Ethernet connection is used to access the internet as well as to communicate between devices such as the computer and ancillaries. The process includes transfer of files (FTP) or control between the machines (SSH or VNC) without changing the network setup and configuration. These keep the Intern Protocol (IP) address assigned by the system router. b. File sharing involves control of files from outside the machine. The network separates from the internet protocol and uses operating system communication. Programs like Samba provide a template compatible to Linux and Windows. c. Static Address is used to assure the connection is always made to the same IP Address. The static address can be configured in the router to assure no competition between addresses. Alternately, a static address can be configured in the RPi for its use. The RPi static can be used to communicate via SSH or VNC to the same location each time. The router assigned address is still in effect. The risk is the router may assign an address over the RPi static address. d. Ad-hoc networks are created for a specific purpose (from the Latin: for this). The network is also called peer-to-peer. The technical name is Independent Basic Service Set (IBSS). The network is often used when two machines are only talking to each other. The network is well suited for robot communication. The most basic ad-hoc has each machine establish its own static IP address. There is NO security. e. Ad-hoc with DHCP is still a simple network between two or a few machines. The RPI establishes its static address. Then the RPi uses DHCP protocol to assign IP addresses to other machines which want to connect. This works well with iPad for remote control of a single RPi which is controlling another device. There is NO security. f. Wireless Access Point (WAP) is a system when the RPi creates a local area network (LAN). The network is available to any machine which wants to connect. The network is standalone with no connection to the outside world. Normal security with passwords is in effect. g. Router adds a Network Address Translation. The tables are a tunnel for the clients to access a common internet connection. This device can replace a dedicated router or computer server. DrMOD Raspberry Pi 2 in a Pieshell pg 34 The RPi is inexpensive, small, and uses low electrical energy. 6. A table of the sections which must be addressed each network type. Process needed NAS Ethernet Static Ad-hoc Ad-hoc DHCP WAP Router samba x interfaces wpa_supplicant x x x x x x x dhcp hostapd NAT x x x x x x 7. The order of the sections is slightly different. The file sharing network storage is given separate, since it is independent of IP addressing. 8. My production devices use a mixture. Eth0 is used to connect to the outside world. A static address is added for consistent SSH and VNC connections. Wlan0 is configured as an ad-hoc network with DHCP so an iPad can access it in the field. Security is not an issue for the field access. π 45.0 Ethernet Annals: Interfaces 1. The instructions are appropriate for either LAN wired (eth) connections or WiFi (wlan). The instructions should not be necessary for normal LAN or WiFi operations. But will be beneficial for troubleshooting, alternative, and advanced configurations. 2. Two files are intertwined for Ethernet operations. The ‘interfaces’ file controls the adapter settings. The ‘wpa_supplicant’ file contains the network SSID, password, and security for outside connections. 3. As with every function of the Pi, the terminal with command line can be used. Open the session at the command prompt, type: sudo nano /etc/network/interfaces 4. The file is initially fully populated and looks similar to this. Only the comments have been added. # local loopback auto lo iface lo inet loopback # hardwired DrMOD Raspberry Pi 2 in a Pieshell pg 35 auto eth0 allow-hotplug eth0 iface eth0 inet manual # wireless 0 auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf # wireless 1 auto wlan1 allow-hotplug wlan1 iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf 5. Numerous variations are possible with the following explanations. Auto means the stanza will be started on boot. Allow-hotplug lets the stanza stop or start when the adapter is unplugged. Iface is the key component and has several ways to connect: manual is default, dhcp, or static. Iface can be used to set the address, netmask, wireless mode, ssid, and all interface connections. Mode has several ways to connect: master is default, or ad-hoc. Wpa_roam can only be used with the iface manual method. Wpa_supplicant.conf is a separate file which provides name, password, and security. 6. The normal application is to connect the computer to an outside network. Address management and security is handled by the router. Since the RPi is a functional computer, it may also be used as a router or to establish separate networks. 7. A common function is to establish a fixed, static address to give a known SSH connection. When a static address is simply added, the router assigned address is still connected to the network. Similarly, an adhoc network may be made between two machines. Finally, a separate network may be built, with the RPi establishing the DHCP addressing. Several, alternative configurations for the wireless adapter are shown below. These can be substituted or added to the normal application. 8. IP address defines where a particular application on a machine is connected to a LAN. Setting a static address becomes a defined subnet for the wireless card. For fixed address on main network use 10.0.1.0 subnet + node # = 10.0.1.100. For fixed address on RPi network use such as 10.10.1.0 subnet + node #. A detailed discussion of addresses is in a later section. 9. Leave eth0 hooked up to the normal ISP router and wlan0 is available for a local network. DrMOD Raspberry Pi 2 in a Pieshell The network can be peer to peer, dhcp, or other options. 10. A generalized interfaces arrangement is shown below. These can be added to the end of the file. The file will need to be changed when acting as a server or when a static address is needed. Uncomment the desired use and comment out the normal connection if necessary. # ---------------------------------------# alternate wlan0 for static address on main network, so SSH to same location # the router will still assign its DHCP address, so two addresses exist # auto wlan0 # allow-hotplug wlan0 # iface wlan0 inet static # address 10.0.1.100 # netmask 255.255.255.0 # # ---------------------------------------# alternate wlan0 using static address creating ad-hoc network # Specify essid here. No security # other machine must have identical file, but different address number. # auto wlan0 # allow-hotplug wlan0 # iface wlan0 inet static # address 10.0.10.1 # netmask 255.255.255.0 # wireless-channel 1 # wireless-essid Pi1 # wireless-mode ad-hoc # ---------------------------------------# alternate wlan0 using static address with DHCP for ad-hoc network # Specify essid here. No security available. # may be able to change gateway IP to main network so connected to internet??? # auto wlan0 # allow-hotplug wlan0 # iface wlan0 inet static # address 10.0.10.1 pg 36 DrMOD # Raspberry Pi 2 in a Pieshell pg 37 netmask 255.255.255.0 ## gateway 10.0.10.1 # wireless-channel 1 # wireless-essid Pi1 #setting gateway will disassociate from internet # ---------------------------------------# alternate wlan0 used as router # Specify essid here. No security # other machine must have identical file, but different address number. # auto wlan0 # allow-hotplug wlan0 # iface wlan0 inet static # address 10.0.10.1 # netmask 255.255.255.0 # gateway 10.0.1.1 #setting gateway will disassociate from internet # ---------------------------------------# explanations: # auto means the stanza will be started on boot. # allow-hotplug lets the stanza stop or start when the adapter is unplugged. # wpa_supplicant.conf provides password, etc # iface has several ways to connect: manual is default, dhcp, or static # mode has several ways to connect: master is default, or ad-hoc # # setting a static address becomes a defined subnet for the wireless card # for fixed address on main network use 10.0.1.0 subnet + node # = 10.0.1.100 # for fixed address on RPi network use such as 10.0.10.0 subnet + node # # setting gateway will disassociate from internet!!! 11. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 12. After changes, restart the network. If wpa_supplicant is modified, the restart can wait until then. sudo service networking stop && sudo service networking start or old standby: sudo reboot DrMOD Raspberry Pi 2 in a Pieshell 13. If an error message shows wpa_supplicant problems, then there is a LAN issue. Likely the password is incorrect. π 46.0 Ethernet Annals: Wpa_supplicant 1. The ‘wpa_supplicant’ file contains the network SSID, password, and security. The file is for making connections to an outside DHCP assigned network. A separate file is used when the RPi is a router . 2. At command prompt type: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 3. The file contents will look something like: ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 # main network network={ ssid="main_network" psk="wifi password" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP auth_alg=OPEN } # added network for RPi to operate independently network={ ssid="Pi1" key_mgmt=NONE id_str="pump" } # network created by usb hard-drive network={ ssid="SeagateWireless" pg 38 DrMOD Raspberry Pi 2 in a Pieshell pg 39 key_mgmt=NONE } 4. Make changes as necessary associated with your network name and password. To add another network, insert similar lines. 5. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 6. After changes, restart the network. This command is now deprecated, but appears to work. sudo service networking stop && sudo service networking start or old standby: sudo reboot π 47.0 Simple Ad Hoc – Peer to Peer 1. Ad Hoc networks are called peer-to-peer and also called Independent Basic Service Set (IBSS). The process is dependent on the interfaces file which sets up the wifi adapters. The complete file can be seen above in the Ethernet Annals section. 2. The process shown hard-fixes all the parameters, which is not preferable for normal operations. On each node, open /etc/network/interfaces in a text editor. At prompt type: sudo nano /etc/network/interfaces 3. Define stanzas for each node's wireless interface. Set the iface to static, which then requires an address and netmask. Set the radio channel. Set the ESSID to the network name. Set the adapter operating mode to ad-hoc. Ad-hoc is a problem with some adapters and is not fully recognized in the standards. Master may be a preferred mode. I have not fully researched and tested yet. All the network addresses in my system are shown as Mode:Master. Node A auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 10.0.10.1 netmask 255.255.255.0 wireless-channel 1 wireless-essid Pi1 DrMOD Raspberry Pi 2 in a Pieshell wireless-mode ad-hoc 4. The second computer must be set to a different address. Otherwise, the settings are identical. Node B auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 10.0.10.2 netmask 255.255.255.0 wireless-channel 1 wireless-essid Pi1 wireless-mode ad-hoc 5. To exit, <Ctrl+x>, then <y>, then <Enter>. 6. Start the interface on each node. Reboot may be necessary sudo ifup wlan0 7. To check if wlan0 is broadcasting, scan for WiFi radios in range: sudo iwlist wlan0 scan 8. All WiFi transmitter configurations are listed. The particular results of interest from the Pi are shown. Cell 06 - Address: 02:11:87:F3:B8:55 ESSID:"Pi1" Protocol:IEEE 802.11bg Mode:Ad-Hoc Frequency:2.412 GHz (Channel 1) Encryption key:off Bit Rates:54 Mb/s Quality:0 Signal level:0 Noise level:0 π 48.0 Broadcasting Ad Hoc – Peer to Peer 1. Ad Hoc networks are called peer-to-peer and also called Independent Basic Service Set (IBSS). The first step is getting the wifi adapter to broadcast. Make a backup copy of the existing interfaces file. pg 40 DrMOD Raspberry Pi 2 in a Pieshell pg 41 sudo cp /etc/networks/interfaces /etc/networks/interfacesbackup 2. Edit the interfaces file sudo nano /etc/networks/interfaces 3. Add the following wlan0 information at end and comment out present information. # alternate wlan0 using static address creating ad-hoc network # Specify essid here. No security auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 10.0.10.1 netmask 255.255.255.0 wireless-channel 1 wireless-essid Pi1 wireless-mode ad-hoc 4. Restart the wlan0 network, by first stopping the existing and then starting the new. sudo ifdown wlan0 sudo ifup wlan0 5. If the Pi was previously used for an infrastructure network, the –f option will force new changes. Often it is necessary to reboot to activate the new wlan0. sudo reboot 6. Check to see if the wifi is broadcasting. iwlist wlan0 scan 7. Although broadcasting, a problem still exists. A computer, which tries to connect, will not have an IP address in the same subnet. A peer-to-peer can be configured or aDHCP server can be installed, which will supply an IP address. 8. Test the broadcasting of the wifi adapter by using another computer to see if the signal is there. π 49.0 DHCP Server 1. The Dynamic Host Configuration Protocol (DHCP) enables network configuration automatically. The DHCP server leases out IP addresses to other machines connected to the local area network (LAN). The process is used to make the unit a router and in a peer to peer ad-hoc network, among other uses. https://help.ubuntu.com/community/isc-dhcp-server DrMOD Raspberry Pi 2 in a Pieshell pg 42 2. Adding DHCP requires updating two files outside the DHCP. The files will have been configured when the Ethernet was activated above, but need modification. The ‘interfaces’ file controls the adapter settings. The ‘wpa_supplicant’ file controls the network SSID name and password. Some of the values, such as essid and subnet, can be alternatively configured in more than one place. 3. Install a server sudo apt-get update sudo apt-get install isc-dhcp-server 4. The default configuration file must be updated. sudo nano /etc/dhcp/dhcpd.conf 5. Make sure the file has the following. ddns-update-style interim; authoritative; subnet 10.0.10.0 netmask 255.255.255.0 { range 10.0.10.5 10.0.10.150; } 6. He following are default values which should already be in the file. default-lease-time 600; max-lease-time 7200; log-facility local7; 7. The interfaces file sets the Pi to an address of 10.0.10.1. The config sets subnet 10.0.10.0 and everything above. The range of addresses for lease is 10.0.10.5 to 10.0.10.150. 8. Restart the Pi. 9. Connect a computer to the network. Pi will assign an IO address on same subnet. Ping the Pi from the other computer. 10. Thanks to Jordan Schaenzle for the simplified ideas. http://spin.atomicobject.com/2013/04/22/raspberry-pi-wireless-communication/ π 50.0 Wireless Access Point: hostapd DrMOD 1. Raspberry Pi 2 in a Pieshell Install the access point daemon. sudo apt-get install hostapd 2. Edit the hostapd configuration file to create a wireless network which is outgoing. sudo nano /etc/hostapd/hostapd.conf 3. Create a wireless network on wlan0. Select channel 6 or any of the other channels. Network name is Pi1 with password of abcdefg33. Add the following lines. interface=wlan0 driver=nl80211 #driver=rtl871xdrv ssid=Pi1 hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=abcdefg33 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP 4. Specify the default location of hostapd configuration file. sudo nano /etc/default/hostapd 5. Remove the comment “#” in front of “daemon_conf”. DAEMON_CONF="/etc/hostapd/hostapd.conf" 6. Two different drivers are available for WiFi communications used in hostapd.conf. The n180211 driver is the default. The rt1871xdrv based on the very common RTL8188CUS chipset is commented out. 7. Install the iw package, if not already installed. sudo apt-get install iw 8. Run the list iwlist pg 43 DrMOD 9. Raspberry Pi 2 in a Pieshell pg 44 If the output of the command is "nl80211 not found" then the rtl871xdrv driver should be selected. 10. An alternate version of hostapd is also required. Adafruit has a pre-compiled edition of hostapd for the rtl871xdrv driver, which must be installed. wget http://www.adafruit.com/downloads/adafruit_hostapd.zip unzip adafruit_hostapd.zip sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG sudo mv hostapd /usr/sbin sudo chmod 755 /usr/sbin/hostapd 11. Thanks to https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point?view=all π 51.0 Network Address Translation: IP Routing between Ethernet and Wireless 1. Configure Network Address Translation ( NAT), which is IP routing between Ethernet and wireless. NAT allows multiple clients to connect to WiFi. Then, all the data is 'tunneled' through the single Ethernet IP. It is still appropriate if only one client is going to connect. 2. Enable IP forwarding. sudo nano /etc/sysctl.conf 3. Uncomment the line to enable packet forwarding. # Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 4. Activate forwarding now. sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" 5. Now the biggy. Turn the Pi into a router. sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT 6. Save the routing tables . sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" 7. Go back to our old friend, interfaces. sudo nano /etc/network/interfaces DrMOD Raspberry Pi 2 in a Pieshell 8. Add the following line to the end of the file. This line will restore the routing table whenever the Pi is booted. pre-up iptables-restore < /etc/iptables.ipv4.nat 9. Use an internet enabled device to determine if the RPi router is broadcasting. There are numerous steps susceptible to errors. π 52.0 DNS Server 1. Domain Name Servers are web based computers which convert IP addresses to names. The server translate a *.com to an IP address for routing. The servers also recognize *.local as a protected name. 2. Google is the most recognized and used, but Google is known for tracking. Consequently, other servers are often preferred. The provider and address is shown in the table. Provider Comodo Secure DNS DNS Advantage Google Public DNS Norton DNS OpenDNS IPv4 IPv6 8.26.56.26 8.20.247.20 156.154.70.1 156.154.71.1 8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844 198.153.192.1 198.153.194.1 208.67.222.222 208.67.220.220 2620:0:ccc::2 2620:0:ccd::2 π 53.0 Handy Commands for Testing & Start/Stop Network 1. Most routine installations can be accomplished with the GUI. More specialized operations require command line operations, which include these functions. These are illustrations and no new application is noted. Ifcommands are being deprecated, but are still referenced in many articles, so they are included. pg 45 DrMOD Raspberry Pi 2 in a Pieshell pg 46 2. Ip commands are the newer technology, since the ‘if’ family is being deprecated. Common examples are listed. ip addr show ip route hostname --ip-address 3. The general form is ip [ OPTIONS ] OBJECT { COMMAND | help } where OBJECT := { link | addr | addrlabel | route | rule | neigh | tunnel | maddr | mroute | monitor } with OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] } 4. Ifconfig is the interface configuration These are shown for historical reference. The command views current configuration of network interfaces including names. It turns an adapter on (up) or off (down). ifconfig # display current settings ifconfig eth0:0 192.168.1.101 # assign a second IP address to an adapter 5. Iwconfig is for interface wireless configuration. The command is similar to the two previous, but for the wireless adapter. Probably the most used is the display the wireless settings. iwconfig # show settings w/ interface names iwconfig "my network" # set essid (extended service set identifier) iwconfig eth0 key # WEP encryption key (WPA/WPA2 not supported iwconfig eth0 ap 00:60:1D:01:23:45 6. #connect to AP with MAC address given Route gives the kernel routing table. Route 7. Ethtool is ethernet adapter tools. ethtool –i # display driver info & check version DrMOD Raspberry Pi 2 in a Pieshell ethtool –p # adapter action like blinking the LED lights ethtool -S # show network statistics ethtool speed <10|100|1000> 8. 9. pg 47 # set the connection speed in Mbps Ping is the network sonar. ping ip-address # ping the address, stop ping with Ctrl+C ping –c # Count, or number, of packets to send ping –I # Wait number of seconds between packets ping –s # Packet size; default is 56 (64 with ICMP) ping –w # Waitsecs before starting pinging ping 8.8.8.8 # ping out from Pi Netstat if for reviewing network statistics netstat # View a list of open sockets netstat –i # show a table of all the network interfaces netstat –s # show summary statistics for each protocol 10. Hostname lets you view your hostname or temporatily change hostname until restart. hostname # view hostname 11. To force a particular network adapter to start: sudo ifup wlan0 12. To force a network adapter to stop the connection. sudo ifdown wlan0 13. To parse internet configuration data. sudo ifquery wlan0 14. Scan the wireless list to determine what network cells are broadcasting. The ESSID, Mode, Frequency, and Encryption are displayed iwlist wlan0 scan 15. To find all the adapters transmitting iwlist scan 16. The driver for all the computer devices can be listed. DrMOD Raspberry Pi 2 in a Pieshell The list is long, detailed, and tedious. dmesg 17. If not connected, you may request an IP-address from the DHCP server on the WiFi network. sudo dhclient -1 wlan0 18. To start or stop network related files named whatever. sudo service whatever stop sudo service whatever start sudo service whatever reload 19. To restart the network sudo service networking stop && sudo service networking start 20. Reload network without reboot sudo service networking reload 21. To find the currently leased address, type: cat /var/lib/dhcp/dhcpd.leases 22. To determine how the network adapters are working ip addr ifconfig iwconfig 23. To test, ping node A from node B. At prompt type: ping 10.0.10.100 24. The results of the ping are shown. <Ctrl+c> if necessary to quit. PING 10.0.10.100 (10.0.10.100) 56(84) bytes of data. 64 bytes from 10.0.10.100: icmp_req=1 ttl=64 time=0.166 ms 64 bytes from 10.0.10.100: icmp_req=2 ttl=64 time=0.124 ms ^C --- 10.0.10.100 ping statistics --2 packets transmitted, 2 received, 0% packet loss, time 999ms pg 48 DrMOD Raspberry Pi 2 in a Pieshell pg 49 rtt min/avg/max/mdev = 0.124/0.145/0.166/0.021 ms 25. If a field provides too much information (TMI), add | grep then-desired-stuff. iwconfig | grep ESSID π 54.0 IP Address, Subnet, Net Mask, SSID, and Other Mysteries 1. Internet Protocol (IP) addresses consists of four octets, such as 216.10.100.10 This is the address supplied from the internet service provider (ISP). The address is connected to the outside world. 2. The LAN Internet Protocol (IP) address (aka inet addr) consists of four octets, such as 10.20.30.40. The address is determined by the DHCP server and used by the client to route messages. Each computer on the network is provided a different LAN IP Address. Remember! If an IP address starts with 192.168 or 10.0 then it is an internal (LAN) address. 3. Subnet is a portion of the IP. At prompt, to get LAN IP address of a computer on the network. ip addr ifconfig Take the Inet Addr and replace final octet with zero to get the subnet. My major LAN subnet is 10.0.1.0 4. Netmask for home network is generally: 255.255.255.0. The mask is a series of 1-bits with no 0 gaps. Ones preserve the subnet value and zeros will mask. The mask is ANDed with the Subnet to obtain the range of addresses. The mask of 255.255.255.224 has a bit arrangement of 11111111.11111111.11111111.11100000. The complement (bit wise NOT) of the mask yields the range. The last octet is 11100000, whose complement is 0001111, giving a range of 31. The range is from the subnet address up to the address plus range. If the last octet of the mask is zero, then the range is 0 to 255. 5. Range is IP address from – to for serving the clients of a particular DHCP service. Normally, more than one DHCP Server is on a LAN. The router is generally setup as a DHCP Server. Determine the machine's currently leased IP Address. Use cat or nano. cat /var/lib/dhcp/dhcpd.leases NOTE: If more than one DHCP server operates on the same LAN, assure ranges do not overlap. 6. Router (aka gateway) is the protocol device which generally assigns the LAN IP address. DrMOD Raspberry Pi 2 in a Pieshell Obtain the router address from the prompt. Look in gateway column on the eth0 or wlan0 line. route -n My main network router is 10.0.1.1 7. Broadcast My main network broadcast is 10.0.1.255. 8. Local domain name is an option for DHCP server, but is not generally used. The name should be *.local, since .local is protected. A typical domain would be mypinet.local 9. Domain Name Server (DNS) has an IP address if it is used. This is only needed if a domain name is used. 10. WAP (wireless access point) 11. SSID (service set id) is the unique name for a wireless LAN (WLAN). The SSID is a 32-character alphanumeric key. The name will be included in quotes. ESSID:”Network_name”. Multiple available networks exist in the same radio airspace. All users who wish to communicate must be configured to the same SSID ! A radio can have up to 32 SSID’s. 12. BSSID (basic SSID) is the MAC address (aka HW addr) of the access point. The address has the form: 11:22:33:44:55:66. The BSSID is transparent to the user, but separates the multiple access points within a WLAN. Each radio has a unique MAC plus 32 SSID’s. Multiple radios provides more address options built on the base MAC address 13. ESSID (extended BSS) consists of all the BSSs in a network. The ESSID identifies the same network as the SSID. 14. Ad-hoc network has no access point, so it has no MAC address. The network generates a 48-bit string of numbers that looks and functions just like a MAC address. π ------------------------ 55.0 Glitch from Power Saver 1. Power saving can cause the module to drop out from time to time. Power saving can be disabled in a new file. sudo nano /etc/mo dpro be.d/8192cu.co nf 2. Paste the following in # Disable power saving pg 50 DrMOD Raspberry Pi 2 in a Pieshell pg 51 options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1 3. Save the file and sudo reboot. π 56.0 Network Storage (NAS) Between Pi & Windows 1. Networking is the process of sharing files and data between systems. By far the most ubiquitous network environment revolves around Windows computers. Samba is a suite of applications which communicate between Unix/Linux/Rasbian and Windows. The objective of this process is to make the Raspberry Pi shared folder visible in the Windows network. 2. In particular, the process will provide for Network Attached Storage (NAS). The process will be the vehicle for file storage on the SD Card. It will also be the same process for usb-disk drives or usb-flash drives. This is a systems process, so super user is necessary, and will be accomplished in the Terminal mode. The process is relatively simple, but looks like a tedious length because of numerous options. 3. First, create the directory (file folder) where the share is to be located. If your folder is on the SD Card, make directory, change ownership, and change mod. sudo mkdir -p /home/samba-share/nas sudo chown -R root:users /home/samba-share/nas/ sudo chmod -R ug+rwx,o+rx-w /home/samba-share/nas/ Skip the next section. 4. If your folder is going to be on a usb hard drive, make the appropriate folder. Two folders are created, if backup drives are planned. If the name of the drive is unknown, check what has been established in /media/. ls /media Use the names already established. If none, establish your own drive name such as ‘usbhdd1’. The folder ‘shares’ will be located on the drive, after the drive is mounted. sudo mkdir /media/usbhdd1/shares sudo mkdir /media/usbhdd2/shares. 5. With the path to the share folders established, install Samba and its configure file. As with most major process, update the system before starting. At prompt, type: sudo apt-get update 6. Install Samba. This will make the Pi a server. Also bind to the Windows architecture. DrMOD Raspberry Pi 2 in a Pieshell pg 52 sudo apt-get install samba samba-common-bin sudo apt-get install winbind To continue, type <y> and press <Enter>. 7. Edit the Samba configuration file. The file is shall we say very well documented. Save the old copy just in case recovery is necessary. It can happen! Edit in nano. At prompt, type: cd /etc/samba sudo cp smb.confold sudo nano smb.conf 8. Your terminal screen should open with a message , “# Sample configuration file for the Samba “ As with other files, the hash # indicates a comment. Remove the hash # to make a line active. Scroll to the Global section. Set the workgroup to match your Windows. Add the realm and netbios name. The realm and netbios are not required if using a simple usb drive workgroup = WORKGROUP realm = raspberrypi netbios name = raspberrypi 9. A periodic save is a good idea. Press <Ctrl+o>, then <Enter>. 10. Scroll on down, then remove semicolon for name resolve order.+ name resolve order = lmhosts host wins bcast 11. Adding security is recommended. Continue scroll, then remove hash # in front on this line. security = user 12. Some users want the [homes} folder available. This provides files that are not recommended. But if you want, a few changes are necessary. valid users = @users writable = yes read only = no 13. Add a section for the file to be shared. Scroll to bottom. The [name] in the bracket will be the directory (folder) which is shared. The path is the location of the shared directory, which you created at the beginning of the process. DrMOD Raspberry Pi 2 in a Pieshell 14. The directory can be called nas or other name you like. The folder is saved on the SD Card, which is treated by the Pi as a drive. [nas] comment = All users path = /home/samba-share/nas valid users = @users force group = users create mask = 0660 directory mask = 0771 writable = yes read only = no 15. If the share is saving on an usb disk drive, the folder can look like this. [backup] comment = Backup Folder path = /media/usbhdd1/shares valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no The file should be changed to reflect usb0 configurations now, rather than usbhhd1. 16. To exit, press <Ctrl+x>. To save press <y>. To keep the same filename, press <Enter>. The Samba configuration file is completed. 17. The configuration file can be checked for errors or as a dump. This is totally optional. sudo testparm 18. Restart the Samba daemons. This is simpler than a ‘sudo reboot’, which restarts everything. sudo /etc/init.d/samba restart 19. Now, we need users which can access the Samba shares. The users must be a valid Unix/Linux/Rasbian account. To create an account, add a new user. As an illustration, add the user name ‘mod’. A Linux password is required. Type the password twice pg 53 DrMOD Raspberry Pi 2 in a Pieshell sudo useradd mod -m -G users sudo passwd mod 20. Now make the Linux user a Samba user. Enter a password for the sharing account. The password is entered twice for security. This command can be run at any time to change the password. sudo smbpasswd -a mod 21. The root and pi can be added to access shares. But they still need a Samba password. sudo smbpasswd -a root sudo smbpasswd -a pi 22. A list of current Samba users can be obtained. sudo pdbedit -L 23. A list of all the shares can be obtained and connections made. The password is the Samba access, rather than the Linux/Rasbian access. sudo smbclient -L localhost 24. The process looks long and intimidating since numerous options were listed. However, it is relatively simple for a single addition of a sharing file. π - KEEPING UP 57.0 Update-Upgrade 1. The Linux Rasbian system is constantly undergoing changes. If there are errors, it may be necessary to get the latest updates. Periodically updates should be checked. 2. “Software” is in three sections: GPU firmware, patched ARM Linux kernel, and userspace. 3. First update the database, then upgrade the user -space software. To get the latest versions at prompt type: sudo apt-get update sudo apt-get upgrade 4. To update the firmware first install the module, then it can be executed. sudo apt-get install rpi-update sudo rpi-update pg 54 DrMOD 5. Raspberry Pi 2 in a Pieshell After the updates, the system must be rebooted. sudo reboot π ------------------------ 58.0 Version, etc. information 1. Information about versions can be obtained. uname –a cat /etc/os-release 2. Hardware information is also available. cat /proc/cpuinfo 3. The loaded modules with number of users includes interfaces. If less information is desired use grep with the desired paramenter, such as spi modules. lsmod lsmod | grep spi 4. The available drivers are in the lib modules for the kernel. Consider the spi drivers. /lib/modules/4.0.8-v7+/kernel/drivers/spi/ 5. The active modules are in etc/modules and can be edited to add another module. /etc/modules sudo nano /etc/modules, then add line spi-bcm2708 6. The module names, etc can be found using: sudo modprobe -h 7. Config.txt is editable. sudo nano /boot/config.txt π ------------------------ 59.0 Errors with Peripherals & Files 1. An error indicating a particular file is not available is frustrating. This error is a common problem with GPIO, SPI and IIC. The problem stems from the default Device Tree updates. pg 55 DrMOD Raspberry Pi 2 in a Pieshell pg 56 If that is the issue, the fix is easy. 2. Although there are numerous other problems, you may not have the following folder for GPIO. /sys/device/virtual/gpio/ 3. First, keep the RPi current with the latest updates. This is equivalent to the PC Windows update, which is performed automatically. But, the Linux world is all about freedom, so you must do the update on your schedule. At the command prompt type: sudo apt-get update sudo apt-get dist-upgrade sudo reboot 4. Although the updates should be executed regularly, now the problems with drivers start. The new kernel is configured to use the new Device Tree by default, as expected but still unfortunately. So, use the new update for raspi-config, which allows use of the devices you prefer. sudo raspi-config 5. When the tool opens with a Menu, navigate >down arrow to Advanced >tab to Select> press <Enter> 6. In Advanced Menu: >down arrow to Update >tab to Select> press <Enter> 7. The tool begins updating. On completion, the Raspi-Config Menu is reopened. >down arrow to Advanced >tab to Select> press <Enter> 8. In Advanced Menu: >down arrow to Device Tree >tab to Select> press <Enter> 9. In would you like the kernel to use Device Tree? >tab to No> press <Enter> 10. In Device Tree is disabled: >tab to OK > press <Enter> 11. In final screen: >tab to Finish > press <Enter> 12. Now we are almost there. At command prompt type: DrMOD Raspberry Pi 2 in a Pieshell pg 57 sudo reboot 13. Check to see if missing files have miraculously appeared. Glory! 14. BE AWARE: This process WILL cause certain functions to NOT operate properly. DO Not do this, unless you are desparate. The present implementation of RPI.GPIO will cease to output. If that is a problem, reload raspi-config, go through the process, in DEVICE TREE select yes. All is well! π ------------------------ 60.0 GPIO as non-Root, PiFace 1. At this time, Rpi.GPIO is set-up to run only as Root. The consequence is shells are verboten and sudo is the in-thing. A fix is in the process by the author of Rpi.GPIO. Until the fix is in, the following file modification changes ownership to a new group. 2. First, update, upgrade, and fix the Device tree as shown in section “Errors with Peripherals & Files”. 3. Add yourself as a member of user group ‘ gpio’. Add the new user ‘pi’ to the group. The switch –a indicates Add and the –G indicates the existing group. At prompt type: sudo usermod –a –G gpio pi. 4. The plug fixes problems with some systems such as PiFace, it does not fix access to /dev/mem/. The memory mapped GPIO still is in control of root. π ------------------------ 61.0 Add Member to Group 1. Accessibility to some files is limited to members of a group. To join a normal group, at command prompt type: usermod -a -G <group name> <username> 2. For groups requiring super user privileges, type: sudo usermod -a -G <group name> <username> 3. The default username is ‘pi’. DrMOD 4. Raspberry Pi 2 in a Pieshell For a list of groups to which the current user is a member, at prompt type: groups π ----------------------------------------- 62.0 Add or Remove Software 1. The simplest way is to use the Rasbian tools. At the prompt, type: sudo apt-get install gimp Then follow the onscreen instructions to complete the task. 2. If gimp was not the tool you really wanted, cleanup the excess junk. At the prompt, type: sudo apt-get remove gimp π ----------------------------------------- 63.0 Search for Software 1. In the open source world, myriad packages exist. 2. Look for programs, such as screenshot At prompt type: apt-cache search screenshot If you want to scroll through, pipe the files, type: apt-cache search screenshot | less. Press ‘q‘ to quit back to the command line. 3. The more up-to-date search uses, at prompt, type: aptitude search. π ----------------------------------------- 64.0 Find Location of File 1. When hacking files, the location may not be remembered. Two different methods are available with slightly different effects. For example, search for the location of the wpa_gui file. 2. At the command prompt, type: which wpa_gui 3. The response line should show ’/usr/sbin/wpa_gui’. pg 58 DrMOD 4. Raspberry Pi 2 in a Pieshell pg 59 Alternately, at the command prompt, type: find / -name wpa_gui The / directs the s earch to the very root of the file system. The –name indicates the identification of the file. π ----------------------------------------- 65.0 File Changes Using Windows PC Changes can be made to files using your Windows computer, but is not recommended. There are numerous protected files, which may encountered issues if not edited properly. Gracefully shutdown the PI. Remove the micro SD card. Place in its adapter. Put in PC reader. Find the file on the micro SD drive. Config.txt is in /boot partition. Edit with Notepad only. Avoid corruption from Word or Wordpad. Make changes to parameters. Save file. Exit notepad. In Windows Explorer, right click on SD card, select "Safely Remove". Alternately, look in This Computer, right click on SD, eject. When notified, remove card. Remove the adapter. Place micro SD back on the PI. The process is very slow and tedious, and generally not recommended. Editing files on the Pi is much easier. When SSH or VNC are activated, then files can be edited on the Windows PC directly. π ----------------------------------------- 66.0 Printer 1. Printer installation is not plug and play, but also is not a Unix marathon, but close. Printers are the traditional hard copy device for a ‘real’ computer, so any good Pi should have the ability. The printer configuration is for wireless devices. DrMOD Raspberry Pi 2 in a Pieshell pg 60 2. To link a printer, first install Common Unix Printing System (CUPS). At the command prompt ,type: sudo apt-get install cups. When asked to continue, type: Y, then press <enter>. 3. Next are administrative changes to the CUPS created user group – lpadmin. Add the new user- pi to the group. The switch –a indicates Add and the –G indicates the existing group. At prompt type: sudo usermod –a –G lpadmin pi. 4. The last pre-configuration is to enable remote editing of CUPS. At prompt, type: sudo nano /etc/cups/cupsd.conf 5. In the file, direct CUPS to listen for any network contact on port 631. Change the file to comment out listen to local host:631 , then add Port 631. # Only listen for connections from the local machine # Listen localhost:631 Port 631 6. Next, allow access to CUPS from any computer on local network. Further down in the file, three times add: Allow @local on the line after Order allow,deny < Location / > # Restrict access to the server... Order allow,deny Allow @local < /Location > < Location /admin > # Restrict access to the admin pages... Order allow,deny Allow @local < /Location > < Location /admin/conf > AuthType Default Require user @SYSTEM # Restrict access to the configuration files... Order allow,deny Allow @local < /Location > 7. CTL+X to exit 8. After any change to the CUPS configuration file, the CUPS server must be restarted. At prompt, type: sudo /etc/init.d/cups restart 8. After restarting CUPS, the administrative panel is accessed from any local network computer. Direct the browser to http://[pi IP or hostname]: 631 DrMOD Raspberry Pi 2 in a Pieshell 9. The default CUPS homepage pops up. Click on <Administrators>Adding Printers and Classes>. On the Administration panel, click <add Printer>. If a security warning pops up, ignore the message. Authentication requires user name given to “lpadmin” earlier. User Name: pi Password: ********* Click <Log in>. 10. After log in , a list of discovered printers is shown. Select the printer being added to the system. 1. The next screen allows editing the Name, Description, and Location. Since the printer is already shared, leave <share the Printer> unchecked. 2. CUPS found the printer, but the driver must be selected. Scroll through available drivers to find the model number that matches. Alternately, a PPD file can be downloaded from the manufacture. If that is the route, click <Choose File>. On way out of screen, click <Add Printer>. 3. As Lucky 13 step, select the Default options for the printer. Click <Set Default Options>. The screen now shows the default administrator panel. 4. Feeling fortunate? Open Leafpad text editor, type a message such as [What a success]. Click File>Print. Hopefully all is well. 5. Repeat steps to add additional printers or more users to the CUPS system. π ----------------------------------------- 67.0 Disk Drive 1. The ultimate storage system is NFTS formatted disk drive. The disk drive format is compatible with other computer systems. Use two disks if you want a mirror or simply more flexibility. Two drives will be configured for sharing on the network, using the Pi as the controller. At prompt type: sudo apt-get install ntfs-3g. 2. Look for unmounted partitions, at prompt type: fdisk -1. First disk is SD card: /dev/mmcb1k0 Second disk is external: /dev/sda. Partition name: /sda1 Third disk is external: /dev/sdb. Partition name: /sda2 3. Make directories for each drive similar to the following. USBHDD? Can be any name. pg 61 DrMOD Raspberry Pi 2 in a Pieshell At prompt type: sudo mkdir /media/USBHDD1. At prompt type: sudo mkdir /media/USBHDD2. 5. Mount drives at directory. At prompt type: sudo mount -t auto /dev/sda1 /media/USBHDD1. At prompt type: sudo mount -t auto /dev/sda2 /media/USBHDD2. 6. Share the folders. At prompt type: sudo mkdir /media/USBHDD1/shares. At prompt type: sudo mkdir /media/USBHDD2/shares. 7. Install Samba for remote access. At prompt type: sudo apt-get install samba samba-common-bin. When requested type: Y, then enter. 8. Before reconfiguring Samba, make a backup. At prompt type: sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old. 9. Edit the Samba config file with nano text editor. At prompt type: sudo nano /etc/samba/smb.conf In the file, many options are commented out with a hash #. Remove the hash to activate the line. 10. The Workgroup can be changed. Default is: WORKGROUP. If you want security (recommended), then remove hash for: security = user. 11. At bottom of smb.conf file, add a section. Brackets surround name of folder seen on network share, in this case: Backup. -[Backup] comment = Backup Folder path = /media/USBHDD1/shares valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no -To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 12. Restart the Samba daemon, at prompt type: sudo /etc/init.d/samba restart 13. To access Samba shares, add a username such as ‘backups’. At prompt type: sudo useradd backups -m -G users. To set password type: sudo passwd backups. Prompts require entering the password twice to confirm. 14. Now add username ‘backups’ to Samba. pg 62 DrMOD Raspberry Pi 2 in a Pieshell pg 63 At the prompt type: sudo smbpasswd -a backups. Then enter password when prompted. 15. Check out files from a networked computer by opening Windows Explorer. Click on Network to confirm hostname RASPBERRYPI is in WORKGROUP. Click on shared folder. You will be prompted to type Username and Password created above. The folder is empty. Place a test file in the Folder. 16. Go back to to the Pi. To see the file, at the prompt type: cd /media/USBHDD1/shares. At prompt type: ls 17. Now configure our Pi so when it restarts it will automatically mount the external hard drives. Use the nano editor and make a quick edit to the file system table /fstab. At the command line type: sudo nano /etc/fstab 18. Add the following lines: /dev/sda1 /media/USBHDD1 auto noatime 0 0 /dev/sda2 /media/USBHDD2 auto noatime 0 0 19. Overwrite the existing file. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. Press CTRL+X to exit, press Y to save, and overwrite the existing file. 20. You now have a hard drive for simple network sharing with no redundancy. Another section will address using two drives as a mirror. Enjoy your ultra-low power NAS. π ----------------------------------------- 68.0 Two Disk Drives with Redundancy 1. Raspberry Pi NAS is hooked up to the network and file transfer works. However, the second hard drive is configured but idle. Two simple Linux tools, rsync and cron, allow making the Raspberry Pi NAS perform a mirror. The mirror is from the /shares/ folder on the primary drive to the /shares/ folder on the second drive. The mirror is on a daily schedule, not a real time RAID-like data mirroring. 2. Add rsync to our Rasbian installation. If this is your first time using rsync, check out ‘How to Use rsync to Backup Your Data on Linux’. At the prompt, type: sudo apt-get install rsync 3. To immediately make the second disk a mirror of the primary, at the prompt type: rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/ DrMOD 4. Raspberry Pi 2 in a Pieshell pg 64 The process is for rsync to compare the two directories USBHDD1 to USBHDD2. Then copy everything from HDD1 to HDD2. Finally delete anything in the backup directory that no longer matches the primary directory. E.g. if a movie file on HDD1 is deleted, that file is removed from the backup on the next synchronization. 5. The next chore is the schedule the process. Cron is a Linux schedule table which can be used to automate a process. At the prompt, type: crontab -e 6. The command will open up the cron scheduling table in the nano text editor. Scroll to the bottom of the table to enter the following line: 0 5 * * * rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/ The command specifies the 24-hour time, year, month, day. The remainder is the process as described above. To exit, press: CTRL+X. Then to save, press: Y. Now <enter>. 7. Be aware of any other processes which may be automated. Only one can occur at a time. So the disk backup may need to be moved in time. Good practices would be to check the files for a day or two. Verify that /USBHDD1/shares/ is appearing in /USBHDD2/shares/. π - HATS 69.0 RealTime Clock (RTC): DS3231 1. A real time clock is necessary to maintain date and time when not connected to the internet. The Maxim- Dallas DS3231 has the excellent precision at a reasonable cost. It operates from 3.3V on the I2C bus. The technique is hacked from the RasClock and modified for the DS chip. 2. Raspian Wheezy and Jessie support a realtime clock. The instructions are for Jessie. Assure the files are up to date. sudo apt-get update && sudo apt-get upgrade 3. Check /boot/overlays to assure that i2c rtc device tree overlay exists. /boot/overlays/i2c-rtc-overlay.dtb 4. To enable the rtc, edit /boot/config.txt. sudo nano /boot/config.txt 5. Add the following line. The Control-X, y, <enter> to save. DrMOD Raspberry Pi 2 in a Pieshell dtoverlay=i2c-rtc,ds3231 6. Restart the Pi to have the hardware rtc recognized. Control with the hwclock commands below. 7. Edit the file /lib/udev/hwclock-set to remove fake clock. sudo nano /lib/udev/hwclock-set 8. Comment out these three lines. # if [ -e /run/systemd/system ] ; then # exit 0 # fi 9. Comment out the two lines which contain --systz # --systz 10. Control of the clock uses the hwclock command. To set the clock for its first use, copy the system time into the clock module: sudo hwclock -w 11. To read the time from the clock module: sudo hwclock -r 12. To copy the time from the clock module to the system: sudo hwclock -s 13. Now the RTC maintains the time, rather than getting time from the internet. 70.0 PiFaceDigital 1. PifaceDigital is a hardware attached on top (HAT) interface with relays and I/O isolation. The board is made by Element14, the same vendor as the Raspberry Pi itself. 2. CAUTION: PiFaceDigital will not work for realtime applications. The software overhead for PFD does not allow immediate interrupts. 3. The board is simple to install and use. Remove power from the Pi. Insert the Piface on top. Set jumpers, if needed. Reapply power. 4. Three Python3 packages are required. The first and second are already installed with Python3 included with Raspian Jessie. pg 65 DrMOD Raspberry Pi 2 in a Pieshell pg 66 sudo apt-get install python3pifacedigitalio sudo aptget install python3pifacedigitalscratchhandler 5. Only the emulator will need installation, if it is used. sudo aptget install python3pifacedigitalemulator sudo reboot 6. Set-up, illustrations, and examples are provided by piface. http://www.piface.org.uk/assets/docs/PiFace-Digital2_getting-started.pdf 7. The interrupt detect routine is high on Linux stack, so is not very responsive. Debounce is still an issue and can be helped with settle_time. Setting to 0 gets events as fast as possible. From other experience 200-300ms is typically needed for swithch debounce. However, because of the slowness of the interrupt handle, shorten that time to 0,1 sec. 8. IMPORTANT: The responses to the LISTENER, interrupt handler are displayed only in the terminal. If IDLE or a script is used, the response is not to the GUI but still is to the terminal. Frustrating! If your interrupt handling is not operating, open the terminal to see the response. Curses graphics create errors when inside the callback routine. π 71.0 PiFaceDigital vs GPIO 1. GPIO is the naked use of the pins. PiFaceDigital (PFD) is HAT interface using SPI (serial peripheral interface) control on isolating chips. Since use involves connection to pins and hardware, the info is included in this section rather than apps. 2. Python setup can be object or function. Object is shown. import pifacedigitalio pfd=pifacedigitalio.PiFaceDigital() 3. PFD setup is embedded within the objects, so nothing is required. The Rpi.GPIO requires the following setup. GPIO.setmode(GPIO.BCM) # Use the standard pin numbering scheme DrMOD Raspberry Pi 2 in a Pieshell pg 67 # Setup channel(pin) as input, use pull up to assure it start with high GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #old 17 GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #old 27 GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) #old 22 GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW) 4. #old 18 PFD object output on channel pfd.relays[0].value=True GPIO function equivalent GPIO.output(21,True) 5. Interrupt processing in called listener in PFD PFD version using a function listener = pifacedigitalio.InputEventListener(chip=pifacedigital) listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, my_callback1()) #magnet cycle switch listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, my_callback2()) #pressure switch listener.activate() GPIO version 6. GPIO.add_event_detect(26, GPIO.RISING, my_callback1, bouncetime=300) #magnet cycle switch GPIO.add_event_detect(19, GPIO.RISING, my_callback2, bouncetime=300) #pressure switch Cleanup is required to shutdown pins and interrupt sensing on termination. listener.deactivate() The GPIO requirement. GPIO.cleanup() 7. # clean up GPIO on CTRL+C exit Reference for the PFD is shown. http://piface.github.io/pifacedigitalio/ π 72.0 BrickPi 1. BrickPi is made by Dexter Industries to control Lego Mindstorms robots. The Hat is not 40 pin, so installation must be carefule. The Wheezy image is from 03/15, so it is very dated. The system will not run under Python3, which causes an error of BrickPi not found to import. π - THE REFERENCES DrMOD Raspberry Pi 2 in a Pieshell pg 68 ----------------------------------------- 73.0 Command Line Instructions Some of the useful commands are noted. Numerous modifiers are associated with commands and are generally preceded by ‘-‘. pwd ls cd mkdir print working directory list change directory make directory shows directory currently in use on standard output device monitor. lists contents of directory ls /dir or device such as lsusb. cd place switches to place. cd.. will focus to parent directory. mkdir newdir creates a directory called newdir cp file 1 file2 mv file1 file2 mv file1 file2 dir rm file copy file1 into file2, which will be created if needed. move file1 into file2. If file2 does not exist file1 is renamed file2. move file1 and file2 into directory dir. remove or delete file. Very dangerous. Avoid wildcards at all cost. cat /proc/ cat /proc/cpuinfo cat /proc/meminfo cat /proc/partitions cat /proc/version cat file1 file2 > file3 view information about hardware from /proc/ directory gives cpu data displays memory data reveals partition data from memory or drives shows version concatenate file1+file2 into file3 vcgencmd free –o –h series of commands for temperature, memory use, etc describes how much free system memory is available chmod bcd file chown you file change who can modify permissions in bcd format to file change ownership to you for file. ls > fileout.txt ls >> fileout.txt sort < fileout.txt sort <fileout.txt > fileout.txt sort lpr ls -1 | less redirect standard output from screen to a file, replacing contents of file. redirect output to file, appending to previous information in file. redirect standard input from file redirects input from file and output to file redirects output to printer pipes less ls into less command. This pipe causes scrolling. file filename head filename tail filename tail –f filename determines the file type before trying to view, particularly configuration displays first 10 lines of file displays last 10 lines of file. displays any new lines added to filename find / -name filename clear echo begin in directory in this case the root(/) search for name filename clear screen echos on screen whatever you type. It is useful to give progress info. xload xload & ^z start a program called xload. Command line waits for program to finish. start program in background. Prompt will return. Ctrl-Z to suspend the program operation DrMOD Raspberry Pi 2 in a Pieshell pg 69 xload bg restart the program in background jobs ps kill %1 kill -1 kill -9 kill 1293 list the processes running, including background with a job number list processes running in more detail with a process id send message to process job 1 to do a graceful termination, from jobs. please hangup process immediate kill because process was not graceful kill PID 1293, from ps startx return to the GUI window For more sophisticated operations, enhanced commands are used. Sudo, a contraction of "substitute user do", begins many command lines. Sudo instructs the operating systems to carry out the following command with super user privileges. Sudo has similarities to administrator. sudo apt-get install synaptic sudo raspi-config sudo shutdown –h time sudo reboot sudo nano /directory/filename downloads and installs synaptic package manager opens the system configuration menu halt the Pi and begin shutdown process in minutes or at 24-hour time. restarts Pi after system configuration changes begin text editor for file π ----------------------------------------- 74.0 More Linux Instructions Command Prompt Commands typically (but not always) have the syntax command -option -option argument An example would be ls –l *.txt The command ‘ls’ performs a directory (i.e. folder) listing. The argument ‘-l’ displays in a ‘lengthy’ format. The ‘*.txt’ argument defines what files to list. Redirection You can force the output into a file, using ‘>’. For example, ls > listing.txt would place the directory listing output into a file called listing.txt. History You can see earlier commands that you have typed by using the history command. It is very useful. Commands with Examples Command Example Description DrMOD Raspberry Pi 2 in a Pieshell man man pwd cd mkdir cd /home mkdir bob pwd ls mkdir /home/bob pwd ls -altr cp mv cp bob.txt mytest1.txt mv bob.txt tests/. rm cat more rm bob.txt cat readme.txt more readme.txt ls –altr | more cat readme.txt | more su su su - bob ps ps -ef kill kill -9 3244 df df -k history history Bring up a screen of help information or a manual page for a command. Press space to step through it, and press 'q' to quit. Very useful to quickly obtain information about any command. The example here pulls up information on what the 'pwd' command does. Change directory (folder) Make a directory (folder) Display the current directory Directory listing of files. The ‘-altr’ is a combination of 4 options. ‘-a’ lists hidden files too. ‘-l’ displays in a lengthy detailed format. ‘-t’ displays in date stamped order. ‘-r’ reverses the order, so that the most recent file is printed last. Copies a file Moves a file into a folder or to a new file name. The example shown here would move the file into the tests folder. Delete a file Displays the contents of a file. Displays content, but pauses per page. It can be combined with other commands that print lots of output, using the ‘pipe’ character ‘|’. The second example would be useful for viewing the contents of a folder with hundreds of files. The third example does the same as the first example. Change user. This allows you to jump from one user to another. It effectively creates a new shell. The first example allows you to become the root user who has administrator privileges. The second example changes to the user called ‘bob’. You can revert back to the original user (i.e. the original shell) by typing ‘exit’. View the running processes. The example lists all processes (‘-e’) and in a long format (‘-f’). This command is useful to see what is running, and also useful if you want to force a process to close using the next command in this table Force a process (program) to be closed. The ‘-9’ is a special signal that usually tells the program to close. The argument 3244 is the process number, found by using the ‘ps –ef’ command mentioned above. Check disk space. The ‘-k’ displays the values in kbytes. See all the previous commands that were typed π ----------------------------------------- 75.0 Nano Editor Shortcuts pg 70 DrMOD Raspberry Pi 2 in a Pieshell The “Control” and “Meta” shortcuts seem to be a secret on the official Raspberry Pi website. Short cuts use the CONTROL+ another key. As an example: CTRL+G, also shown as ^G. Additional commands use the ALT+ another key. As an example: ALT+/, also shown as M-/ Some of the shortcuts can be obtained within nano by using: CTRL+G A complete listing is shown below. Some shortcuts have multiple options. Control CTRL+G CTRL+X CTRL+O CTRL+J F1 F2 F3 F4 Description Display the help text Close the current file buffer / Exit from nano Write the current file to disk Justify the current paragraph CTRL+R CTRL+W CTRL+Y CTRL+V F5 F6 F7 F8 Insert another file into the current one Search for a string or a regular expression Move to the previous screen Move to the next screen CTRL+K CTRL+U CTRL+C CTRL+T F9 F10 F11 F12 Cut the current line and store it in the cut-buffer Paste from the cut-buffer into the current line Display the position of the cursor Invoke the spell checker, if available CTRL+6 CTRL+_ CTRL+\\ Alt (Meta) ALT+G ALT+R ALT+W ALT+A ALT+} ALT+{ Repeat last search Copy the current line and store it in the cutbuffer Cut from the cursor position to the end of the file Mark text at the cursor position Indent the current line Unindent the current line ALT+Space Move forward one character Move back one character Move forward one word Move back one word ALT+6 ALT+T CTRL+F CTRL+B CTRL+Space CTRL+P CTRL+N Place cursor at start of block to copy or cut Go to line and column number Replace a string or a regular expression Move to the previous line Move to the next line pg 71 DrMOD Raspberry Pi 2 in a Pieshell CTRL+A CTRL+E Move to the beginning of the current line Move to the end of the current line ALT+( or ALT+9 ALT+) or ALT+0 ALT+\\ or ALT+| ALT+/ or ALT+? ALT+] ALT+- or ALT+_ ALT++ or ALT+= ALT+< or ALT+, ALT+> or ALT+. ALT+V CTRL+I CTRL+M CTRL+D CTRL+H CTRL+L Move to the beginning of the current paragraph Move to the end of the current paragraph Move to the first line of the file Move to the last line of the file Move to the matching bracket Scroll up one line without scrolling the cursor Scroll down one line without scrolling the cursor Switch to the previous file buffer Switch to the next file buffer Insert the next keystroke verbatim Insert a tab at the cursor position Insert a newline at the cursor position Delete the character under the cursor Delete the character to the left of the cursor Refresh (redraw) the current screen ALT+J ALT+D ALT+X ALT+C ALT+O ALT+S ALT+P ALT+Y ALT+H ALT+I ALT+K ALT+L ALT+Q Justify the entire file Count the number of words, lines, and characters Help mode enable/disable Constant cursor position display enable/disable Use of one more line for editing enable/disable Smooth scrolling enable/disable Whitespace display enable/disable Color syntax highlighting enable/disable Smart home key enable/disable Auto indent enable/disable Cut to end enable/disable Long line wrapping enable/disable Conversion of typed tabs to spaces enable/disable pg 72 DrMOD Raspberry Pi 2 in a Pieshell ALT+B ALT+F ALT+M ALT+N ALT+Z Backup files enable/disable Multiple file buffers enable/disable Mouse support enable/disable No conversion from DOS/Mac format enable/disable Suspension enable/disable π pg 73
© Copyright 2024 Paperzz