การใช้ Raspberry Pi OS Debian GNU/Linux 12 (Bookworm)

Somsak Lima
22 min readOct 13, 2023

--

0.กด Space ตอนเปิด Pi จะเข้า Boot menu

จะมี option ให้เลือกคือ
0 Default
1 SD
2 Network
4 USB
6 NVME

ถ้าไม่มี boot Menu อาจเนื่องจาก Bootloader เก่า อาจจะต้อง Upgrade eeprom และ Bootloader ก่อน

sudo apt update && sudo apt full-upgrade
sudo rpi-eeprom-update

update Bootloader

sudo raspi-config

Advanced Options >> Bootloader Version เลือก choose Latest

แล้วสั่ง update eeprom

sudo rpi-eeprom-update -a
  1. ควรเปลี่ยน จาก Wayland เป็น X windows, update bootloader

sudo raspi-config เลือก 6/A6 เลือก W1

2.Set Fixed IP เปลี่ยนวิธีจาก dhcpd เป็น NetworkManager

สร้างไฟล์ eth0 และป้อนข้อมูลดังตัวอย่าง

sudo nano /etc/network/interfaces.d/eth0

allow-hotplug eth0
iface eth0 inet static
address 192.168.1.101
network 192.168.1.0
netmask 255.255.255.0
gateway 192.168.1.1

3.ติดตั้งโปรแกรมที่มีประโยชน์

สั่ง upgrade ก่อน

 sudo apt update -y && sudo apt upgrade -y
sudo apt install xrdp locate lrzsz mc finger nmap dnsutils hdparm -y
sudo apt install baobab filezilla smartmontools krusader 4pane scrot -y
sudo apt install mosquitto-clients numlockx remmina -y
sudo updatedb
locate filename

ยาวๆ บรรทัดเดียว

sudo apt install xrdp locate lrzsz mc finger nmap dnsutils hdparm  baobab filezilla smartmontools krusader 4pane scrot mosquitto-clients remmina numlockx -y

อื่นๆ เช่น gparted, biglybt, qbittorrent, remmina, dubble commander, kate

บางครั้งควร Auto Remove Package ที่ไม่ได้ใช้ออกด้วยคำสั่ง

sudo apt autoremove

4.เพิ่ม USER กำหนดให้เป็น SUDOER หรือใช้คำสั่ง sudo ได้

sudo adduser slvp

เพิ่มเข้าไป Group sudoer

sudo usermod -aG sudo slvp

แล้ว Reboot จำเป็นต้องทำไม่นั้นเข้าใช้ Remote Desptop ไม่ได้ ต้องใช้ User ธรรมดาในการ Remote Desktop

คำสั่งจำกัดไม่ให้ใช้ Login หรือ ssh ให้ใช้แต่ sftp

sudo chsh -s /sbin/nologin {username}

5.เพิ่มขนาด SWAP Memory Size

Ref.

https://nebl.io/neblio-university/enabling-increasing-raspberry-pi-swap/

หยุด Swap ชั่วคราว:

sudo dphys-swapfile swapoff

แก้ไขไฟล์ config

sudo nano /etc/dphys-swapfile

แก้บรรทัดกำหนดขนาดเป็นขนาดที่ต้องการ

CONF_SWAPSIZE=1024

Initialize Swap File & Start Swap

sudo dphys-swapfile setup
sudo dphys-swapfile swapon

6.ติดตั้ง DOCKER (ไม่ต้องใช้ sudo) ใช้ User Pi ห้ามติดตั้งด้วย User ธรรมดา

curl -sSL https://get.docker.com | sh
#sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker ps

ตัวอย่างหน้าจอตอนติดตั้ง

Client: Docker Engine - Community
Version: 26.1.4
API version: 1.45
Go version: go1.21.11
Git commit: 5650f9b
Built: Wed Jun 5 11:29:12 2024
OS/Arch: linux/arm64
Context: default

Server: Docker Engine - Community
Engine:
Version: 26.1.4
API version: 1.45 (minimum version 1.24)
Go version: go1.21.11
Git commit: de5c9cf
Built: Wed Jun 5 11:29:12 2024
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.33
GitCommit: d2d58213f83a351ca8f528a95fbd145f5654e957
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0

================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================

ดู Version ใช้คำสั่ง docker -v

pi@raspberrypi:/etc $ docker -v
Docker version 27.0.3, build 7d4bcd8

และติดตั้ง Docker Composer

sudo curl -L "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

เปิด github https://github.com/docker/compose/releases/ ดู latest version แล้วแก้หลัง /v ถ้าต้องการลง Version ล่าสุด

7.ติดตั้ง Portainer

ดู Version ที่มีอยู่

https://github.com/portainer/portainer/releases
sudo docker run -d --restart always -p 9000:9000 --name portainer -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.20.2

ติดตั้งเสร็จต้องรีบตั้ง Password ใหม่ ถ้าเลยเวลาจะเจอข้อความ

เรียกใช้โดยใช้ Port 9000

http://[RASPBERRY_PI_IP_ADDRESS]:9000

ตั้ง User Name/Password admin/ยาว 8/12 ตัวอักษร
เช่น admin/m2mlorawan หรือ m2mlorawan123

คลิก ICON รูปเรือ

ดู Version ที่มุมล่างซ้าย

