WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: wifi.tcz  (Read 17964 times)

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: wifi.tcz
« Reply #15 on: October 29, 2013, 07:41:57 PM »
Thanks.  In the future, all that is needed is the diff output - no options. 

I take it that the first code snippet is acceptable for use for our current purposes?

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.tcz
« Reply #16 on: October 29, 2013, 09:15:27 PM »
I won't be able to assess or test till the weekend when I will have access to both equip and open access points.
10+ Years Contributing to Linux Open Source Projects.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.tcz
« Reply #17 on: November 01, 2013, 09:49:28 AM »
Yes. The mods work for an open wifi used with the -a option.
However, when not using the -a option such open wifi items are repeatedly added to wifi.db.
Such is not the case with protected wifi items. This will need to be corrected.
10+ Years Contributing to Linux Open Source Projects.

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: wifi.tcz
« Reply #18 on: November 02, 2013, 01:50:04 PM »
Thanks for your review and findings. In the use case I am pursuing, the user is presented with a script that prompts for a number of setup options. For the option that provides wireless setup, the wifi.db is deleted before wifi.sh is invoked (thus preventing the windup). The bootup logic is then modified to start with "wifi.sh -a".

I understand the need to have open access points behave the same as protected. I believe that can be accomplished. It will also give me the opportunity to exercise the DIFF and PATCH advice you gave me:-)

I'll look at it later tonight when I return home.

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: wifi.tcz
« Reply #19 on: November 02, 2013, 10:27:00 PM »
I've included the dbfile lookup logic to prevent the wifi.db duplicates you indicated.  Hopefully I have followed the correct process for the patch this time.  I'll include both in attachment and inline code form.

Code: [Select]
--- /usr/local/bin/wifi.sh
+++ /home/tc/wifi.sh
@@ -95,11 +95,15 @@
 
 function associate(t,d,s,p,c) {
  print p > ptmp
+ keyphrase=" key restricted "
+ if ( p == "" ) { keyphrase = "" }
+ selchannel=" channel "
+ if ( c == "" ) { selchannel = "" }
  if (t == "WPA") {
  system("wpa_passphrase " s " < " ptmp " > /etc/wpa_supplicant.conf")
  system("wpa_supplicant -i " d " -c /etc/wpa_supplicant.conf -B >/dev/null 2>&1")
  } else {
- system("iwconfig " d " essid " s " key restricted " p " channel " c)
+ system("iwconfig " d " essid " s keyphrase p selchannel c)
  }
  for (try=1; try<20; try++) {
  printf(".")
@@ -227,10 +231,10 @@
  } while (selection < 1 || selection > i)
  if ( offset == 1 && selection != "q") {
  sid_display = sid[selection]
+ password = ""
+ newitem=""
  gsub(" ","\\ ",sid[selection])
  if ( enc[selection] == "on" ) {
- password = ""
- newitem=""
  while ( getline dbitem < dbfile > 0 ) {
  split(dbitem,field,"\t")
  if (sid[selection] == field[1] ) {
@@ -250,7 +254,16 @@
 
  associate(type[selection],wifi,sid[selection],password,chan[selection])
  } else {
- system("iwconfig " wifi " essid " sid[selection] " channel " chan[selection])
+ newitem=1
+ while ( getline dbitem < dbfile > 0 ) {
+ split(dbitem,field,"\t")
+ if (sid[selection] == field[1] ) {
+ newitem=""
+ break
+ }
+ }
+ close(dbfile)
+ associate(type[selection],wifi,sid[selection],password,chan[selection])
  }
  if ( mode == "prompt" ) {
  #Choose automatic or manual setting IP adresses

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.tcz
« Reply #20 on: November 03, 2013, 01:36:07 PM »
Patch easily applied. Thanks! Looks good but will field test before final acceptance.
10+ Years Contributing to Linux Open Source Projects.

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: wifi.tcz
« Reply #21 on: November 09, 2013, 12:23:33 PM »
Hi Robert, did you find time to evaluate the patch and is it so good that it be can be accepted?

I have used it few days and don't find any problems.

Steen

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.tcz
« Reply #22 on: November 09, 2013, 12:36:54 PM »
Yes! A OK. Only waiting for attribtion info, as I wish to give credit where due.
10+ Years Contributing to Linux Open Source Projects.

Offline mcdudeabides

  • Jr. Member
  • **
  • Posts: 60
Re: wifi.tcz
« Reply #23 on: November 09, 2013, 08:39:00 PM »
Yes! A OK. Only waiting for attribtion info, as I wish to give credit where due.

My name is Randy McEuen.  Houston, TX.  Is there any more that I need provide?

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.tcz
« Reply #24 on: November 09, 2013, 10:33:46 PM »
Updated wifi.tcz posted to 4.x and 5.x repos as well as the dCore x86 import directory.
Randy's mods adds open access wifi items to the database and therefore allows auto connect to an open wifi when in pole position.
10+ Years Contributing to Linux Open Source Projects.

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: wifi.tcz
« Reply #25 on: November 12, 2013, 07:43:31 AM »
Hello members, I also would like to propose a change tot he wifi.sh script.

Problem: On my raspberry Pi, the IP address lease is not always obtained fast enough. After a several tries, the wifi.sh script gives up. This is probably caused by not enough performance on the Pi, or my network and/or routers is busy/slow.

Proposal: The wifi.sh script uses the -n option for the udhcpc command. I would like to introduce a option for the wifi.sh script which causes it to use the udhscpc command without the -n option. This will force the udhcpc command to indefinitely try to obtain a lease.
This might be strange and unwanted for some applications, but my Raspberry Pi is used headless with only a WiFi connection. Without the wifi connection the Raspberry is useless anyway, so "keep trying" is better then "stop trying".

I've made some changes to the script, I've introduced a -w option. The "w" stands for wait, as in "wait until lease is obtained".
This is the first version, and I've allready some tests on it. It seems to be working but I want to do more testing.

Tell me your opinion on this change, please:

Code: [Select]
--- /tmp/tcloop/wifi/usr/local/bin/wifi.sh
+++ wifi_new.sh
@@ -11,6 +11,7 @@
  echo "  Default select AP from menu and request IP via DHCP."
  echo "  -a Auto connect to first wifi.db entry via DHCP."
  echo "  -p Select AP from menu and prompt for IP configuration type."
+ echo "  -w Wait indefinitely until lease is obtained"
  echo "  -? Displays this help message."
  exit 0
 }
@@ -25,15 +26,17 @@
 DB=/home/"$TCUSER"/wifi.db
 PTMP=/tmp/wpa.$$
 
-while getopts ap? OPTION
+while getopts apw? OPTION
 do
  case ${OPTION} in
  a) MODE=auto ;;
  p) MODE=prompt ;;
+ w) OBTAINLEASE=wait ;;
  *) help ;;
  esac
 done
 [ -n "$MODE" ] || MODE=menu
+[ -n "$OBTAINLEASE" ] || OBTAINLEASE=try
 
 unset WIFI && CNT=0
 until [ -n "$WIFI" ]
@@ -72,7 +75,7 @@
  iwlist "$WIFI" scanning
  [ "$?" == 0 ] && break
  sleep 1
-done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v ptmp="$PTMP" '
+done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v obtainlease="$OBTAINLEASE" -v ptmp="$PTMP" '
 BEGIN {
  RS="\n"
  FS=":"
@@ -186,13 +189,20 @@
  if ($2 ~ /WPA/ ) type[i]="WPA"
 }
 END {
+ if ( obtainlease == "try" ) {
+     lease = "-n "
+ print("Set to try a few times to obtain a lease." )
+ } else if ( obtainlease == "wait" ) {
+     lease = ""
+ print("Set to try indefinitely until lease is obtained." )
+ }
  if ( mode == "auto" ) {
  print("Attempting auto connection with " autoconnect)
  for (i in sid) {
  gsub(" ","\\ ",sid[i])
  if (autoconnect == sid[i] ) {
  associate(type[i],wifi,sid[i],mypass,chan[i])
- system( "udhcpc -n -i " wifi " 2>/dev/null" )
+ system( "udhcpc " lease "-i " wifi " 2>/dev/null" )
  exit
  }
  }
@@ -274,14 +284,14 @@
  setipaddresses(wifi)
  }
  else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease "-i " wifi " 2>/dev/null")
  if ( results == 0 )
  if ( newitem == 1 )
  printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
  }
  }
  else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease " -i " wifi " 2>/dev/null")
  if ( results == 0 )
  if ( newitem == 1 )
  printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile

