Jump to content

Reset Button to run a Script on the Fon


Recommended Posts

EDIT: read my last comment, this is working now and if you want to do the same look at my last post.

Can anyone help... I am a complete noob when it comes to scripting but if I can't get an answer from the community I'm not afraid of busting out good old Google and giving it a crack and then sharing it back to the community... So here's today's question.

Has anyone used the GPIO pins for the reset button (or just the reset button for that matter) to control the wifi of the Fon? I found this LINK where it shows you how to do just that, but as always I'm looking for more.

So from what I understand you can control the LED and the wifi gpio's by pressing the reset button. However I want it to do more. What I would like it to do is run a script that would do the following..

1.) Not change the state of the wifi at all

2.) killall hostapd

3.) Start karma

4.) Start tcpdump and log all packets to my SDCard

Anyone feel like helping out (I hate to say it a LAZY) noob?

Link to comment
Share on other sites

I'm no linux guru, but after looking around I came up with this, I have no idea if it works but it might point you in the right area.

Generic Toggle Script

Create a file called

wogglein

/sbin and paste this into it:

#!/bin/sh

KARMA_STATE = `get_karma`

Case "$KARMA_STATE" in
1)
    # Karma is on

    karma_cli -s off
    hostapd

0)
    # karma is off

    killall -9 hostapd
    karma_cli -s on
    tcpdump -i ath0 -w /mnt/tcpdump

esac

Then set

chmod +x /sbin/woggle

Hotplugging

Now to get hotplugging working, create a directory in

/etc/hotplug.d

called

button

and then create a file in

/etc/hotplug.d/button

called

01-radio-toggle

as in the original wifi toggle script (above). Paste this into that file:

if [ "$BUTTON" = "ses" ]; then
        if [ "$ACTION" = "pressed" ]; then
                /sbin/woggle
        fi
fi

and set

chmod +x 01-radio-toggle

Ref:

http://wiki.openwrt.org/oldwiki/openwrtdoc...ware/wifitoggle

Link to comment
Share on other sites

I'm at work now so I"ll try that as soon as I get home and let you all know...

Thanks again!!!

EDIT:

OK so I tried this and had a lot of problems, but I was dead set on making it work so this is what I have so far... Note its still not 100% but its getting there... Mind you I am running Piranha 2.0 so the hostapd line may be different for you, but I'm not sure.

Also right now I'm just focused on the script part and not so much the button part. When I execute the script it does everything 100% correctly. However when I run the script a second time to kill Karma, tcpdump and re-enable hostapd everything works except for the hostapd part.

I'll provide the error that I'm getting in a little bit.. I know there is a fix for it but I didn't have time to work with it any more.

root@Jasager:/sbin# vi woggle
#!/bin/sh

KARMA_STATE=`iwpriv ath0 get_karma | cut -d ":" -f2`
echo "KARMA_STATE=$KARMA_STATE"
case "$KARMA_STATE" in

    # KARMA IS ON...
1* )  echo "Turning off Karma";
      killall tcpdump;
      karma_cli -s off;
      hostapd -P /var/run/wifi-ath0.pid -B /var/run/hostapd-ath0.conf;
;;
    # KARMA IS OFF...
0* )  echo "Turning on Karma";
      killall -9 hostapd;
      karma_cli -s on;
      tcpdump -i ath0 -s 0 -U -w /mnt/mmc/tasty.tcpdump&;
;;
*)
      echo "Umm do you have Karma installed?"
esac
~

Link to comment
Share on other sites

OK so like I mentioned the first time I run the script everything is fine. However the Second time I get an error (in bold). Now if I run the line "hostapd -P /var/run/wifi-ath0.pid -B /var/run/hostapd-ath0.conf" again it looks like it works fine... How should I restart the hostapd correctly?

root@Jasager:/# woggle

KARMA_STATE=0

Turning on Karma

Turning Karma On

root@Jasager:/# tcpdump: WARNING: ath0: no IPv4 address assigned

tcpdump: listening on ath0, link-type EN10MB (Ethernet), capture size 96 bytes

root@Jasager:/# woggle

KARMA_STATE=1

Turning off Karma

45 packets captured

45 packets received by filter

0 packets dropped by kernel

Turning Karma Off

Configuration file: /var/run/hostapd-ath0.conf

Using interface ath0 with hwaddr 00:18:84:27:86:11 and ssid 'default'

bind(PF_UNIX): Address already in use

Failed to setup control interface

root@Jasager:/#

Note the BOLD text above. Now if I run this part of the script a second time, as you can see below it works the way its intended. Can someone tell me why?

root@Jasager:/# hostapd -P /var/run/wifi-ath0.pid -B /var/run/hostapd-ath0.conf

Configuration file: /var/run/hostapd-ath0.conf

Using interface ath0 with hwaddr 00:18:84:27:86:11 and ssid 'default'

root@Jasager:/#

Thanks again for the help..

Link to comment
Share on other sites

OK to get this to work when you press the reset button this is what you need to do. First you need to install the "hotplug2" package if its not installed...... Then create a file called /etc/hotplug.d/button/30-button-trigger

in that file past this

#!/bin/sh
    if [ "${ACTION}" == "released" ]
       then
         /sbin/woggle
fi

Now create a file called /sbin/woggle and paste the following...

!/bin/sh

KARMA_STATE=`iwpriv ath0 get_karma | cut -d ":" -f2`
echo "KARMA_STATE=$KARMA_STATE"
case "$KARMA_STATE" in

    # KARMA IS ON...
1* )  echo "Turning off Karma";
      killall tcpdump;
      karma_cli -s off;
      hostapd -P /var/run/wifi-ath0.pid -B /var/run/hostapd-ath0.conf;
     ;;
    # KARMA IS OFF...
0* )  echo "Turning on Karma";
      mv /mnt/mmc/tasty.tcpdump /mnt/mmc/tasty.tcpdump.old
      killall hostapd;
      karma_cli -s on;
      tcpdump -i ath0 -w /mnt/mmc/tasty.tcpdump &
;;
*)
      echo "Umm do you have Karma installed?"
esac

OK to finish up lets make sure that the woggle script is executable.

chmod +x /sbin/woggle

SPECIAL THANKS TO

01706 and digininja!!!!!

I have learned a bunch about this so if you have questions maybe I can help. Hope someone out there finds use in this....

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...