Upgrade Portainer Version ใหม่

docker stop portainer
docker rm portainer

แล้วลงใหม่ แม้จะลงใหม่ค่า Password Admin ที่ตั้งไว้จะเป็นตัวเก่าไม่ได้กลับไปเป็น Default

การเริ่ม Portainer ใหม่

pi@raspberrypi:~ $ sudo docker stop portainer
pi@raspberrypi:~ $ sudo docker start portainer
Template เดิม https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json

8.ติดตั้ง Chirpstack V.4X บน Docker ติดตั้ง

ใช้ user root ติดตั้งโดย

sudo su
cd /home/pi
git clone https://github.com/brocaar/chirpstack-docker.git
cd chirpstack-docker

แก้ความถี่จาก eu868 เป็น as923

nano /home/pi/chirpstack-docker/docker-compose.yml
    environment:
- INTEGRATION__MQTT__EVENT_TOPIC_TEMPLATE=eu868/gateway/{{ .GatewayID }}/event/{{ .EventType }}
- INTEGRATION__MQTT__STATE_TOPIC_TEMPLATE=eu868/gateway/{{ .GatewayID }}/state/{{ .StateType }}
- INTEGRATION__MQTT__COMMAND_TOPIC_TEMPLATE=eu868/gateway/{{ .GatewayID }}/command/#
environment:
- INTEGRATION__MQTT__EVENT_TOPIC_TEMPLATE=as923/gateway/{{ .GatewayID }}/event/{{ .EventType }}
- INTEGRATION__MQTT__STATE_TOPIC_TEMPLATE=as923/gateway/{{ .GatewayID }}/state/{{ .StateType }}
- INTEGRATION__MQTT__COMMAND_TOPIC_TEMPLATE=as923/gateway/{{ .GatewayID }}/command/#

และแก้เพิ่มความถี่ให้ครบ 8 ช่องความถี่

nano /home/pi/chirpstack-docker/configuration/chirpstack/region_as923.toml

เพิ่มตรงด้านล่างสุดของไฟล์

[[regions.network.extra_channels]]
frequency=923600000
min_dr=0
max_dr=5
[[regions.network.extra_channels]]
frequency=923800000
min_dr=0
max_dr=5
[[regions.network.extra_channels]]
frequency=924000000
min_dr=0
max_dr=5
[[regions.network.extra_channels]]
frequency=924200000
min_dr=0
max_dr=5
[[regions.network.extra_channels]]
frequency=924400000
min_dr=0
max_dr=5
[[regions.network.extra_channels]]
frequency=924600000
min_dr=0
max_dr=5

*ถ้าจะให้ติดตั้ง Chirpstack เวอร์ชั่นล่าสุด เช่น 4.9 ให้แก้ไฟล์ docker-compose.yml เพิ่มเติมตรง :4 ให้แก้เป็น :latest แทน

แก้ mqtt Server ถ้าจะใช้ mqtt

nano /home/pi/chirpstack-docker/configuration/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
# See https://www.chirpstack.io/gateway-bridge/install/config/ for a full
# configuration example and documentation.

[integration.mqtt.auth.generic]
servers=["tcp://mosquitto:1883"]
username=""
password=""

เสร็จแล้วสั่งเริ่มสร้าง Container

cd /home/pi/chirpstack-docker/
sudo docker-compose up -d

เรียกใช้ Chirpstack ที่ Port:8080
ใช้ User/Password admin/admin

ลองดู Regions ว่ามีความถี่ครบ 8 ช่องที่ as923

9.เช็ค Version ของ Chirpstack

pi@raspberrypi:~ $ sudo docker exec -u root  -it chirpstack-docker-chirpstack-1 /usr/bin/chirpstack --version
chirpstack 4.5.1

หรือ

pi@raspberrypi:~ $ sudo docker exec -u root  -it chirpstack-docker-chirpstack-1 /bin/sh
/ # chirpstack --version
chirpstack 4.5.1

หรือ คลิก Container ชื่อ chirpstack-docker-chirpstack-1

คลิกที่ Console

เลือก Command /bin/sh แล้วกด Connect

จะเข้าไปที่ sh ใน Container สามารถใช้คำสั่งเช็ค version ได้ตามภาพ

เรียกใช้ Chirp ที่ Port:8080
ใช้ User/Password admin/admin

ลองดู Regions ว่ามีความถี่ครบ 8 ช่องที่ as923

หลัง Reboot Server ตอนเข้าใช้งาน ถ้าเจอ Error “context deadline exceeded (code: 2) error” ตอน Add NS ให้ดู IP ของ NS ชื่อ chirpstack/chirpstack-network-server:3 บน Docker Portainer ว่าเป็น IP อะไร ใช้ IP นั้นแทน

เรียกใช้งาน ChirpSatck REST API V.4.4.0

เรียกใช้ http://IP:8090/

10. ติดตั้ง Influxdb 2.7.5 บน Raspbian 64

ดู Version ล่าสุด เปิด https://hub.docker.com/ ค้น influxdb หรือเปิดตรง
https://hub.docker.com/_/influxdb

ใช้ User Pi ติดตั้ง

sudo docker pull influxdb:2.7.6
sudo docker run -d --restart always -p 8086:8086 --name=influxdb   -v influxdb:/var/lib/influxdb  influxdb:2.7.6

