Open7
rasberry pi
![Kumassy](https://res.cloudinary.com/zenn/image/fetch/s--5tFNIFu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/85b9558bc7.jpeg)
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $ sudo systemctl status hciuart
● hciuart.service - Configure Bluetooth Modems connected by UART
Loaded: loaded (/lib/systemd/system/hciuart.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-02-21 01:23:41 GMT; 1 months 22 days ago
Main PID: 704 (hciattach)
Tasks: 1 (limit: 1596)
CPU: 272ms
CGroup: /system.slice/hciuart.service
└─704 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow - b8:27:eb:52:3e:33
Feb 21 01:23:35 raspberrypi systemd[1]: Starting Configure Bluetooth Modems connected by UART...
Feb 21 01:23:41 raspberrypi btuart[449]: bcm43xx_init
Feb 21 01:23:41 raspberrypi btuart[449]: Flash firmware /lib/firmware/brcm/BCM43430A1.hcd
Feb 21 01:23:41 raspberrypi btuart[449]: Set BDADDR UART: b8:27:eb:52:3e:33
Feb 21 01:23:41 raspberrypi btuart[449]: Set Controller UART speed to 921600 bit/s
Feb 21 01:23:41 raspberrypi btuart[449]: Device setup complete
Feb 21 01:23:41 raspberrypi systemd[1]: Started Configure Bluetooth Modems connected by UART.
pi@raspberrypi:~ $ sudo systemctl disable hciuart
Removed /etc/systemd/system/dev-serial1.device.wants/hciuart.service.
pi@raspberrypi:~ $ sudo apt install python3-pip
pi@raspberrypi:~ $ sudo pip3 install pyserial
以下のような状態になった
pi@raspberrypi:~ $ ls -l /dev | grep serial
lrwxrwxrwx 1 root root 5 Apr 15 09:13 serial0 -> ttyS0
lrwxrwxrwx 1 root root 7 Apr 15 09:13 serial1 -> ttyAMA0
以下を参考にして serial0 が Primary UART をさすようにする
bluetooth は使わないので無効化しておく
https://toki-blog.com/pi-serial/
https://www.ingenious.jp/articles/howto/raspberry-pi-howto/gpio-uart/
pi@raspberrypi:~ $ sudo tail /boot/config.txt
[all]
[pi4]
# Run as fast as firmware / board allows
arm_boost=1
[all]
enable_uart=1
dtoverlay=disable-bt
pi@raspberrypi:~ $ sudo reboot now
入れ替わった
pi@raspberrypi:~ $ ls -l /dev/ | grep serial
lrwxrwxrwx 1 root root 7 Apr 15 09:19 serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Apr 15 09:19 serial1 -> ttyS0
![Kumassy](https://res.cloudinary.com/zenn/image/fetch/s--5tFNIFu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/85b9558bc7.jpeg)
BP35A1コマンドリファレンスマニュアル(Single-hop Edition)
10.3 Wi-SUN B ルートを想定した通信
この通りに実装する
先ず初めに以下の手順でコーディネータ側を起動します。
SKSETPWD C 0123456789AB
SKSETRBID 00112233445566778899AABBCCDDEEFF
SKSCAN 0 FFFFFFFF 4
![Kumassy](https://res.cloudinary.com/zenn/image/fetch/s--5tFNIFu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/85b9558bc7.jpeg)
本日の学び
![Kumassy](https://res.cloudinary.com/zenn/image/fetch/s--5tFNIFu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/85b9558bc7.jpeg)
既存の実装では
readline
を使って行をわけている。
- https://qiita.com/rukihena/items/82266ed3a43e4b652adb
- https://github.com/rin-ofumi/m5stickc_wisun_hat/blob/9ad6371758b6c25f6b505d6fad2322d1d664007d/test_WiSUN_Ambient.py#L17
- https://rabbit-note.com/2016/12/25/bp35a1-python/
しかし、 ERXUDP
をバイナリで読むと
read b"ERXUDP FE80:0000:0000:0000:0123:4567:89ab:cdef 02CC 02CC XXXXXXXXXXXX 0 0068 \0\0\0h ........ \0\0\n"
read b" ~l9\xb8 ....... D20\r\n"
のようにペイロードの途中で \n
が入ることがあるようだ。
きちんと \r\n
でデータを区切る必要がある
![Kumassy](https://res.cloudinary.com/zenn/image/fetch/s--5tFNIFu5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/85b9558bc7.jpeg)
BP35A1 コマンドリファレンスマニュアル
pp.47
ADDR64
: UINT8[8]
, 端末の IEEE 64bit MAC アドレス