raspberrypi-os-guide

Working with Raspberry PI OS

Installing OS on SD Card

How to choose the correct version of OS

How to connect and work with Raspberry PI from a computer from command line (i.e. headleass)

Update and upgrade Linux package information

First things first:

sudo apt-get update
sudo apt-get upgrade

sudo gives root privilege.

Install Git

sudo apt install git

Enter the command below to verify the installation:

git --version

Install Node.js

Install Node.js from the NodeSource Repository, a third party service which resolves the installation process.

curl -sL https://deb.nodesource.com/setup_<version>.x | sudo bash -
sudo apt-get install -y nodejs

Go to https://deb.nodesource.com/ for command with latest version.

NOTE

NodeJS Install Steps for ARMv61 processor (RPi Zero W)

  1. Go to the unoffical builds download page of Node.js site and select the version of NodeJS you want to install. Copy the link of the ARMv6 version of NodeJS (Select the link with the .xz extension).

  2. Download the file wget <link>. Example
      wget https://unofficial-builds.nodejs.org/download/release/v14.13.0/node-v14.13.0-linux-armv6l.tar.xz
    
  3. Extract the binary from the tarball file using the following command tar xvfJ <file_name.tar.xz>. Example
      tar xvfJ node-v14.13.0-linux-armv6l.tar.xz
    
  4. Copy the contents of the extracted tarball file to the usr/local directory: sudo cp -R <extracted tar folder>/* /usr/local. Example:
      sudo cp -R node-v14.13.0-linux-armv6l/* /usr/local
    
  5. Reboot and check everything is working correctly
    node -v && npm -v`.
    

Extra steps

  1. You might have to do the following if you receive a command not found error. First, open the .profile file using nano: sudo nano ~/.profile
  2. Add the following line to the end of the file and hit Ctrl+X to save, and then hit ‘y’ and enter to confirm the changes: PATH=$PATH:/usr/local/bin.
  3. Reboot and check is it working. NOTE: If running node command shows exec format error then undo the previous steps and try again. Make sure to add PATH variable to .profile and then reboot.

Command to install Python package installer (pip3) and python packages

   sudo apt install python3-pip
   pip3 install smbus2

Execute certain command on boot

Example

   node /home/pi/projects/raspberry-pi-projects/home-iot/app.js &

To know about the ending &, check How to run a process in the background in this doc.

Restart network or the OS when connection is lost

Enable the 1-Wire Interface

(Courtesy: circuitbasics.com)
We’ll need to enable the One-Wire interface before the Pi can receive data from the sensor. Once you’ve connected the DS18B20, power up your Pi and log in, then follow these steps to enable the One-Wire interface:

[Extra] Install LocalTunnel (proxy tool)

  1. Install localtunnel globally to use localtunnel command lt from anywhere
      npm install -g localtunnel
    

    If not installed globally then full path to lt executable have to be used, which will be something like /home/pi/.../mode_modules/.bin/lt.

  2. Forward a local port specifying a subdomain:
      lt --subdomain <subdomain_name> --port <port_number>
      # example
      lt --subdomain my-unique-subdomain-name --port 8080
    

How to publicly access a web app, running locally on RPI

  1. Need a static IP address from the ISP with a specific port (commonly 80) open allowing incoming request.
  2. Run the web app with node/rginx/apache2 locally in RPI.
  3. If the RPI is connected with router Wifi, then forward the interal/localhost port to public. On TP-link, go to Advanced > Port Forwarding to map a port to that local port.

TroubleShooting

Useful Notes

Useful Linux terminal commands