Remote Operation of a Powerswitch
2. BASIC SETUP
Because we did not want to change the network parameters of the PC, we
connected the powerswitch with the serial calbe to the PC and did
the first setup using VMware and starting a HyperTerminal (9600 bauds). There
we connected to the default IP-address of the powerswitch: 192.168.100.100 and
entered several times 'Enter' until the prompt ">" appeared. The command
/np brings you to the Network Parameters Menu, where you can enter the
number of the parameter, you want to change. We changed the IP-address only
(to 192.168.0.20).
Then enter /rs to restart and leave the configuration menu. Now the
serial cable can be disconnected and further setup can be done from any
browser on a PC in the same network.
3. FINE TUNING OF THE SETUP
Starting a browser in the network and entering http://admin-name:admin-password@192.168.0.20 is
now sufficient for the rest of the setup:
- login as the default administrator name (admin) and the default password
(admin).
- From the Menu 'General' select the port number, if you want to have another port than 80 (eg. 81)
- From the menu select 'Security' and:
- Set admin-name and admin-password as you like
- Set a username and userpassword as you like (this user can only switch on and off)
- Set the the IP-address ranges, from which the powerswitch can be reached (and select Permit/Deny and Activated)
- Click on 'Apply Changes'
4. SWITCHING WITH A BROWSER
This is easy: select the IP-address of the powerswitch (in our example
http://192.168.0.20, login and click on 'Power' to switch on and off.
5. SWITCHING THROUGH A UNIX-COMMAND
There is no documentation on how this can be done... So I had to find out by
myself, what commands are sent to the powerswitch when clicking on the
'Power' icon. Using 'ethereal' is a good tool to find such things out:
- Start ethereal as root and start capturing packets
- Switch the powerswitch via web-interface on and off
- Stop capturing
- Click on the first packet you see, which is sent to the powerswitch
- From the menu choose 'Tools' and then 'Follow TCP-stream'
- You will see, that your browser sends a command P1=0 if you turn
off the power (and P1=1 if you turn it on).
With this and using curl (see man curl or with the konqueror man:curl) and after some testing we find out, that the following command allows to switch a device ON:
curl -u user:userpassword --data-binary P1=1 http://192.168.0.20:81/cmd.html
(In the above example, use 80 instead of 81, or whatever port you
have selected in paragraph 3).
For switching the device OFF, set P1=0 in the command above. Please note, that
it is necessary to add the string /cmd.html in the web-address!!
And: Should you have a special character in your password, such as a $,
the password must be masked and entered as \$.
Alternatively and if you have PHP installed on your system, you may create a PHP-script switch.php on your machine with the following content:
<?php // // Switch device at powerswitch ON: (P1=1) ; OFF: P1=0 // $url = "http://192.168.0.20:81/cmd.html"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "user:userpassword"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "P1=1"); $result = curl_exec($ch); curl_close($ch); echo $result; ?>and then enter the command: php -f switch.php ; to switch the device off, use P1=0 in the php-script.