ทดสอบ influx โดย

sudo docker exec -it influxdb influx

ถ้าทำงานปรกติจะเห็น

วิธีใช้งานและการเตรียม Influxdb 2.X สำหรับเก็บข้อมูล Sensor

https://www.influxdata.com/blog/getting-started-with-influxdb-2-0-ppscraping-metrics-running-telegraf-querying-data-and-writing-data/

เปิด http://ip:8086

คลิก Get Started

user :admin
password :influx123
Organization :Influxdata
Initial Bucket Name :system

จะเจอหน้า

คลิก Quick Start

เช็ค Version เข้า Console Influxdb บน Portainner

root@23a3a0a4739e:/# influxd version
InfluxDB v2.7.6 (git: 3c58c06206) build_date: 2024–04–12T21:51:37Z

หรือ

pi@raspberrypi:~ $ curl -sL -I localhost:8086/ping
HTTP/1.1 204 No Content
Vary: Accept-Encoding
X-Influxdb-Build: OSS
X-Influxdb-Version: v2.7.6
Date: Fri, 07 Jun 2024 02:04:19 GMT

ทดสอบ Influx ผ่าน API

pi@raspberrypi:~ $ curl localhost:8086/health
{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[], "version": "v2.7.5", "commit": "09a9607fd9"}

ถ้าต้องการให้แสดงออกหน้าจอรูปแบบ Json ให้ส่งต่อไปที่คำสั่ง json_pp

curl localhost:8086/health|python -m json.tool หรือ
curl localhost:8086/health|json_pp

ถ้าจะให้แสดง JSON แบบสีให้ติดตั้ง jq

sudo apt install jq

แล้วเรียกคำสั่งเช่น

curl localhost:8086/health|jq

คำสั่ง json_reformat

ติดตั้งโดยคำสั่ง

sudo apt install yajl-tools

แสดงชื่อ Bucket ออกมาทั้งหมด

curl http://localhost:8086/api/v2/buckets — header “Authorization: Token your_api_token”

ดูเพิ่มเติมที่ https://www.influxdata.com/blog/getting-started-influxdb-api/

ดูเพิ่มเติม https://jet.dev/blog/secure-influxdb-setup-with-docker/

11. ติดตั้ง Grafana บน docker ใช้ User Pi

ดู version ล่าสุดที่

sudo docker volume create grafana-storage
sudo docker run -d --restart always -p 3000:3000 --name=grafana -v grafana-storage:/var/lib/grafana grafana/grafana

เรียกใช้งาน http://IP address:3000

Password เดิม admin/admin
ตั้งใหม่เป็น admin/grafana

ดู Version Grafana
เข้า Console Grafana ใน Portainer ใช้คำสั่ง

7ef3a79fa89c:~$ grafana -v
grafana version 10.3.3

12.ติดตั้ง NodeRed บน Docker

ref:https://nodered.org/docs/getting-started/docker

ใช้ User Pi ติดตั้ง

sudo docker run -d --restart always -it -p 1880:1880 -v node_red_data:/data --name nodered nodered/node-red

portเรียกใช้ :1880 ใช้ Username/Password คือ admin/admin

13.Port ที่ใช้

8123 Home Assistant
80 Midas Helium Miner Cotx Firware (cotx4umidas)
554 Yoosee IP cam

เรียกใช้

Portainer ที่ Port:9000 admin/m2mlorawan123
Chirpstack ที่ Port:8080 admin/admin
Grafana ที่ Port:3000 admin/grafana
InfluxDB ที่ Port:8086 admin/influx123
NodeRed ที่ Port:1880
Dragino Gateway ที่ Port:8000 admin/dragino
Dragino 10.130.1.1 ssh port 2222, web admin port

14. Add Printer ตัวอย่าง Brother HL-1210W

ให้ทำที่ Console เท่านั้น Remote เข้าไปจะไม่เห็น Network Printer
ก่อนอื่นให้ติดตั้ง Driver Printer Brother ก่อนด้วยคำสั่ง

sudo apt-get install printer-driver-brlaser

เลือก Print Setting ใน Preferences

คลิกที่ Network Printer ถ้า Printer Brother ต่อ Wifi อยู่แล้วจะเจอชื่อ Printer

ให้คลิกชื้อ Printer Brother HL-1210W ตัวล่าง ซึ่งเชื่อมต่อแบบ AppSocket/JetDirect via DNS-SD

เลือก Driver ยี่ห้อ Brother

เลือกรุ่น HL-1200

คลิก Apply

เลือกทดสอบโดยการคลิก Print Test Page

คลิก Print Test Page อีกครั้ง

ถ้า Printer ใช้งานได้ปรกติ จะเห็น Icon Printer พร้อมเครื่องหมายติกถูกสีเขียว

15. Capture Screen

ติดตั้ง scrot

sudo apt install scrot

-d SEC
-u active window

16. Home Assistant

แก้ App Template บน Portainer เป็น

https://raw.githubusercontent.com/technorabilia/portainer-templates/main/lsio/templates/templates-2.0.json

หรือ

https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json

Deploy Container Homeassistant

เรียกใช้

https://localhost:8123

17. ดูว่า Raspberry Pi Hardware Revision เท่าไร

