Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

標籤: Raspberry Pi

Reaspberry Pi Pico W 無線網路連線寫法

Posted on 2024 年 6 月 26 日2024 年 6 月 26 日 By 日落 在〈Reaspberry Pi Pico W 無線網路連線寫法〉中尚無留言

Raspberry Pi Pico W Getting Start 的範例程式其實蠻簡單的:

import network
from time import sleep

wlan = network.WLAN(network.STA_IF)

wlan.active(True)
wlan.connect("Zeroplex", "wifi-password")

while wlan.isconnected() == False:
    print('Waiting for connection...')
    sleep(1)

print(wlan.ifconfig())

但事實上這段 Pico W 的行為會和程式碼有一段差距。

先來看一下 active() 這段:

wlan.active(True)
wlan.connect("Zeroplex", "wifi-password")

在啟用 wifi 以後,必須先掃描所有 wifi SSID。掃描會花上一段時間,因此若不先等待掃描完畢,而直接 connect() 可能會出現錯誤,像是「SSID 不存在」之類的。

較好的寫法會是:

wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# wait for SSID scan and discover
sleep(5)

# connect
wlan.connect("Zeroplex", "wifi-password")

# check connection
if False == wlan.isconnected():
    print('failed to connect')
else:
    print('connected')
Tags:Python, Raspberry Pi

使用 Raspberry Pi 作為 lab 機的一些問題

Posted on 2022 年 11 月 12 日2022 年 11 月 13 日 By 日落 在〈使用 Raspberry Pi 作為 lab 機的一些問題〉中尚無留言

為了省錢,買個 Pi 4 Model B 8GB 作為 lab 機,但稍做了一些調整:

  • 安裝 Ubuntu server
  • /var 和 /home 改 mount 到 SSD 上面去
  • 使用 8 port USB hub + 便宜的 USB disk,加上 mdadm 和 lvm 把 disk IO 打散來處理 log
Respberry Pi model B 的系統概況

RPi 4 的 OS 可以使用 Ubuntu 跑起來挺順的,大多數的 package 也都可以安裝,沒遇到什麼問題。

RPi 4 的處理器、記憶體其實都夠快了,只要 disk IO 不要碰到 MicroSD card 跑起來不太會有卡頓的感覺,甚至 bittorrent 把 1 Gbs 網路吃滿也可以穩穩的運作。


這裡開始講一些會遇到的問題。

近期的 lab 已 docker 甚至有一些 k8s 的實驗要跑,但是 RPi 4 的處理器架構為 aarch64,就會遇到一些 image 是不支援 aarch64 的,搞到最後還要自己編譯 base image …. 苦啊。


下次還是存點錢去買 x86 架構的機器做 lab (聽說 Intel NUC 的評語不錯,可考慮) 比較實在。

Tags:Raspberry Pi

Ubuntu 20.04 Failed to Change Password while Using cloud-init

Posted on 2022 年 1 月 22 日2022 年 2 月 22 日 By 日落 在〈Ubuntu 20.04 Failed to Change Password while Using cloud-init〉中尚無留言

Cloud-Init should allow you to modify password after first time login. But if SSH closed while changing password:

WARNING: Your password has expired.
You must change your password now and login again!
Changing password for ubuntu.
Current password:
passwd: Authentication token manipulation error
passwd: password unchanged
Connection to 192.168.0.102 closed.

There might be Cloud-Init issue in older version.

There is a workaround to by-pass force passwd. Find /boot/firmware/user-data in the boot partition, then you will see options:

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
  expire: true
  list:
  - ubuntu:ubuntu

Update expire to false if you do not want to change password in first login. Or create your own username/password in list if expire is not work.

Please notice that device is not safe using default user name and password. Change it after you connect to the device.

Tags:Linux, Raspberry Pi, Ubuntu

提醒自己 – Respberry Pi 4 Model B 的 Wifi 只吃 2.4G

Posted on 2021 年 11 月 2 日2021 年 11 月 7 日 By 日落 在〈提醒自己 – Respberry Pi 4 Model B 的 Wifi 只吃 2.4G〉中尚無留言

手上更新到 Pi 4 的零組件總算都到期了,但是初次安裝不管怎麼樣都連不上 Wifi。
搞了半天原來我根本沒有給 Wifi 2.4G 的連線設定,5G 根本吃不到,所以整理來說腦殘浪費了一小時。

在做個筆記,很久以前提到 Ubuntu 的網路管理已經轉交給 netplan,所以 Ubuntu on Raspberry Pi 4 的狀況也一樣,有線網路、無線網路的設定也必須寫在 /etc/netplan 目錄下,更新以後將設定套用到全系統:

$ sudo netplan generate
$ sudo netplan apply
$ reboot

若需要 netplan 的語法,可以參考 netplan configuration examples。

Tags:Raspberry Pi

給台灣人的 Raspbian 懶人版映象檔

Posted on 2019 年 7 月 6 日2021 年 3 月 12 日 By 日落 在〈給台灣人的 Raspbian 懶人版映象檔〉中尚無留言

這幾天被 Raspbian 安裝搞得七葷八素,所以乾脆把幾個常用設定改好,直接打包給大家用。

我用的是 Raspbian Buster Lite:

  • Version: June 2019
  • Release Date: 2019-06-20
  • Kernal version: 4.19

我調整過的設定 (目標是接上電源線即可遠端操作):

  • Localization
    • Locale:en_US.utf8 + zh_TW.utf8
    • 時區:Asia/Taipei
    • 鍵盤對應:en (US)
    • Wify county:TW
  • SSH 預設啟動 (port 2222)
  • 有線網路自動 DHCP
  • /etc/apt/source.list 的 source 改為 NCHC (快超多)
  • 已經做過一次 apt-get update && apt-get upgrade
載點:https://mega.nz/#F!dR5EVABL!Nkynwg5ivQuRyRqpGz1Q4A

SHA1: 71664d5651d660077621f91b29edeecf4810a486
SHA256: 981a8ded523c30f06ec09292445255c55a862e5d756b4e0fff5f8d069ef35afa
Tags:Linux, Raspberry Pi, Raspbian

其他

關於我  (About me)

小額贊助

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.