PHP scripting

PHP scripting (3)

KMTronic LAN Ethernet IP 8 channels WEB Relay board BOX

 

 

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:
FF0101  // TURN ON Relay 1
FF0100  // TURN OFF Relay 1
FF0201  // TURN ON Relay 2
FF0200  // TURN OFF Relay 2
...

FF0801  // TURN ON Relay 8
FF0800  // TURN OFF 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 )

KMtronic UDP LAN Controled Internet relay board

 

 

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); 

$msg = "FF0000";

$len = strlen($msg);

socket_sendto($sock, $msg, $len, 0 ,'192.168.1.199', 12345); socket_recvfrom($sock, $buf, 12, 0, $from, $port);

echo $buf; socket_close($sock);

?>

 

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:
FF0101  // TURN ON Relay 1
FF0100  // TURN OFF Relay 1
FF0201  // TURN ON Relay 2
FF0200  // TURN OFF Relay 2
...

FF0801  // TURN ON Relay 8
FF0800  // TURN OFF Relay 8

 

Create a new file.

<?php

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

$msg = "FF0101"; // TURN ON Relay 1

$len = strlen($msg);

socket_sendto($sock, $msg, $len, 0 ,'192.168.1.199', 12345);

socket_recvfrom($sock, $buf, 12, 0, $from, $port);

echo $buf;

socket_close($sock);

?>

Save the file as relay_1_on.php and run. ( $ php relay_1_on.php )

Wednesday, 27 July 2016 06:48

Creating PHP Scripts ("Hello World!")

Written by

 

Create a new empty file with your editor and begin with a simple PHP code block.

<?php

Print "Hello, World!"; 

?>

 

Save the file as hello.php

 

To make the script work, run the hello.php command:

$ php list.php