Raspberry Pi でスワップファイルを無効にする

スワップファイルを消して、無効にする(永続) :

$ sudo swapoff --all
$ sudo systemctl stop dphys-swapfile
$ sudo systemctl disable dphys-swapfile

check :

$ sudo systemctl is-enabled dphys-swapfile
> disabled

$ sudo systemctl status dphys-swapfile
> Active: inactive (dead)

$ free
> Swap: 0 0 0

参考

行を間引いて表示

分毎のログを大雑把に見るため行を間引いて(スキップして)表示したい。

pythonで書いた。1

#!/usr/bin/env python3

import argparse

def setup_parser():
    p = argparse.ArgumentParser()
    p.add_argument('infile')
    p.add_argument('skip', type=int)
    return p

def lineskip(infile:str, skip:int):
    # 行始めを1とし、指定数の余剰が1の時に表示する
    n = 1
    with open(infile) as f:
        for line in f:
            if (n % skip) == 1:
                print(line, end='')
            n += 1

if __name__ == '__main__':
    parser = setup_parser()
    args   = parser.parse_args()
    lineskip(args.infile, args.skip)

こうする。

% chmod +x lineskip.py
% ./lineskip.py every_minute.csv 60         // 1時間毎に
2023-08-01T10:00:02,  ....
2023-08-01T11:00:03,  ....
2023-08-01T12:00:02,  ....

ちょっと待って欲しい。

こんな汎用的なこと、もっと簡単にできない訳がない。 調べたらawkで1行だった。うーんスゴい。

% awk 'NR%60==1' every_minute.csv

参考


  1. ログのファイルサイズが不明なので、ファイル全体を読むのは避けたい。なのでfor line in f:で行単位で読むのがポイント。

import requests するとエラーが出る

エラーが出る
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3.
原因

requests(==2.30.0)最新版をインストールすると依存関係のurllib3(==2.0.2)最新版がインストールされる。

が、reqeustsはurllib3(==1.21.1~1.26.15)しか対応していないためエラーが出る。多分。

自分の環境
(venv) % python3 --version
Python 3.9.6

(venv) % pip install requests
(venv) % pip list
requests    2.30.0
urllib3     2.0.2

(venv) % python3
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path/to/venv/lib/python3.9/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "path/to/venv/lib/python3.9/site-packages/urllib3/__init__.py", line 38, in <module>
    raise ImportError(
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/2168
古いurllib3を入れると解決する

urllib3最新版に拘りがなければ暫くこれで凌ぐが吉。

(venv) % pip install urllib3==1.26.15
(venv) % pip list
requests    2.30.0
urllib3     1.26.15

(venv) % python3
>>> import requests
>>>

現在(2023-05-06)進行中っぽい事案

構造体が境界調整されるのを回避する(パディング、アライメント)

構造体は境界調整される(パディング=詰め物、アライメント=調整)

コンパイラがデータをメモリに効率良い様に配置する。 奇数アドレスを避け、偶数アドレスにする。 処理系によっては2byte単位ではなく4byte単位になったりする。

typedef struct {
    char  a;    //ADDR=0x00
    //padding_3byte
    int   b;    //ADDR=0x04
    short c;    //ADDR=0x08
    //padding_2byte
} T;            //sizeof(T) == 12

このパディング、アライメントを回避する。

gcc

typedef struct {
    //略
} T __attribute__((__packed__))

g++, VC++

#pragma pack(push, 1)   //1byte
typedef struct {
    //略
} T;
#pragma pack(pop)

パディングなしだとアドレス、サイズが変わる。

#pragma pack(push, 1)
typedef struct {
    char  a;    //ADDR=0x00
    int   b;    //ADDR=0x01
    short c;    //ADDR=0x05
} T;            //sizeof(T) == 7
#pragma pack(pop)

参考

/dev/ttyUSB0をユーザーが使えるようにする

バイスのアクセス権はdialoutグループに所属するユーザー

$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 12月  6 14:11 /dev/ttyUSB0

自分(zumaa)のグループを確認、所属してない

$ id -a
uid=1000(zumaa) gid=1000(zumaa) groups=1000(zumaa),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),109(netdev),113(scanner),116(lpadmin)

グループにユーザーを追加する(=自分の所属グループにdialoutを追加する)

$ sudo gpasswd -a zumaa dialout
$ su - zumaa
(グループ追加を反映するため再ログインする)

or
$ su
# gpasswd -a zumaa dialout
# exit

Linuxでシリアルポートにrootで書き込みできないとき

Debian/Raspbianのバージョン情報

Linuxの情報

$ uname -a
Linux raspberrypi 5.10.103-v7+ #1529 SMP Tue Mar 8 12:21:37 GMT 2022 armv7l GNU/Linux

Debian/Raspbianのバージョン

$ cat /etc/debian_version
10.13

$ cat /etc/issue
Raspbian GNU/Linux 10 \n \l

ディストリビューション情報

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster