Javascript Button for Triggering PICNIC02 TS

The current progress of study in PICNIC as a web-based actuator are accessing socket to getStatus and commanding lamps via web based. This code was written in PHP and using javascript for improving the button.

<?php
$page ="PICNIC 02 Board Actuator";

// host and socket configuration
$host = "192.168.64.44"; 	// kasiihama laboratory
$port = "80"; 			// standard port http

// function debug
function debug($debuger) {
		echo "<pre>";
		print_r($debuger);
		echo "</pre>";
		}
?>
<html>
<head>
<title><?php echo $page;?></title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript">
$( init4h );
// initiate led 4
function init4h() {
	$('#bt4h').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB4=H");
		})
	}
$( init4l );
function init4l() {
	$('#bt4l').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB4=L");
		})
	}
// initiate led 5
$( init5h );
function init5h() {
	$('#bt5h').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB5=H");
		})
	}
$( init5l );
function init5l() {
	$('#bt5l').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB5=L");
		})
	}
// initiate led 6
$( init6h );
function init6h() {
	$('#bt6h').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB6=H");
		})
	}
$( init6l );
function init6l() {
	$('#bt6l').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB6=L");
		})
	}

// initiate led 7
$( init7h );
function init7h() {
	$('#bt7h').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB7=H");
		})
	}
$( init7l );
function init7l() {
	$('#bt7l').click(function() {
		$.get("http://192.168.64.44/modify.cgi?RB7=L");
		})
	}
</script>
<link rel="stylesheet" type="text/css" href="pic.css" />
</head>
</head>
<body>
<h1 align="center"><?php echo $page; ?></h1>
<hr />
<?php

// host and socket configuration
$host = "192.168.64.44"; 	// kasiihama laboratory
$port = "80"; 			// standard port

// function open socket php
$fp = fsockopen($host, $port, $errno, $errstr, 30);
//$fp = fsockopen('udp://192.168.64.44',10002, $errno, $errstr, 30); //using udp
if (!$fp) {
	echo "$errstr ($errno)<br />\n";
	} else {

	// method get status
	$d = "00"; 		// get status, using command :00
 	fputs($fp,$d);		// puts our command and send it using fp
 	$result = fgets($fp,64);// response data, 64 bits
	}
	fclose($fp);	// close socket connection

	// print the result
	echo "<center><pre>";
	echo "Connection status : " .$result;
	echo "</pre></center>";

// check the lamp status
// if(!$fp) {
//	echo "$errstr($errno) <br />\n";
//	} else {
		// cek cek status
//		$led = "1";
//		fputs($fp,$led);
//		$resLed = fgets($fp,64);
//
//		}
//	fclose($fp);
//	debug($resLed);
?>
<hr />
<h3 align="center">Button Switch</h3>
<form name="myForm" action="">
<table id="tlamp">
<tr class="thead">
	<td>LED 4</td>
	<td>LED 5</td>
	<td>LED 6</td>
	<td>LED 7</td>
</tr>
<tr>
	<td>
		<input type="button" id="bt4h" value="Turn On">
		<input type="button" id="bt4l" value="Turn Off">
	</td>
	<td>
		<input type="button" id="bt5h" value="Turn On">
		<input type="button" id="bt5l" value="Turn Off">
	</td>
	<td>
		<input type="button" id="bt6h" value="Turn On">
		<input type="button" id="bt6l" value="Turn Off">
	</td>
	<td>
		<input type="button" id="bt7h" value="Turn On">
		<input type="button" id="bt7l" value="Turn Off">
	</td>
</tr>
<table>
</form>
</body>
</html>

This is the page views of above code, I know that code above need to be check about the udp connection and how to supervise the lamp directly using socket connection.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.