Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config option to enable DHCP #105

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions sd/test/equip_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ log() {
}

get_config() {
key=$1
grep $1 /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
grep "^$1=" /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
}


Expand Down Expand Up @@ -263,6 +262,11 @@ log "Debug mode = $(get_config DEBUG)"
### Let ppl hear that we start connect wifi
/home/rmm "/home/hd1/voice/connectting.g726" 1

HOSTNAME="$(get_config HOSTNAME)"
HOSTNAME="${HOSTNAME// /}" # strip all whitespace
log "Setting hostname to ${HOSTNAME}"
hostname "${HOSTNAME}"

log "Check for wifi configuration file...*"
log $(find /home -name "wpa_supplicant.conf")

Expand All @@ -271,21 +275,26 @@ res=$(/home/wpa_supplicant -B -i ra0 -c /home/wpa_supplicant.conf )
log "Status for wifi configuration=$? (0 is ok)"
log "Wifi configuration answer: $res"

log "Do network configuration 1/2 (ip and gateway)"
#ifconfig ra0 192.168.1.121 netmask 255.255.255.0
#route add default gw 192.168.1.254
ifconfig ra0 $(get_config IP) netmask $(get_config NETMASK)
route add default gw $(get_config GATEWAY)
log "Done"
if [[ $(get_config DHCP) == "yes" ]] ; then
log "Do network configuration (DHCP)"
udhcpc --interface=ra0 --hostname="${HOSTNAME}" >> ${LOG_FILE}
log "Done"
else
log "Do network configuration 1/2 (IP and Gateway)"
#ifconfig ra0 192.168.1.121 netmask 255.255.255.0
#route add default gw 192.168.1.254
ifconfig ra0 $(get_config IP) netmask $(get_config NETMASK)
route add default gw $(get_config GATEWAY)
log "Done"
### configure DNS (google one)
log "Do network configuration 2/2 (DNS)"
echo "nameserver $(get_config NAMESERVER)" > /etc/resolv.conf
log "Done"
fi

log "Configuration is :"
ifconfig | sed "s/^/ /" >> ${LOG_FILE}

### configure DNS (google one)
log "Do network configuration 2/2 (DNS)"
echo "nameserver $(get_config NAMESERVER)" > /etc/resolv.conf
log "Done"

### configure time on a NTP server
log "Get time from a NTP server..."
NTP_SERVER=$(get_config NTP_SERVER)
Expand All @@ -298,7 +307,8 @@ log "New datetime is $(date)"


### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
GATEWAY=$(ip route | awk '/default/ { print $3 }')
ping -c1 -W2 $GATEWAY > /dev/null
if [ 0 -eq $? ]; then
/home/rmm "/home/hd1/voice/wifi_connected.g726" 1
fi
Expand Down Expand Up @@ -397,7 +407,8 @@ fi
### Final led color

### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
GATEWAY=$(ip route | awk '/default/ { print $3 }')
ping -c1 -W2 $GATEWAY > /dev/null
if [ 0 -eq $? ]; then
led $(get_config LED_WHEN_READY)
/home/rmm "/home/hd1/voice/success.g726" 1
Expand Down
4 changes: 4 additions & 0 deletions sd/test/yi-hack.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ ROOT_PASSWORD=1234qwer

### Network configuration
# Don't forget to also fill the file wpa_supplicant.conf for the wifi configuration
# Hostname (cannot have any spaces)
HOSTNAME=YiCamera
# Set DHCP to 'yes' to enable DHCP client (if 'yes', Yi will ignore IP/Netmask/etc settings below)
DHCP=no
IP=192.168.1.121
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
Expand Down