Skip to content

Instantly share code, notes, and snippets.

@HackingGate
Last active April 25, 2024 11:28
Show Gist options
  • Save HackingGate/9dc4434c3de17188a17844438fc38aff to your computer and use it in GitHub Desktop.
Save HackingGate/9dc4434c3de17188a17844438fc38aff to your computer and use it in GitHub Desktop.
My environment temperature calculation for https://github.com/srob/homebridge-sensehat
#!/usr/bin/python
from sense_hat import SenseHat
import os
def get_cpu_temp():
res = os.popen('vcgencmd measure_temp').readline()
return float(res.replace("temp=", "").replace("'C\n", ""))
def get_temp(sense):
t1 = sense.get_temperature_from_humidity()
t2 = sense.get_temperature_from_pressure()
t = (t1 + t2) / 2
t_cpu = get_cpu_temp()
t_corr = t - ((t_cpu - t) / 15) - 3
return t_corr
sense = SenseHat()
humidity = sense.get_humidity()
pressure = sense.get_pressure()
print("%s %s %s" % (get_temp(sense), humidity, pressure))
@HackingGate
Copy link
Author

HackingGate commented Jun 7, 2023

@HackingGate
Copy link
Author

Upgrade Raspberry Pi OS from buster to bullseye by ChatGPT

As of my last training data cut-off in September 2021, the process to upgrade your Raspberry Pi OS from "Buster" (Debian 10) to "Bullseye" (Debian 11) would follow similar steps to other Debian-based system upgrades.

Here is a general outline of the steps you'd take:

Step 1: Make a backup

Before you begin, it's essential to back up any important data. System upgrades have the potential to go wrong, and it's always better to be safe than sorry.

Step 2: Update your current system

First, update your existing system packages to their latest versions. To do this, open a terminal and type:

sudo apt update
sudo apt full-upgrade

This will update the package list and upgrade all packages to their latest version. The full-upgrade command will also handle any dependencies, removing obsolete packages if necessary.

Step 3: Modify your apt sources

You will need to modify the /etc/apt/sources.list file and change all instances of 'buster' to 'bullseye'. You can do this manually with a text editor or use the sed command in terminal:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak  # Backup your sources list
sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list

If you have additional software sources set up in separate files under /etc/apt/sources.list.d/, you should also update those files:

sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list.d/*.list

Step 4: Perform the upgrade

You can now proceed with the upgrade by running:

sudo apt update
sudo apt full-upgrade

This will update your package list with the Bullseye repositories and perform the upgrade.

Step 5: Clean up

After the upgrade, you may want to remove unnecessary packages:

sudo apt autoremove
sudo apt autoclean

Step 6: Reboot your Raspberry Pi

Finally, reboot your Raspberry Pi to make sure everything is working as expected:

sudo reboot

NOTE: This is a general guide. The specific steps may vary based on your particular configuration and the specific versions of the OS. It's crucial to back up your data before performing an OS upgrade, as things can occasionally go wrong. Proceed with caution and consult the official documentation and community if you encounter problems or have concerns. It's often also a good idea to test this process on a secondary device first, if one is available.

@HackingGate
Copy link
Author

HackingGate commented Jun 13, 2023

1. Install QEMU:

sudo apt update
sudo apt-get install qemu-system-arm qemu-efi

2. Download the Raspberry Pi OS image and Kernel image:

wget https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2023-05-03/2023-05-03-raspios-bullseye-arm64-lite.img.xz
xz -d 2023-05-03-raspios-bullseye-arm64-lite.img.xz

wget https://raw.githubusercontent.com/dhruvvyas90/qemu-rpi-kernel/master/kernel-qemu-5.10.63-bullseye
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb-bullseye-5.10.63.dtb

@HackingGate
Copy link
Author

HackingGate commented Jun 13, 2023

Migrating to 64-bit OS (aarch64)

Why?
https://www.linuxserver.io/blog/a-farewell-to-arm-hf

How?

Reflash the image

Official Raspberry Pi OS

Download Raspberry Pi OS

https://www.raspberrypi.com/software/operating-systems/

Install Raspberry Pi OS using Raspberry Pi Imager

brew install raspberry-pi-imager

Flash with SSH enabled

sudo dpkg-reconfigure locales

@HackingGate
Copy link
Author

HackingGate commented Jun 14, 2023

@HackingGate
Copy link
Author

HackingGate commented Jun 14, 2023

Calibre web with docker compose

docker-compose.yml

---
version: "2.1"
services:
  calibre-web:
    image: lscr.io/linuxserver/calibre-web:latest
    container_name: calibre-web
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - DOCKER_MODS=linuxserver/mods:universal-calibre
      - OAUTHLIB_RELAX_TOKEN_SCOPE=1 #optional
    volumes:
      - /home/pi/calibre/config:/config
      - /home/pi/calibre/library:/books
    ports:
      - 8083:8083
    restart: unless-stopped

Crontab

crontab -e

@reboot (sleep 30s ; cd calibre ; /usr/bin/docker compose up -d --build)&

Basic Configuration

Screenshot 2023-06-15 at 2 02 40

@HackingGate
Copy link
Author

Calibre web

Install https://github.com/janeczku/calibre-web

Create /etc/systemd/system/calibre-web.service

[Unit]
Description=Calibre-Web
After=network.target

[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi/calibre
ExecStart=/home/pi/.local/bin/cps
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and start

sudo systemctl enable calibre-web
sudo systemctl start calibre-web

@HackingGate
Copy link
Author

@HackingGate
Copy link
Author

@HackingGate
Copy link
Author

HackingGate commented Sep 8, 2023

fileserver

Install

curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash

Init

filebrowser config init

Change listen port from default 8080 to 8780 (Optional)

filebrowser config set --port 8780

Test

filebrowser -r .

Add user

filebrowser users add admin admin

Update user

filebrowser users update admin --username pi
filebrowser users update pi --password pass1234

Add /etc/systemd/system/filebrowser.service with the following content.

[Unit]
Description=filebrowser
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/pi
ExecStart=/usr/local/bin/filebrowser -r /home/pi
Restart=on-failure
User=pi
Group=pi

[Install]
WantedBy=multi-user.target

Load, enable and run

sudo systemctl daemon-reload
sudo systemctl enable --now filebrowser.service

@HackingGate
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment