Raspberry Pi

http://robin.me/pi.html
https://github.com/SensorsIot/IOTstack Docker on the Pi
https://youtu.be/zVhYvvrGhMU Pi SSD
curl robin.me/setup.txt |sudo bash curl robin.me/set.txt |sudo bash nohup curl https://robin.me/s.txt |sudo bash & RaspAP curl -sL https://install.raspap.com | bash https://raspap.com/#quick https://app.remote.it/#devices sudo apt update sudo apt install remoteit sudo apt install rpi-imager version number: sudo apt-get install lsb_release lsb_release -a architecture: dpkg --print-architecture sudo raspi-config sudo apt-get --yes update && sudo apt-get --yes upgrade && sudo apt-get --yes dist-upgrade sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade Backup SD card: diskutil list sudo dd if=/dev/disk1 of=~/PiSDCardBackup.dmg https://nodered.org/docs/getting-started/raspberrypi
Wifi hotspot autoswitch https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/183-raspberry-pi-automatic-hotspot-and-static-hotspot-installer
curl "https://www.raspberryconnect.com/images/hsinstaller/AutoHotspot-Setup.tar.gz" -o AutoHotspot-Setup.tar.gz tar -xzvf AutoHotspot-Setup.tar.gz cd Autohotspot sudo autohotspot-setup.sh sudo apt-get purge dns-root-data ssh pi@192.168.50.5 vnc: 192.168.50.5::5900 for webservers use http://192.168.50.5/ Virtual KVM switch https://github.com/debauchee/barrier https://github.com/debauchee/barrier Pi SSD
Make Python 3 the default: If it is python2, you need to execute the following commands to set default python to python3. 1. Enter directory /usr/bin cd /usr/bin 2. Delete the old python link. sudo rm python 3. Create new python links to python. sudo ln -s python3 python 4. Check python. Press Ctrl-Z to exit. python remove ssh key with: ssh-keygen -f "/home/pi/.ssh/known_hosts" -R "192.168.0.232" bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) > node-red-pi --max-old-space-size=256 sudo systemctl enable nodered.service sudo apt-get --yes install screen sudo apt-get --yes install npm sudo npm install -g node-red-admin sudo apt-get --yes install festival sudo apt-get --yes install apache2 sudo apt-get --yes install libasound2-dev sudo apt-get --yes install fail2ban sudo apt-get --yes install lynx sudo apt-get --yes install w3m sudo apt-get --yes install sshpass sudo apt-get --yes install ddclient sudo apt-get --yes install mosquitto mosquitto-clients sudo systemctl enable mosquitto.service Wireguard VPN setup https://www.crosstalksolutions.com/pivpn-wireguard-complete-setup-2022/ https://pivpn.io/ PiSugar https://github.com/PiSugar/pisugar-power-manager-rs port 8421 for web manager VPN https://www.pivpn.io/ https://www.comparitech.com/blog/vpn-privacy/raspberry-pi-vpn/ http://webmin.com/ wget http://prdownloads.sourceforge.net/webadmin/webmin_1.941_all.deb sudo dpkg -i webmin_1.941_all.deb sudo apt -f install Get USB boot functionality: sudo apt update && sudo apt full-upgrade vcgencmd bootloader_version sudo reboot sudo vi /etc/default/rpi-eeprom-update Check you are on stable, change it if not sudo rpi-eeprom-update -d -f /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-06-15.bin sudo reboot accessories sdcard copier to copy from sd to usb lsblk ( list block devices ) sudo apt-get --yes --force-yes install screen && sudo apt-get --yes --force-yes install npm && sudo npm install -g node-red-admin && sudo apt-get --yes --force-yes install festival && sudo apt-get --yes --force-yes install apache2 && sudo apt-get --yes --force-yes install libasound2-dev && sudo apt-get --yes --force-yes install fail2ban && sudo apt-get --yes --force-yes install lynx && sudo apt-get --yes --force-yes install sshpass && sudo apt-get --yes --force-yes install ddclient sudo /etc/init.d/apache2 restart Resize swap: sudo swapoff /swapfile sudo fallocate -l 1G /swapfile ls -lh /swapfile sudo mkswap /swapfile sudo swapon /swapfile Swap resize: The configuration file is: /etc/dphys-swapfile The content is very simple. By default my Raspbian has 100MB of swap: CONF_SWAPSIZE=100 If you want to change the size, you need to modify the number and restart dphys-swapfile: /etc/init.d/dphys-swapfile restart tar zip and encrypt To encrypt the contents of the current working directory (depending on the size of the files, this may take a while): tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz To decrypt a tar archive contents, use the following command: openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test To Encrypt: gpg --output encrypted.data --symmetric --cipher-algo AES256 un_encrypted.data To Decrypt: gpg --output un_encrypted.data --decrypt encrypted.data tar -czf - * data.toencrypt&& gpg data.toencrypt --output encrypted.data --symmetric --cipher-algo AES256 fail2ban: sudo vi /etc/fail2ban/jail.local [ssh] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log bantime = 900 banaction = iptables-allports findtime = 900 maxretry = 3 sudo service fail2ban restart ~/.screenrc startup_message off shell -/bin/bash put in /boot/ : touch ssh wpa_supplicant.conf file is: ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=GB network={ ssid="Rowling" psk="password" key_mgmt=WPA-PSK } export EDITOR=vi export PATH=/home/pi:$PATH sudo apt-get install raspberrypi-ui-mods sudo apt-get install raspberrypi-net-mods run scripts on startup http://goo.gl/1uxBui Extra io http://goo.gl/qD0E9R check for hotspots: sudo iwlist wlan0 scan sudo iwlist wlan0 scan | egrep 'ESSID|Quality'|less sudo vi /etc/wpa_supplicant/wpa_supplicant.conf sudo ifdown wlan0 and sudo ifup wlan0 Bring up and down the lan and renew dhcp: sudo ifup wlan0 dhclient -v {interface_name} (renew dhcp) brng network up and down sudo ifdown eth0 && sudo ifup eth0 checkwifi.sh ping -c4 192.168.1.1 > /dev/null if [ $? != 0 ] then echo "No network connection, restarting wlan0" sudo ip link set wlan0 down sleep 5 sudo ip link set wlan0 up fi crontab -e */5 * * * * /usr/bin/sudo -H /home/pi/checkwifi.sh >> /dev/null 2>&1 This command will schedule a daily reboot at 9am. sudo crontab -e 0 9 * * * /sbin/shutdown -r now view ports sudo netstat -nltp add ports sudo ufw allow in from any to any port 8080 wifi setup: wpa_gui sudo apt-get install samba samba-common-bin sudo vi /etc/samba/smb.conf workgroup = WORKGROUP sudo service samba restart [pihome] comment= Pi Home path=/home/pi browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no smbpasswd -a pi sudo reboot apt-cache search ftp To upgrade to wiringpi 2.52: cd /tmp wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v gpio readall gpio read 21 gpio -g mode 4 out to turn GPIO 4 to an output, and gpio -g write 4 1 to set it to HIGH (i.e. 1) install apache sudo apt-get install apache2 php5 libapache2-mod-php5 -y cd /var/www/html reinstall apache2: sudo apt-get purge apache2 sudo apt autoremover apache2 sudo apt-get install apache2 sudo /etc/init.d/apache2 restart send a file via rsync rsync -av -e 'ssh -p21098' ./localfile robin@lefever.website:~/ change the hostname: sudo vi /etc/hostname sudo vi /etc/hosts w3m wget -r -npH lefever.website/utils/ SSH ssh -l robin lefever.website -p 21098 chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys ssh-keygen cat id_rsa.pub >> authorized_keys id_rsa to other device sudo apt-get install weavedconnectd sudo weavedinstaller sudo apt-get install mlocate sudo updatedb locate / set teh time sudo ntpd -q -g sudo apt-get install wavemon ( wifi monitoring ) process manager sudo apt-get install htop ssh_keygen ssh-keygen -R server.example.com copy ssh credentials ssh-keygen -t rsa -b 2048 ssh-copy-id -i ~/.ssh/id_rsa.pub pi@4kendrick.com mv .ssh/authorized_keys /etc/dropbear/authorized_keys How to force ssh client to use only password auth ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no example.com get ip on pi: ifconfig ssh to pi: ssh -l pi 192.168.60.102 run vnc from pi: sudo apt-get install tightvncserver tightvncserver vnc from mac terminal open vnc://192.168.60.102:5901 to set a root password: sudo su passwd sudo chown user:user ~/.Xauthority to send a file from mac to pi over ssh rsync -v -e ssh ./bashaliases.txt pi@192.168.60.102:~/ Shutdown x: Sorry the ctrl-alt-F1, ctrl-C Firmware update: sudo rpi-update .bashrc if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi .bash_aliases alias ,='/bin/ls -AC --color=tty -F -b' alias ,,='/bin/ls -lA --color=tty -F -b' alias ,,,='/bin/ls -AC1 --color=tty -F -b' alias ,l='/bin/ls -AC --color=tty -F -b |less -E' alias ,,l='/bin/ls -Al --color=tty -F -b |less -E' alias ,,,l='/bin/ls -AC1 --color=tty -F -b |less -E' alias ..='cd ..' alias e='exit' alias c='clear' alias x='startx' alias s='screen -R' alias hg='history |grep' exec bash restarts the shell ============================================== sudo vi /etc/dhcpcd.conf # Example static IP configuration: interface wlan0 static ip_address=192.168.0.200/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1 interface eth0 static ip_address=192.168.1.23/24 Certification ========= for Stretch: add source to debian sources list: sudo vi /etc/apt/sources.list.d/raspi.list deb http://ftp.debian.org/debian stretch-backports main sudo apt-get update then sudo apt-get install python-certbot-apache -t stretch-backports then install certs for apache: sudo certbot --apache Certificates stored: /etc/letsencrypt/live/$domain /etc/letsencrypt/live/12kendrick.com/privkey.pem /etc/letsencrypt/live/12kendrick.com/cert.pem ======================== Internet Speed testing: sudo pip install speedtest-cli speedtest-cli ======================== audio works: sudo apt-get install festival install node-red-contrib-say install node-red-contrib-play-audio ======================== ======================== alarm in bed block one Please speak more loudly, except when I ask you to speak in a quiet voice. ======================== sudo npm install node-red-contrib-speakerpi sudo apt-get install libasound2-dev amixer cset numid=3 1 amixer cset numid=3 2 alsamixer ======================== @reboot /home/pi/dd.sh 0 0 * * * /home/pi/dd.sh 0 1 * * * sudo apt-get update 0 2 * * * sudo apt-get upgrade dd.sh exec 1> >(logger -s -t $(basename $0)) 2>&1 sudo ddclient -force ======================== sudo adduser bob sudo update-alternatives --set editor /usr/bin/vim.tiny To add a new user to sudoers, type sudo visudo (from a sudoer user) and find the line root ALL=(ALL:ALL) ALL, under the commented header # User privilege specification sudo visudo # User privilege specification root ALL=(ALL:ALL) ALL bob ALL = NOPASSWD: ALL sudo userdel -r bob ======================== # m h dom mon dow command # * * * * * command to execute # ┬ ┬ ┬ ┬ ┬ # │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) # │ │ │ └────────── month (1 - 12) # │ │ └─────────────── day of month (1 - 31) # │ └──────────────────── hour (0 - 23) # └───────────────────────── min (0 - 59) ======================== sudo service cron restart */1 * * * * /root/job.sh ======================== switch / gpio stuff Pi Gpio https://github.com/raspberrypilearning/physical-computing-guide/blob/master/pull_up_down.md pinout shows the gpio pins gpio readall shows each pins status setup the gpio pin in python: import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) pushpin = 17 # set input push button pin GPIO.setup(pushpin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # with pull up resistor rasp switch pi zero gpio The Pi GPIO are all set as INPUTS at power-up. GPIO 0-8 have pull-ups to 3V3 applied as a default. GPIO 9-27 have pull-downs to ground applied as a default. When started using the recommended Debian distro for RPi, GPIO is disabled. You have to enable each pin individually. If you're doing it via /sys you will find "Paths in Sysfs" interesting (search within http://www.kernel.org/doc/Documentation/gpio.txt). In particular, you would be enabling a pin by "exporting" it. Any commands below assume you are running with root privileges (sudo or otherwise) or you have changed the permissions/ownership of the virtual files being modified. echo 4 > /sys/class/gpio/export This enables GPIO pin #4 which then causes /sys/class/gpio/gpio4 to exist, which contains several virtual files. Those files include "direction" which defines whether it's an input or an output pin, "value" which is either read-only for input or writable for output and contains the current value, and others. echo out > /sys/class/gpio/gpio4/direction # set it as an output pin echo 1 > /sys/class/gpio/gpio4/value # set the value to ON echo 0 > /sys/class/gpio/gpio4/value # set the value to OFF echo in > /sys/class/gpio/gpio4/direction # set it as input cat /sys/class/gpio/gpio4/value # get the value echo 4 > /sys/class/gpio/unexport # disables pin 4 and removes the gpio4 directory PiZero GPIO https://cdn.sparkfun.com/assets/learn_tutorials/6/7/6/PiZerov2.pdf
gpio readall raspi-gpio get 17 pinout raspi-gpio set 17 ip pu Setting up systemd for active.py: sudo vi /lib/systemd/system/activepy.service ================================ [Unit] Description=Active Pi Service After=multi-user.target [Service] Type=idle User=pi ExecStart=/usr/bin/python /home/pi/active.py Restart=always RestartSec=0 [Install] WantedBy=multi-user.target ================================== sudo chmod 644 /lib/systemd/system/activepy.service sudo systemctl daemon-reload sudo systemctl enable activepy.service sudo systemctl start activepy.service sudo systemctl status activepy.service haymqtt.py sudo vi /lib/systemd/system/haymqtt.service ================================ [Unit] Description=MQTT Alarm Service After=multi-user.target [Service] Type=idle User=pi ExecStart=/usr/bin/python /home/pi/onion/haymqtt.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ================================== sudo chmod 644 /lib/systemd/system/haymqtt.service ( sudo python /home/pi/onion/active.py ) sudo systemctl daemon-reload sudo systemctl enable haymqtt.service check: sudo systemctl status haymqtt.service sudo apt-get install python-pip sudo pip install paho-mqtt sudo pip install --upgrade setuptools sudo apt-get install python-pip RPi.GPIO sudo pip install twilio==5.7.0 usb boot --------- sudo apt update sudo apt full-upgrade check in /lib/firmware/raspberrypi/bootloader/beta/ 03/06/2020 vcgencmd bootloader_version will show the current bootloader version ( was 16th april on flash ) sudo rpi-eeprom-update -d -f [file] -d forces default bootloader config -f specifies file [file] is the file in the beta directory copy the sd card to the USB drive and reboot