[19. April 2013] A-400 Advanced Network Setup now available | [11 Jan. 2013] Customize your A-400 Home Screen

Firmware: A-400 [13 May 2013] | C-300 [30 Nov. 2012] | A-300 [30 Nov. 2012] | C-200 [21 Jan. 2013] | A-200/A-210 [10 Aug. 2012]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Thread Closed 
Wifi On/Off switch project with Java Mika
03-20-2010, 11:51 AM (This post was last modified: 03-20-2010 12:00 PM by gozothegreat.)
Post: #1
Wifi On/Off switch project with Java Mika
my java / Mika project

What was the purpose of this project : i wanted to use the NMT to swith off my WIFI signal of my router at night and switch it on again in the morning.

My modem/router Siemens gigaset sx762 has NO telnet access (was disabled by my provider), only http.

My NMT is hardwired to the network and the Wifi signal is only used to surf the net on an iPhone.

After reading a lot on the forums and with my knowledge of the java programming language, i decided to use Mika to do the project.

What dit i use :

Fiddler2 : sniffer program : http://www.fiddler2.com/fiddler2/
Filezilla : ftp program : http://filezilla-project.org/
Netbeans 6.8 : java IDE, java 1.6 jdk. : http://java.sun.com/javase/downloads/wid...tbeans.jsp
putty : telnet client : http://www.chiark.greenend.org.uk/~sgtatham/putty/
Crontab : to schedule the on/off process on the nmt
Mika : Java jre that runs on the nmt : http://mediaplayersite.com/node/148

how did i do it :

- First, with the help of Fiddler, i detected the HTTP posts needed to login to the router and change the Wifi Setting.

- With Netbeans, i wrote 1 java-class that does the login, and depending a start parameter, switch off or on the wifi.
This java class uses standard java objects like the URL object, to do the posting. Once the java class ran successfully on my pc, it was time to move it to the nmt.

- Installing Mika is really straightforward : download the 'mika-sleep-fixed.rar' available via the link above.
Unrar it, and copy it over to the NMT : i put it on 'share/mika. The tricky part of copying the jre using Filezilla, is that you MUST change the tranfert type to 'Binary'
Else, the mika program won't run !!

- Next, i copied my java class (packaged in a Jar file) over to the NMT and then ran the program from command line with putty (telnet), like this :
'/share/mika/bin/mika -classpath /share/mika/bin/Wifi.jar wifi.Pure 1' where
the classpath param specifies where to find the Pure.class file.
1 is the param to switch Wifi on.

- finally, made 2 .sh files : one to swith off, one to switch on.

- using the crontab command, you can schedule the .sh files to execute the java program
f.ex : * 22 * * * /share/wifiSwitchOff.sh -> switch Wifi off at 22 pm
* 7 * * * /share/wifiSwitchOn.sh -> switch Wifi on at 7 am

- one thing, if you want that the crontab stays intact on reboot of the NMT, you have to change some stuff in the file 'start_app.sh'

Perhaps this will inspire other java-developers?
Find all posts by this user
03-22-2010, 11:39 AM
Post: #2
RE: Wifi On/Off switch project with Java Mika
I've only just noticed that people are running Mika on this device. (Someone did post a message on the Mika forums a year ago, but I was very busy at the time and didn't follow up all that well). Looks like this could be a useful "reference" platform for MIPS CPU (we have some paying customers using MIPS, but always with a proprietary toolchain and kernel so the builds are no use to anyone else).
What would be a good baseline model for us to use for testing?

- Chris of /k/ Embedded Java Solutions
Find all posts by this user
03-22-2010, 07:37 PM
Post: #3
RE: Wifi On/Off switch project with Java Mika
(03-22-2010 11:39 AM)kiffer Wrote:  I've only just noticed that people are running Mika on this device. (Someone did post a message on the Mika forums a year ago, but I was very busy at the time and didn't follow up all that well). Looks like this could be a useful "reference" platform for MIPS CPU (we have some paying customers using MIPS, but always with a proprietary toolchain and kernel so the builds are no use to anyone else).
What would be a good baseline model for us to use for testing?