pi@raspberrypi:/tmp $ cat /sys/firmware/devicetree/base/model;echo
Raspberry Pi 4 Model B Rev 1.5

หรือ

cat /proc/cpuinfo

ดูด้านล่าง

Revision : d03115
Serial : 100000006b63ed73
Model : Raspberry Pi 4 Model B Rev 1.5

Pi4B Rev 1.5 ใน Proc Info ไม่มีข้อมูล Hardware

Hardware : BCM2835
Revision : c03114
Serial : 10000000bc5a0020
Model : Raspberry Pi 4 Model B Rev 1.4

18.วิธ๊ลง .deb ที่ Download มา

sudo dpkg -i .deb

19. NMAP Scan Port

nmap -v -A 192.168.1.100
Starting Nmap 7.93 ( https://nmap.org ) at 2024–01–01 17:07 +07
NSE: Loaded 155 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 17:07
Completed NSE at 17:07, 0.00s elapsed
Initiating NSE at 17:07
Completed NSE at 17:07, 0.00s elapsed
Initiating NSE at 17:07
Completed NSE at 17:07, 0.00s elapsed
Initiating Ping Scan at 17:07
Scanning 192.168.1.100 [2 ports]
Completed Ping Scan at 17:07, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 17:07
Completed Parallel DNS resolution of 1 host. at 17:07, 0.02s elapsed
Initiating Connect Scan at 17:07
Scanning 192.168.1.100 [1000 ports]
Discovered open port 22/tcp on 192.168.1.100
Discovered open port 8080/tcp on 192.168.1.100
Discovered open port 3389/tcp on 192.168.1.100
Discovered open port 9000/tcp on 192.168.1.100
Discovered open port 3001/tcp on 192.168.1.100
Discovered open port 8086/tcp on 192.168.1.100
Discovered open port 8090/tcp on 192.168.1.100
Discovered open port 3000/tcp on 192.168.1.100
Completed Connect Scan at 17:07, 0.18s elapsed (1000 total ports)
Initiating Service scan at 17:07
Scanning 8 services on 192.168.1.100

20. ssh เข้า Dragino LPS8N-AS923-TH

$ ssh -i key.pem root@192.168.1.179 -p 2222  -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa

อ้างอิง link https://medium.com/@akshaybengani/getting-started-with-homeassistant-using-docker-6621f7ee920f

21. Backup ด้วย Deja-dup

ติดตั้งด้วยคำสั่ง

sudo apt update
sudo apt upgrade
sudo apt install deja-dup

เรียกใช้ที่ Accessories Backups

ใช้ Backup ลง SAMBA File Server หรือ smb

ให้เลือก General Location เป็น Network Server

Server Address เช่น

smb://kimax/sda1

Folder

raspberrypi เป็นต้น

Network Server รองรับหลาย Protocol เช่น

22. Disk Usage Analyzer

sudo apt install baobab

23.lscpu

pi@raspberrypi:~ $ lscpu
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0–3
Vendor ID: ARM
Model name: Cortex-A72
Model: 3
Thread(s) per core: 1
Core(s) per cluster: 4
Socket(s): -
Cluster(s): 1
Stepping: r0p3
CPU(s) scaling MHz: 100%
CPU max MHz: 1800.0000
CPU min MHz: 600.0000
BogoMIPS: 108.00
Flags: fp asimd evtstrm crc32 cpuid
Caches (sum of all):
L1d: 128 KiB (4 instances)
L1i: 192 KiB (4 instances)
L2: 1 MiB (1 instance)
Vulnerabilities:
Gather data sampling: Not affected
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Not affected
Retbleed: Not affected
Spec rstack overflow: Not affected
Spec store bypass: Vulnerable
Spectre v1: Mitigation; __user pointer sanitization
Spectre v2: Vulnerable
Srbds: Not affected
Tsx async abort: Not affected

24.เช็คว่า SDcard เร็วพอหรือเปล่า

เรียกโปรแกรม RAspberry Pi Diagnostics

25. จาก MS Windows ต้องการ Mount Share ของ SAMBA

รูปแบบ เช่น

pushd \\192.168.1.75\sdc1

ยกเลิก

popd \\192.168.1.75\sdc1

26.ดู IP

pi@raspberrypi:~ $ hostname -I
192.168.1.100 172.18.0.1 172.17.0.1 2403:6200:88a0:44db:e65f:1ff:fe5d:813d

27. ติดตั้ง SAMBA

sudo apt update && sudo apt upgrade -y
sudo apt-get install samba samba-common-bin
sudo mkdir -m 1777 /home/pi/shared
sudo nano /etc/samba/smb.conf

ต่อท้ายไฟล์ด้วย

[pimyshare]
path = /home/pi/shared
writeable=Yes
create mask=0777
directory mask=0777
public=no

สร้าง User ที่เข้าใช้ share ต้องเป็น user ของ Raspbian หากยังไม่ได้เป็น ให้
sudo adduser user ก่อน

sudo smbpasswd -a pi

Restart smbd

sudo systemctl restart smbd

ใช้ netscan

คลิกที่ pimyshare จะมี หน้าต่างให้ป้อน user/password ของ smbd ที่เราสร้างไว้คือ user pi

เรียกใช้อีกวิธี \\192.168.1.X

จะเห็น share ที่ใช้งานได้

เรียกโดยการ Map Network Drive

อีกวิธีคือ เปิด command ด้วย Administrator authorize แล้ว

net use X: \\192.168.1.100\pimyshare /user:pi somsak

map ด้วยคำสั่ง net use

หากต้องการ snapshot เช่น

c:\snapshot1.5 HD1:1+HD1:2+HD1:3+c: z:\$day$month$yearFull$disk-DRIVE.sna

ยกเลิก map

net use X: /delete

ใช้ smbclient

smbclient -L 192.168.12.14 -U pi
Enter pi's password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.5-Ubuntu]

Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
pimyshare Disk
IPC$ IPC IPC Service (Samba 4.4.5-Ubuntu)
pi Disk Home Directories
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.5-Ubuntu]

