LoginSignup
1
1

More than 3 years have passed since last update.

cuiでのラズパイwifi設定と設定ようscript

Posted at

目的

遠隔に設置したラズパイ(ak20でネットワークにつなげている)に予備のwifiネットワークに繋げるようにネットワークの設定を行う。
または、ラズパイのネットワークの設定にあらかじめお客さんのネットワーク設定を入れておく

やり方

wifiの設定ファイルの編集
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP

network={
    ssid="W03_aaaaa" #wifiの名前
    psk="aaaa"  #wifiのパスワード
    key_mgmt=WPA-PSK 
}

network={
    ssid="W03_bbbb" #wifiの名前
    psk="bbbbb"  #wifiのパスワード
    key_mgmt=WPA-PSK
    priority=3  #優先度 大きいほうに優先してつなぐ default 0
    disabled=1  #自動接続するかどうか 1だと自動接続しない default 0
}

script

上記参考にwpaを書き換えるスクリプトを書くことでお客さん用のラズパイ設定が楽になります。(⚠️sudo権限じゃないと実行できない)

add_wifi_ssid.py
import fire


def main(ssid: str, password: str):
  file = "/etc/wpa_supplicant/wpa_supplicant.conf"
  with open(file, 'a') as f:
    text = "network={\nssid=\"" + ssid + "\"\npsk=\"" + password + "\"\nkey_mgmt=WPA-PSK\n}"
    print(text, file=f)


if __name__ == '__main__':
  fire.Fire(main)

その他

cuiでwifiを切り替えるコマンド
networksetup -setairportnetwork en0 $ssid $password
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1