Raspberry Pi OS 64bit Lite (Raspbian Buster Lite)のセットアップ

Raspberry Pi 4 Model B
今回は3Dプリンタで印刷したフレームにRaspberry Pi, 2.5インチ SSD, 6010 ファンを搭載したこいつがターゲット。
USB bootのためのbootloaderの更新は済ませてある。
性能的にはddでの計測で読み書き200MB/s前後、openssl speed -multi 4を回しても60℃未満という感じ。

準備

  1. 64bit版のイメージをダウンロードする Index of /raspios_lite_arm64/images
  2. balenaEtcherでSSDにイメージを焼き、/boot/sshを作る
  3. 電源を繋ぎしばし待つ

メモ

ssh pi@raspberrypi.localraspberryで接続する。
ssh-keygen -t ed25519して~/.ssh/id_ed25519.pubGitHubに登録しておく。
sshdの設定が不安ならssh -v -o PubkeyAuthentication=no pi@raspberrypi.localで試せる。

初期設定

passwd
sudo apt update && sudo apt upgrade

echo "NTP=ntp.nict.jp" | sudo tee -a /etc/systemd/timesyncd.conf

curl -s https://github.com/ebith.keys | tee -a ~/.ssh/authorized_keys

sudo tee -a /etc/ssh/sshd_config << EOM > /dev/null
PasswordAuthentication no
PermitRootLogin no
Port 22
EOM

sudo tee -a /etc/dhcpcd.conf << EOM > /dev/null
interface eth0
static ip_address=192.168.0.81/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 1.1.1.1 8.8.8.8
EOM

sudo hostnamectl set-hostname raspberrypi4b
sudo timedatectl set-timezone Asia/Tokyo
sudo dpkg-reconfigure locales

環境整備

ARMで64bitの環境で今どきのツールなどを使おうとすると概ねバイナリの配布がない。
そもそもDebian系はパッケージがあってもリポジトリは無いということも多く面倒。

sudo apt install git tmux vim
sudo update-alternatives --config editor

公式に従って入れるやつ

自前ビルドのやつ

Rust

curl https://sh.rustup.rs -sSf | sh
source .cargo/env

ghq get starship/starship
cd ghq/github.com/starship/starship/
sed -i -e '/^\[dependencies\]$/a openssl = { version = "0.10.30", features = ["vendored"] }' Cargo.toml
cargo build --release
cp target/release/starship ~/.cargo/bin/

ghq get dandavison/delta
cd ghq/github.com/dandavison/delta
cargo build --release
cp target/release/delta ~/.cargo/bin/

cargo install ripgrep
cargo install bat
cargo install lsd
cargo install fd-find

Go

echo "deb http://deb.debian.org/debian buster-backports main contrib non-free" | sudo tee /etc/apt/sources.list.d/buster-backports.list
sudo apt -t buster-backports install golang
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:$PATH

go get -u github.com/junegunn/fzf
go get -u github.com/x-motemen/ghq

dotfiles

ghq get ebith/dotfiles
cd ghq/github.com/ebith/dotfiles
./create_link.py .config .vim .gitconfig .tmux.conf .yarnrc
mkdir -p ~/.vimlocal/{backup,swap,undo}
chsh -s /usr/bin/fish
sudo systemctl reboot
rm .bash* .profile
fisher

このあと

  • VPSで動かしているのをこっちに移して解約する
  • UPSは無いので停電の際はあきらめる

ATOM Lite(ESP32)でWiFiに常時接続してHTTP POSTする

追記: 公式ライブラリのできがあんまり良くないので使わないやつも書いた M5 ATOM(ESP32)でWiFiに常時接続してHTTP POSTするやつ

めっちゃググったりして頑張ったのでその結果をまとめておく。

#define FASTLED_INTERNAL

#include <M5Atom.h>
#include <WiFi.h>
#include <ArduinoJson.h>
#include <HttpClient.h>

const char* ssid = "**********";
const char* password = "**********";

void post(const char* content) {
  DynamicJsonDocument doc(JSON_OBJECT_SIZE(2));
  doc["title"] = "ATOM Lite Wifi Test";
  doc["content"] = content;
  String json;
  serializeJson(doc, json);

  HTTPClient http;
  http.begin("http://httpbin.org/post");
  http.addHeader("Content-Type", "application/json");
  http.POST(json);
  Serial.println(http.getString());
  http.end();
}

void setup() {
  M5.begin(true, false, true);
  Serial.println();
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    if (M5.Btn.wasPressed()) {
      post("The button was pressed.");
    } 
    delay(50);
    M5.update();
  } else {
    M5.dis.drawpix(0, 0x001000);
    WiFi.begin(ssid, password);
    int wifiReconnectCount = 0;
    while (WiFi.status() != WL_CONNECTED) {
      if (wifiReconnectCount >= 300) { ESP.restart(); }
      wifiReconnectCount++;
      delay(100);
    }
    post("It's now online.");
    M5.dis.drawpix(0, 0x100000);
  }
}

ATOM Liteでインターホン鳴ったりボタン押されたらDiscordに通知するやつ作った

今までRaspberry Pi ZeroでやっていたのをATOM Liteに移した。
特別なことはしていないが慣れていないとそこそこ詰まりどころがあったのでまとめておく。

Grove端子

できあいのケーブルやユニバーサル基板用のメスコネクタは売っているが、ケーブル自作用のコンタクトやハウジングは公式には存在しない。
NS-TECHの1125を使っているらしくSMH200, YST200, HY2.0といったやつが互換品のようだがAliExpressでさえ僅かな店舗が出品しているという程度で入手難度が高い。
JST PHのコンタクトで代替できない事もないが刺さり具合が不安定。
現状日本で買えるのはGrove互換コネクタ HY2.0mm ハウジング・コンタクトピンセット / CON302-HY2-4P-5Pだけの様子。
以前はaitendoでも取り扱いがあったようだが長く入荷が無いらしくコンタクトの在庫が1個あるだけでハウジングは売られていなかった。

PlatformIO on VSCode

ATOM Liteでhttp postしてwebhookを叩いて通知を飛ばすやつ

家のインターホンはボタンが押されると2vが流れる拡張用端子がついていたのでGPIO32とGNDに繋いだ。