Server Comment
--------- -------
DLINK-03A0A7
MAIL4 mail4 server (Samba, Ubuntu)

Workgroup Master
--------- -------
NAS CLOUD
WORKGROUP MAIL4

28.ติดตั้ง Webmin

29. ติดตั้ง Apache2 และ php

30.ติดตั้ง DHCP Server

31.ดู CPU Temp

sudo vcgencmd measure_temp
temp=60.9'C

https://linuxconfig.org/how-to-check-temperature-on-raspberry-pi

32.NVME SSD

ดู Log

sudo journalctl -b | grep -i nvme
Aug 07 13:58:50 raspberrypi kernel: Kernel command line: reboot=w coherent_pool=1M 8250.nr_uarts=1 pci=pcie_bus_safe smsc95xx.macaddr=D8:3A:DD:C4:1E:81 vc_mem.mem_base=0x3fc00000 vc_mem.mem_size=0x40000000 console=ttyAMA10,115200 console=tty1 root=PARTUUID=94a98bc2-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=TH nvme_core.default_ps_max_latency_us=0 pcie_aspm=off
Aug 07 13:58:50 raspberrypi kernel: nvme nvme0: pci function 0000:01:00.0
Aug 07 13:58:50 raspberrypi kernel: nvme 0000:01:00.0: enabling device (0000 -> 0002)
Aug 07 13:58:50 raspberrypi kernel: nvme nvme0: missing or invalid SUBNQN field.
Aug 07 13:58:50 raspberrypi kernel: nvme nvme0: allocated 64 MiB host memory buffer.
Aug 07 13:58:50 raspberrypi kernel: nvme nvme0: 4/0/0 default/read/poll queues
Aug 07 13:58:50 raspberrypi kernel: nvme nvme0: Ignoring bogus Namespace Identifiers
Aug 07 13:58:50 raspberrypi kernel: nvme0n1: p1 p2
Aug 07 13:58:50 raspberrypi kernel: EXT4-fs (nvme0n1p2): mounted filesystem 4aa56689-dcb4-4759-90e6-179beae559ac ro with ordered data mode. Quota mode: none.
Aug 07 13:58:50 raspberrypi kernel: EXT4-fs (nvme0n1p2): re-mounted 4aa56689-dcb4-4759-90e6-179beae559ac r/w. Quota mode: none.
Aug 07 13:58:51 raspberrypi systemd-fsck[416]: /dev/nvme0n1p1: 377 files, 19240/130812 clusters

Test Speed

ติดตั้ง hdparm

sudo apt-get install hdparm
pi@raspberrypi:~ $ sudo hdparm -Tt --direct /dev/nvme0n1

/dev/nvme0n1:
Timing O_DIRECT cached reads: 836 MB in 2.00 seconds = 417.41 MB/sec
Timing O_DIRECT disk reads: 1260 MB in 3.00 seconds = 419.37 MB/sec

ติดตั้ง smartmontools

sudo apt install smartmontools
pi@raspberrypi:~ $ sudo smartctl -c /dev/nvme0
smartctl 7.3 2022-02-28 r5338 [aarch64-linux-6.6.31+rpt-rpi-2712] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Firmware Updates (0x12): 1 Slot, no Reset required
Optional Admin Commands (0x0017): Security Format Frmw_DL Self_Test
Optional NVM Commands (0x0015): Comp DS_Mngmt Sav/Sel_Feat
Log Page Attributes (0x03): S/H_per_NS Cmd_Eff_Lg
Maximum Data Transfer Size: 64 Pages
Warning Comp. Temp. Threshold: 83 Celsius
Critical Comp. Temp. Threshold: 85 Celsius

Supported Power States
St Op Max Active Idle RL RT WL WT Ent_Lat Ex_Lat
0 + 6.00W - - 0 0 0 0 15000 0

Supported LBA Sizes (NSID 0x1)
Id Fmt Data Metadt Rel_Perf
0 + 512 0 0

Optimize

pi@raspberrypi:~ $ sudo fstrim -av
/boot/firmware: 435.8 MiB (456998912 bytes) trimmed on /dev/nvme0n1p1
/: 420.1 GiB (451088744448 bytes) trimmed on /dev/nvme0n1p2

Edit Boot Parameter

sudo nano /boot/firmware/cmdline.txt
nvme_core.default_ps_max_latency_us=0 pcie_aspm=off

ติดตั้ง NVME App

sudo apt install nvme-cli
sudo nvme get-feature /dev/nvme0 -H
get-feature:0x01 (Arbitration), Current value:0x00000006
High Priority Weight (HPW): 1
Medium Priority Weight (MPW): 1
Low Priority Weight (LPW): 1
Arbitration Burst (AB): 64
get-feature:0x02 (Power Management), Current value:00000000
Workload Hint (WH): 0 - No Workload
Power State (PS): 0
get-feature:0x03 (LBA Range Type), Current value:00000000
Number of LBA Ranges (NUM): 1
type : 0 - Reserved
attributes : 0x1 - LBA range may be overwritten, LBA range should be visible from the OS/EFI/BIOS
slba : 0
nlb : 0x3b9e12af
guid : 00000000000000000000000000000000
get-feature:0x04 (Temperature Threshold), Current value:0x00000164
Threshold Type Select (THSEL): 0 - Over Temperature Threshold
Threshold Temperature Select (TMPSEL): 0 - Composite Temperature
Temperature Threshold (TMPTH): 83ฐC (356 Kelvin)
get-feature:0x05 (Error Recovery), Current value:00000000
Deallocated or Unwritten Logical Block Error Enable (DULBE): Disabled
Time Limited Error Recovery (TLER): 0 ms
get-feature:0x06 (Volatile Write Cache), Current value:0x00000001
Volatile Write Cache Enable (WCE): Enabled
get-feature:0x07 (Number of Queues), Current value:0x00070007
Number of IO Completion Queues Allocated (NCQA): 8
Number of IO Submission Queues Allocated (NSQA): 8
get-feature:0x08 (Interrupt Coalescing), Current value:00000000
Aggregation Time (TIME): 0 usec
Aggregation Threshold (THR): 1
get-feature:0x09 (Interrupt Vector Configuration), Current value:0x00010000
Coalescing Disable (CD): True
Interrupt Vector (IV): 0
get-feature:0x0a (Write Atomicity Normal), Current value:0x00000001
Disable Normal (DN): True
get-feature:0x0b (Async Event Configuration), Current value:0x00000200
Discovery Log Page Change Notices : Do not send async event
Endurance Group Event Aggregate Log Change Notices : Do not send async event
LBA Status Information Notices : Do not send async event
Predictable Latency Event Aggregate Log Change Notices : Do not send async event
Asymmetric Namespace Access Change Notices : Do not send async event
Telemetry Log Notices : Do not send async event
Firmware Activation Notices : Send async event
Namespace Attribute Notices : Do not send async event
SMART / Health Critical Warnings : Do not send async event
get-feature:0x0d (Host Memory Buffer), Current value:0x00000001
Enable Host Memory (EHM): Enabled
Host Memory Descriptor List Entry Count (HMDLEC): 2
Host Memory Descriptor List Address (HMDLAU): 0x11
Host Memory Descriptor List Address (HMDLAL): 0xeb4000
Host Memory Buffer Size (HSIZE): 16384
get-feature:0x10 (Host Controlled Thermal Management), Current value:0x01520157
Thermal Management Temperature 1 (TMT1) : 338 Kelvin (65ฐC)
Thermal Management Temperature 2 (TMT2) : 343 Kelvin (70ฐC)

nvme error log

sudo nvme error-log /dev/nvme0

smart log

pi@raspberrypi:~ $ sudo nvme smart-log -H /dev/nvme0
Smart Log for NVME device:nvme0 namespace-id:ffffffff
critical_warning : 0
Available Spare[0] : 0
Temp. Threshold[1] : 0
NVM subsystem Reliability[2] : 0
Read-only[3] : 0
Volatile mem. backup failed[4] : 0
Persistent Mem. RO[5] : 0
temperature : 36ฐC (309 Kelvin)
available_spare : 100%
available_spare_threshold : 10%
percentage_used : 0%
endurance group critical warning summary: 0
Data Units Read : 287,793 (147.35 GB)
Data Units Written : 400,572 (205.09 GB)
host_read_commands : 2,099,326
host_write_commands : 2,351,951
controller_busy_time : 323
power_cycles : 58
power_on_hours : 131
unsafe_shutdowns : 17
media_errors : 0
num_err_log_entries : 0
Warning Temperature Time : 0
Critical Composite Temperature Time : 0
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0

33.Boot SSD ด้วยสาย USB-SATA ของจีนด้วย Port USB 3.0 ไม่ได้

ดูยี่ห้อของสาย

lsusb && lsusb -t
Bus 002 Device 002: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS578 SATA 6Gb/s
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c534 Logitech, Inc. Nano Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
|__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 3: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 12M

ดูบรรทัด usb-storage ต่อที่ BUS 2 DEVICE 2 คือบรรทัดแรก JMicron

ดูบรรทัด ID 152d:0578 JMicron Technology Corp.

แก้ไฟล์ Bootloader Parameter

sudo nano /boot/firmware/cmdline.txt

ใส่ไว้หน้าบรรทัด

usb-storage.quirks=152d:0578:u ...

ถึงแม้เพิ่มแล้วหากเปลี่ยนไปใช้สายยี่ห้ออื่นก็ยัง Boot ได้ปรกติ เช่น สาย UGREEN เป็นต้น

หากเป็นสายรุ่น Initio Corporation INIC-3639

lsusb && lsusb -t
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 13fd:3960 Initio Corporation INIC-3639
Bus 001 Device 003: ID 046d:c534 Logitech, Inc. Nano Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 1: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 3: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M
usb-storage.quirks=13fd:3960:u