- Chris of /k/ Embedded Java Solutions
Well, i've got an A-110, it's not the newest model, that would be the 200-series.
Find all posts by this user
03-23-2010, 10:13 AM
Post: #4
RE: Wifi On/Off switch project with Java Mika
(03-22-2010 07:37 PM)gozothegreat Wrote:  Well, i've got an A-110, it's not the newest model, that would be the 200-series.
A-200 maybe. I'll ask this as a new thread. Thanks.
Find all posts by this user
08-26-2010, 10:47 PM
Post: #5
RE: Wifi On/Off switch project with Java Mika
Hello,

I think there is a mistake in your crontab.
Should'nt you specify minutes ? I think your script runs every minute at 22pm and 7 am.

I found your topic because I'm looking for a way to modify crontab.
I tried but crontab is resetted after reboot.
It seems like you have the solution ... i'm going to try this Cool
Find all posts by this user
08-27-2010, 02:16 AM
Post: #6
RE: Wifi On/Off switch project with Java Mika
In his first post, he talks about changing the /share/start_app.sh script which gets installed with
the help of the CSI program. To make sure crontab is good after a reboot, create a text file which
you can append to /etc/cron.daily

Given a file myCron.txt contains the lines needed, include lines at the end of start_app.sh
cat /share/myCron.txt >> /etc/cron.daily

Not sure if you'll need to restart the cron daemon in order to have the changes take effect (just test it).
Find all posts by this user
08-27-2010, 12:44 PM
Post: #7
RE: Wifi On/Off switch project with Java Mika
Good learning excercise for Mika. I would have just used a wget script though Wink

Mika/Java could be interesting if I ever re-write the Oversight scanner, (else it would be perl or python if someone ever ported them).

Re-writing the Oversight GUI in C just reminded me of a lot of things (good and bad) about C Smile I never learned C++ properly, went from C to Java

What do you guys think of netbeans, i am using it at work (for a WAR app) but it uses a lot of resources and the editor is frustrating. Inserting stuff I dont want and not inserting stuff I do. I will try adding VIM bindings to netbeans. And it doesnt seem to shutdown tomcat consistently.

In the end I mostly ditched it and just used vim+ctags+ant.

Oversight: Jukebox | FeedTime: Automatic nzbs
Find all posts by this user
[+] 1 user says Thank You to lordy for this post
08-27-2010, 02:10 PM
Post: #8
RE: Wifi On/Off switch project with Java Mika
(08-27-2010 02:16 AM)garp99 Wrote:  In his first post, he talks about changing the /share/start_app.sh script which gets installed with
the help of the CSI program. To make sure crontab is good after a reboot, create a text file which
you can append to /etc/cron.daily

Given a file myCron.txt contains the lines needed, include lines at the end of start_app.sh
cat /share/myCron.txt >> /etc/cron.daily

Not sure if you'll need to restart the cron daemon in order to have the changes take effect (just test it).
Its working fine when I modify start_app.sh.
Thank you for the tip !
Find all posts by this user
09-01-2010, 07:28 PM
Post: #9
RE: Wifi On/Off switch project with Java Mika
(08-27-2010 12:44 PM)lordy Wrote:  Good learning excercise for Mika. I would have just used a wget script though Wink
didn't know the wget script thing. will examine it. All examples welcome.
Find all posts by this user
09-01-2010, 08:59 PM (This post was last modified: 09-02-2010 08:35 AM by gozothegreat.)
Post: #10
RE: Wifi On/Off switch project with Java Mika
Looks like this wget script is working :

#!/bin/sh

url=http://192.168.2.1/UE/ProcessForm
pswrd=blablabla
postlogin="form_submission_type=login&form_submission_parameter=welcome_login.html&current_page=welcome_login.html&next_page=home_security.html&i=1&your_password=blablabla"
postswitch="form_submission_type=ok_submit&form_submission_parameter=&current_page=submission_iframe.html&next_page=submission_iframe.html&6_set_IGD.LANDevice.1.WLANConfiguration.1.RadioEnabled=1&7_set_IGD.LANDevice.1.WLANConfiguration.1.Enable=0"
wget --quiet --no-clobber --http-password=$pswrd --post-data=$postlogin $url
wget --quiet --no-clobber --http-password=$pswrd --post-data=$postswitch $url

the --no-clobber param will overwrite the html which is downloaded.

Is there a way of saying with wget : just do the post and don't download the html?
Find all posts by this user
09-01-2010, 10:17 PM (This post was last modified: 09-01-2010 10:18 PM by garp99.)
Post: #11
RE: Wifi On/Off switch project with Java Mika
From http://www.gnu.org/software/wget/manual/wget.html

