2015年6月26日金曜日

[Intel Edison]WiFiの固定IPアドレス設定

まずは、シリアル接続した状態でEdisonのWiFiを設定します。
既にWiFi接続されている方は読み飛ばして下さい。


Terminal -- bash -- 80x24
root@Edison:~# configure_edison --wifi

Configure Edison: WiFi Connection

Scanning: 1 seconds left

0 : Rescan for networks
1 : Exit WiFi Setup
2 : Manually input a hidden SSID
3 : AnotheWiFi01
4 : AnotheWiFi02
5 : AnotheWiFi03
6 : AnotheWiFi04
7 : myWiFi


Enter 0 to rescan for networks.
Enter 1 to exit.
Enter 2 to input a hidden network SSID.
Enter a number between 3 to 7 to choose one of the listed network SSIDs: 7
Is myWiFi correct? [Y or N]: Y
Password must be between 8 and 63 characters.
What is the network password?: ***************************************************************
Initiating connection to myWiFi. Please wait...
Attempting to enable network access, please check 'wpa_cli status' after a minute to confirm.
Done. Please connect your laptop or PC to the same network as this device and go to http://xxx.xxx.xxx.xxx or http://Edison.local in your browser.
root@Edison:~#

以上でWiFiルータとの接続は完了しますが、DHCPでIPアドレスを取得しているので起動の度にアドレスが変わってしまいます。

で、以下で固定IPアドレスの設定を行います。
最初に現在接続しているWiFiのデフォルトゲートウェイとネットマスクを確認します。


Terminal -- bash -- 80x24
root@Edison:~# /sbin/route
Kernel IP routing table
DestinationGatewayGenmask  Flags  Metric  Ref  Use Iface
default  ******.setup  0.0.0.0UG000 wlan0
yyy.yyy.yyy.yyy  * zzz.zzz.zzz.zzz  U000 wlan0
xxx.xxx.xxx.xxx  *xxx.xxx.xxx.xxxU000 usb0
root@Edison:~#

黄色の"yyy.yyy.yyy.yyy"がデフォルトゲートウェイ、
マゼンタの"zzz.zzz.zzz.zzz"がネットマスクとなります。

次に、"/etc/wpa_supplicant/wpa_cli-actions.sh"を編集して固定IPアドレスを設定します。色文字の箇所が追加部分となります。
"xxx.xxx.xxx.xxx"の箇所には指定したいIPアドスを、
"yyy.yyy.yyy.yyy"、"zzz.zzz.zzz.zzz"には上記で取得したデフォルトゲートウェイ、ネットマスクを入力します。




Terminal -- bash -- 80x24
root@Edison:~# vi /etc/wpa_supplicant/wpa_cli-actions.sh
#!/bin/sh
#
# This script file is passed as parameter to wpa_cli, started as a daemon,
# so that the wpa_supplicant events are sent to this script
# and actions executed, like :
# - start DHCP client when STA is connected.
# - stop DHCP client when STA is disconnected.
# - start DHCP client when P2P-GC is connected.
# - stop DHCP server when P2P-GO is disconnected.
#
# This script skips events if connmand (connman.service) is started
# Indeed, it is considered that the Wifi connection is managed through
# connmand and not wpa_cli
#

IFNAME=$1
CMD=$2

kill_daemon() {
  NAME=$1
  PF=$2

  if [ ! -r $PF ]; then
    return
  fi

  PID=`cat $PF`
  if [ $PID -gt 0 ]; then
    if ps | grep $NAME | grep $PID; then
      kill $PID
    fi
  fi
  if [ -r $PF ]; then
    # file can be removed by the deamon when killed
    rm $PF
  fi
}

echo "event $CMD received from wpa_supplicant"

# if Connman is started, ignore wpa_supplicant
# STA connection event because the DHCP connection
# is triggerd by Connman
if [ `systemctl is-active connman` == "active" ] ; then
  if [ "$CMD" = "CONNECTED" ] || [ "$CMD" = "DISCONNECTED" ] ; then
    echo "event $CMD ignored because Connman is started"
    exit 0
  fi
fi

if [ "$CMD" = "CONNECTED" ]; then
  kill_daemon udhcpc /var/run/udhcpc-$IFNAME.pid
#udhcpc -i $IFNAME -p /var/run/udhcpc-$IFNAME.pid -S
ifconfig $IFNAME xxx.xxx.xxx.xxx netmask zzz.zzz.zzz.zzz
route add default gw yyy.yyy.yyy.yyy
fi

if [ "$CMD" = "DISCONNECTED" ]; then
  kill_daemon udhcpc /var/run/udhcpc-$IFNAME.pid
  ifconfig $IFNAME 0.0.0.0
fi

if [ "$CMD" = "P2P-GROUP-STARTED" ]; then
  GIFNAME=$3
  if [ "$4" = "GO" ]; then
    kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
    ifconfig $GIFNAME xxx.xxx.xxx.xxx up
    cp /etc/wpa_supplicant/udhcpd-p2p.conf /etc/wpa_supplicant/udhcpd-p2p-itf.conf
    sed -i "s/INTERFACE/$GIFNAME/" /etc/wpa_supplicant/udhcpd-p2p-itf.conf
    udhcpd /etc/wpa_supplicant/udhcpd-p2p-itf.conf
  fi
  if [ "$4" = "client" ]; then
    kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
    kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
    udhcpc -i $GIFNAME -p /var/run/udhcpc-$GIFNAME.pid
  fi
fi

if [ "$CMD" = "P2P-GROUP-REMOVED" ]; then
  GIFNAME=$3
  if [ "$4" = "GO" ]; then
    kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
    ifconfig $GIFNAME 0.0.0.0
  fi
  if [ "$4" = "client" ]; then
    kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
    ifconfig $GIFNAME 0.0.0.0
  fi
fi
root@Edison:~#

以上で設定は終了です。
再起動すると、設定が有効になります。

0 件のコメント:

コメントを投稿