หากเป็นรุ่น Other World Computing

Bus 002 Device 002: ID 7825:a2a4 Other World Computing External SATA Hard Drive Adapter cable PA023U3
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c534 Logitech, Inc. Nano Receiver
Bus 001 Device 003: ID 214b:7250 Huasheng Electronics USB2.0 HUB
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~ $

Wavelink

Bus 002 Device 002: ID 7825:a2a4 Other World Computing External SATA Hard Drive Adapter cable PA023U3
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c534 Logitech, Inc. Nano Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

34.ดูความเร็ว Benchmark SSD

ใช้สาย SATA Jmicron ต่อ USB 3.0

sudo hdparm -Ttv /dev/sda1

/dev/sda1:
multcount = 1 (on)
readonly = 0 (off)
readahead = 256 (on)
geometry = 65535/255/63, sectors = 1048576, start = 8192
Timing cached reads: 2104 MB in 2.00 seconds = 1052.63 MB/sec
Timing buffered disk reads: 512 MB in 2.66 seconds = 192.65 MB/sec

ใช้สาย UGREEN

sudo hdparm -Ttv /dev/sda1

/dev/sda1:
multcount = 1 (on)
readonly = 0 (off)
readahead = 131064 (on)
geometry = 65535/255/63, sectors = 1048576, start = 8192
Timing cached reads: 2248 MB in 2.00 seconds = 1124.50 MB/sec
Timing buffered disk reads: 512 MB in 1.73 seconds = 295.53 MB/secสาย

สาย Initio Corporation INIC-3639

pi@raspberrypi:~ $ sudo hdparm -Ttv /dev/sda1

/dev/sda1:
multcount = 1 (on)
readonly = 0 (off)
readahead = 256 (on)
geometry = 65535/255/63, sectors = 1048576, start = 8192
Timing cached reads: 2188 MB in 2.00 seconds = 1094.22 MB/sec
Timing buffered disk reads: 478 MB in 3.00 seconds = 159.12 MB/sec

35.วิธีติดตั้ง MiniDLNA Server

sudo apt update 
sudo apt upgrade
sudo apt install minidlna

Config

sudo nano /etc/minidlna.conf

แก้

media_dir=A,/mnt/mediaDrive/audio
media_dir=P,/mnt/mediaDrive/pictures
media_dir=V,/mnt/mediaDrive/videos

friendly_name=PiMyLifeUpMiniDLNA

restart process

sudo systemctl restart minidlna

เช็คที่ Port 8200

หรือดูจาก Xplorer ที่ Network

36. Mosquitto Client

ติดตั้ง

sudo apt install -y mosquitto-clients

ตัวอย่างการใช้งานกับ Chirpstack

ดู Uplink Payload และอื่นๆ

mosquitto_sub -t “application/+/device/+/event/up” -v -h 192.168.1.100

Downlink Topic

เปิด Switch ส่ง 010203

mosquitto_pub -t "application/3f9e3205-b474-4949-9b16-1ab1142f8393/device/1200000000000002/command/down" -h 192.168.1.100 -m   "{\"devEui\": \"1200000000000002\",\"confirmed\": true,\"fPort\": 1, \"data\": \"AQID\" }

ปิด Switch ส่ง 040506

mosquitto_pub -t "application/3f9e3205-b474-4949-9b16-1ab1142f8393/device/1200000000000002/command/down" -h 192.168.1.100 -m   "{\"devEui\": \"1200000000000002\",\"confirmed\": true,\"fPort\": 1, \"data\": \"BAUG\" }"

https://docs.rakwireless.com/Knowledge-Hub/Learn/Use-the-MQTT-Broker-Like-a-Pro/

37. JSON One line to Multiline

https://jsonformatter.org/json-to-one-line

38. โปรแกรมอื่นๆ เช่น

ว่าง

39.ติดตั้ง NOIP หรือ duc

http://www.raspberryhome.net/article/7/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87-client-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%AD%E0%B8%B1%E0%B8%9A%E0%B9%80%E0%B8%94%E0%B8%97-dns-%E0%B8%82%E0%B8%AD%E0%B8%87-no-ip-%E0%B8%9A%E0%B8%99-raspberry-pi

mkdir noip
cd noip
wget https://www.noip.com/client/linux/noip-duc-linux.tar.gz
tar vzxf noip-duc-linux.tar.gz
cd noip-2.1.9–1
sudo make
sudo make install
sudo /usr/local/bin/noip2
sudo noip2 -S

sudo nano /etc/rc.local

แทรกคำสั่ง

/usr/local/bin/noip2

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/usr/local/bin/noip2
exit 0

เช็คค่าที่ตั้งไว้

pi@raspberrypi:~ $ sudo /usr/local/bin/noip2 -S
1 noip2 process active.

Process 873, started as noip2, (version 2.1.9)
Using configuration from /usr/local/etc/no-ip2.conf
Last IP Address set 49.49.240.124
Account m2m@gmail.com
configured for:
host m2m.ddns.net
Updating every 30 minutes via /dev/eth0 with NAT enabled.

40. Show IP no.

hostname -I
192.168.1.101 2403:6200:88a1:4231:e65f:1ff:fe31:9362

41. Show Bootloader Version