Code:
‘--post-data=string’
‘--post-file=file’
    Use POST as the method for all HTTP requests and send the specified data in the request body. ‘--post-data’ sends string as data, whereas ‘--post-file’ sends the contents of file. Other than that, they work in exactly the same way. In particular, they both expect content of the form key1=value1&key2=value2, with percent-encoding for special characters; the only difference is that one expects its content as a command-line parameter and the other accepts its content from a file. In particular, ‘--post-file’ is not for transmitting files as form attachments: those must appear as key=value data (with appropriate percent-coding) just like everything else. Wget does not currently support multipart/form-data for transmitting POST data; only application/x-www-form-urlencoded. Only one of ‘--post-data’ and ‘--post-file’ should be specified.

    Please be aware that Wget needs to know the size of the POST data in advance. Therefore the argument to --post-file must be a regular file; specifying a FIFO or something like /dev/stdin won't work. It's not quite clear how to work around this limitation inherent in HTTP/1.0. Although HTTP/1.1 introduces chunked transfer that doesn't require knowing the request length in advance, a client can't use chunked unless it knows it's talking to an HTTP/1.1 server. And it can't know that until it receives a response, which in turn requires the request to have been completed – a chicken-and-egg problem.

    Note: if Wget is redirected after the POST request is completed, it will not send the POST data to the redirected URL. This is because URLs that process POST often respond with a redirection to a regular page, which does not desire or accept POST. It is not completely clear that this behavior is optimal; if it doesn't work out, it might be changed in the future.

    This example shows how to log to a server using POST and then proceed to download the desired pages, presumably only accessible to authorized users:

              # Log in to the server.  This can be done only once.
              wget --save-cookies cookies.txt \
                   --post-data 'user=foo&password=bar' \
                   http://server.com/auth.php
              
              # Now grab the page or pages we care about.
              wget --load-cookies cookies.txt \
                   -p http://server.com/interesting/article.php

    If the server is using session cookies to track user authentication, the above will not work because ‘--save-cookies’ will not save them (and neither will browsers) and the cookies.txt file will be empty. In that case use ‘--keep-session-cookies’ along with ‘--save-cookies’ to force saving of session cookies.
Find all posts by this user
09-02-2010, 08:07 AM
Post: #12
RE: Wifi On/Off switch project with Java Mika
(08-26-2010 10:47 PM)PHPlaylistCreator Wrote:  Hello,

I think there is a mistake in your crontab.
Should'nt you specify minutes ? I think your script runs every minute at 22pm and 7 am.

I found your topic because I'm looking for a way to modify crontab.
I tried but crontab is resetted after reboot.
It seems like you have the solution ... i'm going to try this Cool
thanks for the advice, I realise indeed that the minutes should be 0 instead of *.
So the correct cron-trigger should be :

0 22 * * * /share/wifiSwitchOff.sh -> switch Wifi off at 22 pm
0 7 * * * /share/wifiSwitchOn.sh -> switch Wifi on at 7 am

Is this ok?
Find all posts by this user
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Which box for Java/Mika development kiffer 4 2,389 03-24-2010 05:11 PM
Last Post: Willem53
  How to switch off the front panel light of the A110? gevrey 2 1,470 01-15-2010 01:35 PM
Last Post: Slevin
  is there a way to keep WIFI settings after Reboot ? wheely 1 1,226 01-06-2010 10:30 PM
Last Post: wheely
Lightbulb Watchdog script to get rid of wireless (WiFi) disconnections keramidas 24 10,978 12-14-2009 11:34 PM
Last Post: happy
  install java 1.5 or 1.6 on PCH-A110 cerber 6 2,740 07-20-2009 12:44 AM
Last Post: dc11ab
  Running Java applications on the NMT? tiwas 3 2,554 04-13-2009 09:49 AM
Last Post: werner
  Java programs tomlee 38 17,518 04-08-2009 03:17 PM
Last Post: Mudshark
  First Java Musicbox mike_leber 10 4,453 04-08-2009 09:13 AM
Last Post: Cadish
Lightbulb pchPls - Java PCH Playlist Generator skafoelix 6 3,855 03-29-2009 08:34 AM
Last Post: dc11ab
  Mono project HammarNet 2 1,348 03-24-2009 12:33 AM
Last Post: majkeli

Forum Jump: