
PHP scripting (3)
PHP Scripts: Control KMtronic LAN WEB Relay board via PHP
Written by Super User
http://www.info.kmtronic.com/km-web-eight-relay-box.html
PHP code for STATUS Read WEB Relay board connected to IP: 192.168.1.199 PORT:80 USER: admin PASSWORD: admin
Create a new file. <?php $url = "http://192.168.1.199:80/status.xml"; $username = "admin"; $password = "admin"; //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); //execute post $result = curl_exec($ch); print $result;
Save the file as web_8relay_status.php and run. ( $ php web_8relay_status.php )
Result: $ php web_8_relay_status.php 0 0 0 0 0 0 0 0 0
PHP code for CONTROL WEB Relay board connected to IP: 192.168.1.199 PORT:80 USER: admin PASSWORD: admin
COMMANDS: FF0801 // TURN ON Relay 8
Create a new file. <?php $url = "http://192.168.1.199:80/FF0101"; // TURN ON Relay 1 $username = "admin"; $password = "admin"; //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); //execute post $result = curl_exec($ch); print $result; ?> Save the file as web_relay_1_on.php and run. ( $ php web_relay_1_on.php ) |
PHP Scripts: Control KMtronic LAN UDP Relay board via PHP
Written by Super User
http://www.info.kmtronic.com/km-udp-eight-relay-box.html
PHP code for STATUS Read UDP Relay board connected to IP: 192.168.1.199 PORT:12345
UDP COMMAND: FF0000
Create a new file. <?php $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
Save the file as status.php and run. ( $ php status.php )
Result: $ php list.php
PHP code for CONTROL UDP Relay board connected to IP: 192.168.1.199 PORT:12345
UDP COMMANDS: FF0801 // TURN ON Relay 8
Create a new file. <?php $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); Save the file as relay_1_on.php and run. ( $ php relay_1_on.php ) |
Create a new empty file with your editor and begin with a simple PHP code block. <?php
Save the file as hello.php
To make the script work, run the hello.php command: $ php list.php |