pi@raspberrypi:~ $  vcgencmd bootloader_version
2024/07/30 14:02:35
version 5f18ffb61682740ed1751ba59952843d7521314f (release)
timestamp 1722344555
update-time 1724161230
capabilities 0x0000007f

42. Show Sata3 to USB chip


pi@raspberrypi:~ $ lsusb
Bus 002 Device 002: ID 13fd:3960 Initio Corporation INIC-3639
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c534 Logitech, Inc. Nano Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~ $

Bootloader Version 2024/07/30 สามารถ boot สาย USB-SATA ที่ใช้ Chip Initio Corporation INIC-3639 ได้แล้ว ไม่ต้องแก้เพิ่มอะไรใน Command Line

43. Remove RPI-connect

sudo apt install rpi-connect

44. Build Custom MicroPython Firmware

cd /micropython/ports/esp32
idf.py build

/home/pi/docker-micropython-build-master /project

0x1000 build/bootloader/bootloader.bin
0x8000 build/partition_table/partition-table.bin
0x10000 build/micropython.binls

locate micropython/ports

45. Format SSD ใหม่

เลือก Erase Format card as FAT32

Format แล้วจะเป็น MBR ไม่ใช้ GPT และเป็น FAT32 สำหรับเขียน Boot Image

46.หาก TTN เจอ Error

Downlink Transmission Fail with result COLLISION_PACKET

ให้ Disable Dragino Gateway ในส่วน Secondary LoRaWAN Server

47.Remote IT ใน PI

เข้าเวป https://app.remote.it

เลือก Raspberry Pi

Copy Script คำสั่งที่ Remote IT สร้างขึ้นมา ตัวอย่าง เช่น

R3_REGISTRATION_CODE="8B6F3B6A-0D79-5EB5-86FC" sh -c "$(curl -L https://downloads.remote.it/remoteit/install_agent.sh)"

ไป RUN ใน PI จะขึ้นชื่อเครื่องอัตโนมัติมาให้เลือก Connect

เพิ่ม Service RDP

คลิก + หลัง Service คลิกที่ TAB RDP แล้วกด SAVE

จะเห็น Service RDP เพิ่มเข้ามา รอสักครู่จะเห็น CONNECT สามารถเชื่อมต่อได้

ตอนเชื่อมต่อ RDP

ให้คลิก CONNECT จะมีชื่อ Host และ Port ขึ้นมา ให้ Copy ไปใช้กับโปรแกรม Remote Desktop

48.วิธีติดตั้ง Qbtorrent

ใช้ Add/Remove Software ใน Preferences

พิมพ์ torrent ในช่องค้นหา เลือก bittorrent client based on libtorrent-rasterbar wit Qt5 GUI หรือ ด้านล่างเขียนว่า qbittorent-version

49.คำสั่ง Linux

ดูจาก FB. Dan Nanni

ตัวอย่าง เช่น

49.Docker Command

มี Image อะไรให้ใช้บ้างดูที่ https://hub.docker.com/

ลองค้นแต่ Official Image

เช่น

 docker run --name myweb -p 80:80 -v /myweb:/usr/share/nginx/html -d nginx

https://hub.docker.com/r/satmandu/raspios/tags Raspbian Image

50.ติดตั้ง OPENVPN

ดูที่ https://dockovpn.io/docs/quickstart/

docker run -it --rm --cap-add=NET_ADMIN \
-p 1194:1194/udp -p 80:8080/tcp \
-e HOST_ADDR=$(curl -s https://api.ipify.org) \
--name dockovpn alekslitvinenk/openvpn

ดาวน์โหลด Config ไฟล์ได้จากคำแนะนำตอนติดตั้ง ตรงข้อความ เช่น

download your client.ovpn config at http://81.198.169.234/

จะได้ File client.vpn

ดาวน์โหลด Client สำหรับ Winsows ได้ที่
https://openvpn.net/client/client-connect-vpn-for-windows/

ติดตั้งแล้วเรียกโปรแกรม openvpn

คลิก TAB Upload File

ยกไฟล์ client.vpn ลงมาวาง

จะเห็นว่าเริ่มใช้งานได้

50.Scannet

sudo nmap -sS -O 192.168.1.0/24 

51. Proxmox

How to Install Proxmox on the Raspberry Pi คลิก

Installing Proxmox on Raspberry Pi 4 and 5 คลิก

I built a Proxmox home lab using my Raspberry Pi คลิก

How to install Windows 11 on your Raspberry Pi คลิก

52. ทำ Pi ให้เป็น Wifi Router ด้วย RaspAP หรือ OpenWRT

https://www.sunfounder.com/blogs/news/the-ultimate-guide-to-transforming-your-raspberry-pi-into-a-powerful-router

53.ss investigate socket

54.atop

55.btop

56.iftop

57.s-tui

58.iotop

59.wavemon

60.

99.Link ที่น่าสนใจ

https://www.framboise314.fr/une-passerelle-lorawan-pour-le-raspberry-pi-chez-elecrow/

--

--

Somsak Lima
Somsak Lima

Written by Somsak Lima

สนับสนุนและส่งเสริมให้ผู้สนใจสามารถใช้งานเทคโนโลยี LoRa และ LoRaWAN ได้ โดยนำความรู้ที่ได้ไปต่อยอดเพื่อใช้งาน

No responses yet