« Last Edit: November 12, 2013, 12:31:22 PM by Gerrelt »
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: wifi.tcz
« Reply #26 on: November 12, 2013, 11:20:18 AM »
Hi Gerrelt
Quote
( I've tried to mimic the difference report as used by mcdudeabides, a "-" means line deleted, a "+" means line added)
Don't do this manually, that's what the  diff  command is for:
Code: [Select]
diff Original_File Modified_File > diff.txtThat will list just the differences and save them to a file called diff.txt.

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: wifi.tcz
« Reply #27 on: November 12, 2013, 12:32:11 PM »

Ah thanx! I used the diff command and updated my post.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: wifi.tcz
« Reply #28 on: November 13, 2013, 07:14:26 AM »
I've did some more testing yesterday evening, and everything seems to work fine.

I added this line to the bootlocal.sh:

Code: [Select]
/<patch to wifi script>/wifi_new.sh -a -w
And it connected after every reboot or power off -> power on.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: wifi.tcz
« Reply #29 on: November 14, 2013, 03:20:21 PM »
Hello everybody,

I've made another (small) change to the script I want to propose.

Problem: When connected to a wifi router, the name displayed in the DHCP client list is "unknown". This makes it more difficult to discover the tinycore device amongst the other devices.

Solution: Adding the "-x hostname:<hostname>" option to the udhcpc command. With the "hostname" command the current set hostname is retrieved, and that is used as the hostname for the wifi DHCP client.
If, for some strange reason, the hostname cannot be determined, it will default to "Tinycore".

The difference report (compared to the current wifi.sh, so it also contains my previous change request):
Code: [Select]
--- /tmp/tcloop/wifi/usr/local/bin/wifi.sh
+++ wifi_new.sh
@@ -11,6 +11,7 @@
  echo "  Default select AP from menu and request IP via DHCP."
  echo "  -a Auto connect to first wifi.db entry via DHCP."
  echo "  -p Select AP from menu and prompt for IP configuration type."
+ echo "  -w Wait indefinitely until lease is obtained"
  echo "  -? Displays this help message."
  exit 0
 }
@@ -25,16 +26,22 @@
 DB=/home/"$TCUSER"/wifi.db
 PTMP=/tmp/wpa.$$
 
-while getopts ap? OPTION
+while getopts apw? OPTION
 do
+
  case ${OPTION} in
  a) MODE=auto ;;
  p) MODE=prompt ;;
+ w) OBTAINLEASE=wait ;;
  *) help ;;
  esac
 done
 [ -n "$MODE" ] || MODE=menu
+[ -n "$OBTAINLEASE" ] || OBTAINLEASE=try
 
+CURRENTHOSTNAME=$(hostname -s)
+[ -n "$CURRENTHOSTNAME" ] || CURRENTHOSTNAME=Tinycore
+
 unset WIFI && CNT=0
 until [ -n "$WIFI" ]
 do
@@ -72,7 +79,7 @@
  iwlist "$WIFI" scanning
  [ "$?" == 0 ] && break
  sleep 1
-done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v ptmp="$PTMP" '
+done ) | awk -v wifi="$WIFI" -v dbfile="$DB" -v mode="$MODE" -v obtainlease="$OBTAINLEASE" -v currenthostname=$CURRENTHOSTNAME -v ptmp="$PTMP" '
 BEGIN {
  RS="\n"
  FS=":"
@@ -186,13 +193,20 @@
  if ($2 ~ /WPA/ ) type[i]="WPA"
 }
 END {
+ if ( obtainlease == "try" ) {
+     lease = "-n "
+ print("Set to try a few times to obtain a lease." )
+ } else if ( obtainlease == "wait" ) {
+     lease = ""
+ print("Set to try indefinitely until lease is obtained." )
+ }
  if ( mode == "auto" ) {
  print("Attempting auto connection with " autoconnect)
  for (i in sid) {
  gsub(" ","\\ ",sid[i])
  if (autoconnect == sid[i] ) {
  associate(type[i],wifi,sid[i],mypass,chan[i])
- system( "udhcpc -n -i " wifi " 2>/dev/null" )
+ system( "udhcpc " lease "-i " wifi " -x hostname:" currenthostname " 2>/dev/null" )
  exit
  }
  }
@@ -274,14 +288,14 @@
  setipaddresses(wifi)
  }
  else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease "-i " wifi " -x hostname:" currenthostname " 2>/dev/null")
  if ( results == 0 )
  if ( newitem == 1 )
  printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
  }
  }
  else {
- results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+ results = system( "udhcpc " lease "-i " wifi " -x hostname:" currenthostname " 2>/dev/null")
  if ( results == 0 )
  if ( newitem == 1 )
  printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
my Raspberry Pi page: http://raspberry.gerrelt.nl