How to choose the correct version of OS
ssh
in the root directory of the memory card.ssh -p 22 <os_username>@<rpi_ip_address>
.First things first:
sudo apt-get update
sudo apt-get upgrade
sudo
gives root privilege.
sudo apt install git
Enter the command below to verify the installation:
git --version
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
- Try avoiding the process of downloading installer, extracting etc. For new Linux users, it can be a mess.
- ARMv6 processor is not supported by NodeSource; even for Node-v10.
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).
wget <link>
. Example
wget https://unofficial-builds.nodejs.org/download/release/v14.13.0/node-v14.13.0-linux-armv6l.tar.xz
tar xvfJ <file_name.tar.xz>
. Example
tar xvfJ node-v14.13.0-linux-armv6l.tar.xz
usr/local
directory: sudo cp -R <extracted tar folder>/* /usr/local
. Example:
sudo cp -R node-v14.13.0-linux-armv6l/* /usr/local
node -v && npm -v`.
Extra steps
.profile
file using nano: sudo nano ~/.profile
PATH=$PATH:/usr/local/bin
.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. sudo apt install python3-pip
pip3 install smbus2
/etc/rc.local
with root permission and commands before exit
command.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.
/usr/local/bin/checkwifi.sh
.
ping -c4 <router_ipv4> > /dev/null
if [ $? != 0 ]
then
echo "No network connection, restarting wlan0"
/sbin/ifdown 'wlan0'
sleep 5
/sbin/ifup --force 'wlan0'
fi
crontab -e
Add the following line:
*/5 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1
This will run the script in checkwifi.sh every 5 minutes, writing its output to /dev/null
so it won’t clog your syslog.
if [ $? != 0 ] then sudo /sbin/shutdown -r now fi ```
(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:
sudo nano /boot/firmware/config.txt
then add this text to the bottom of the file:
dtoverlay=w1-gpio
Note: If any dtoverlay=
is already there, doesn’t matter; add one more at bottom.
Exit nano, and reboot the Pi with sudo reboot
.
sudo modprobe w1-gpio
. Then enter sudo modprobe w1-therm
.
- Modules are pieces of code which extend the functionality of the operating system kernel without the need to reboot. Once loaded, modules reside in memory.
- To remove the module use
sudo modprove -r <module_name>
Change directories to the /sys/bus/w1/devices
directory.
Enter ls
to list the devices. Something like 28-xxxxxxxxxxx w1_bus_master1
will be displayed.
28-xxxxxxxxxxx
directory and type cat w1_slave
to see the temperature value from sensor.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
.
lt --subdomain <subdomain_name> --port <port_number>
# example
lt --subdomain my-unique-subdomain-name --port 8080
Trouble: Problem connecting to RPI with VSCode remote explorer with previous ssh config.
Shoot: Remove the previous ssh SHA1 string from the computer. On Windows, it is in os drive/users/<username>/.ssh/known_hosts
.
Trouble Where to look for system logs, crash/error/warning logs:
Shoot:
dmesg
will return most of the activity of the current boot. dmesg
returns every event after the boot and how long after the boot, in seconds./var/log/messages
/var/log/syslog
and /var/log/kern.log
will return pretty much every event you could ever need to know to figure out what happened.Use node
command to add a node.js app on device startup. Running with npm
command will run an extra npm
process.
Installing Node.js with NodeSource will resolve the ARM architecture and other compatibilities and downloads the correct version of the Node.js distribution. So Node.js installed with one model Raspberry PI may not run on other model(s). Like RPI3 is ARMv71, so Node.js ARMv71 distribution has to be installed to run on that machine. But after that this installation will not run on RPI Zero W, which is ARMv61. ARMv61 distribution of Node.js has to be installed too.
To change or add WIFI information diretly from the memory card: Wifi network information saved in /etc/wpa_supplicant/wpa_supplicant.conf
.
To add new network information, add following block of code at the end of the file:
network={
ssid="<ssid_name>"
psk="<plain_text_password>"
}
IMPORTANT Don’t use apostroph (‘) in wifi passwork.
sudo apt-get update
sudo apt-get upgrade
If problem occurred on upgrade, run this:
sudo apt-get upgrade --fix-missing
sudo rpi-eeprom-update
only available in RPi-4. ls
mkdir <dir_name>
Removing files and directories
rm -r <dir_name>
rm -r -f *.*
rm -i mydir/*
After each file name displays, type y
and press Enter to delete the file. Or to keep the file, just press Enter.
-s
to display only the total size, -h
to display sizes in a human-readable format.
sudo du -sh
Specific directory
sudo du -sh /home/pi
sudo nano <file_name>
sudo shutdown -h now
sudo reboot
ps -e
Filtering processes
ps -e | grep <partial_process_name>
Example:
ps -e | grep node
Real-time process listing by CPU usage
top
nohup <command_and_arguments> &
nohup
is short for “no hang-up”. Ending ‘&’ will run the command in the background.
kill -9 <process_id>
# or
kill -9 <process_name>
-9
denotes SIGKILL; to see full list of kill parameters, use kill -l
-11
ps -eo pmem,time,stat,pid,pcpu,command --sort -pcpu | head -11
free -h
sudo tailscale up
sudo rasp-config
vcgencmd measure_temp
Regular expression to get only the value:
vcgencmd measure_temp | grep -o -E '[[:digit:]].*'
cat /sys/class/thermal/thermal_zone0/temp
cat /proc/cpuinfo
Use grep to filter information:
cat /proc/cpuinfo | grep Model
dmesg | grep voltage
Also Cpu throttle status, good value is 0x0
:
vcgencmd get_throttled
Bit Position | Meaning |
---|---|
0 | Under-voltage detected |
1 | Arm frequency capped |
2 | Currently throttled |
3 | Soft temperature limit active |
16 | Under-voltage has occurred |
17 | Arm frequency capping has occurred |
18 | Throttling has occurred |
19 | Soft temperature limit has occurred |
For example, a throlled value shows 0x80008. Now convert this hex value to binary in two steps - hex to decimal, decimal to binary.
let n = parseInt('0x80000', 16) // must use quotes. without quotes it shows different value.
n.toString(2) // result: 10000000000000000000
Here, in the value ‘10000000000000000000’ 19th bit is turned on which means soft temperature limit has occurred.
<command_and_arguments> > <file_name>
.
Example:
top -b -n1 > output.txt
File will be saved in current directory.
System log path /var/log/messages
. Additionally enable watch dog to do vigorous logging.
scp username@remotehost:file_name.ext /my/local/destination/path