obix 协议 通过http协议读写举例

1,后台建立obix协议。

 2.建立一个bw 可写的节点

3,获取节点值get

http://10.7.10.15/obix/config/Sampler/pw

4:设置节点值:

http://10.7.10.15/obix/config/Sampler/pw/set/<bool val="true" />

下雨了,先回家,等接好图在详细写下,整个过程。

1省了:无法上传图片。

2省了:无法上传图片

3下面是页面内容:

<script type='text/javascript' src='/ord?file:^obixWatch.js'></script>
<script type='text/javascript' src='/ord?file:^jquery.js'></script>
<script type='text/javascript' language='Javascript'>

  var obixWatch = new ObixWatch();
  
  /**
   * Called when the page is loaded
   */
  function start()
  {
    // Build the items to Watch
    var item1 = { uri: '/obix/config/Test/Light1/out/', 
                  handler: watchCallback, 
                  dispName: 'VAV1', 
                  inBody: '',
                  pickle: document.getElementById('abc001') 
                };
    
    var item2 = { uri: '/obix/config/Test/Light2/out/', 
                  handler: watchCallback, 
                  dispName: 'VAV2', 
                  inBody: '',
                  pickle: document.getElementById('abc002') 
                };
    
    var item3 = { uri: '/obix/config/Test/Light3/out/', 
                  handler: watchCallback, 
                  dispName: 'VAV3', 
                  inBody: '',
                  pickle: document.getElementById('abc003') 
                };
	 var item4 = { uri: '/obix/config/Test/Motor/out/', 
				  handler: watchCallback2, 
				  dispName: 'VAV4', 
				  inBody: '',
				  pickle: document.getElementById('abc004') 
	         };
	 var item5 = { uri: '/obix/config/Test/IR_IN/out/', 
		  handler: watchCallback3, 
		  dispName: 'VAV5', 
		  inBody: '',
		  pickle: document.getElementById('abc005') 
	 };
	  var item6 = { uri: '/obix/config/Test/Restive/out/', 
		  handler: watchCallback4, 
		  dispName: 'VAV6', 
		  inBody: '',
		  pickle: document.getElementById('abc006') 
	 };

    // Add the items to Watch                
    obixWatch.addURIs([item1, item2, item3,item4,item5,item6]);
    
    // Start the Watch
    obixWatch.startWatch();

 
  }
  
  /**
   * Called when the page is unloaded
   */
  function stop()
  {
    obixWatch.stopWatch();
  }
  
  /**
   * Call back when the oBIX Watch is updated
   */
  function watchCallback(uriItem, node)
  {
    // Update the inner HTML element with the 'display' part of oBIX
    uriItem.pickle.innerHTML = node.getAttribute('val');  
	var num=node.getAttribute('val'); 
	if(num==5.0){
	    uriItem.pickle.innerHTML ="<img src='images/light_yes.jpg'/>";  
	}
	else{
	    uriItem.pickle.innerHTML ="<img src='images/light_no.jpg'/>";  
	}
  }

    function watchCallback2(uriItem, node)
  {
    // Update the inner HTML element with the 'display' part of oBIX
    uriItem.pickle.innerHTML = node.getAttribute('val');  
	var flag=node.getAttribute('val'); 
	if(flag=="true"){
	    uriItem.pickle.innerHTML ="<img src='images/fenji_yes.jpg'/>";  
	}
	else{
	    uriItem.pickle.innerHTML ="<img src='images/fenji_no.jpg'/>";  
	}
  }
     function watchCallback3(uriItem, node)
  {
    // Update the inner HTML element with the 'display' part of oBIX
    uriItem.pickle.innerHTML = node.getAttribute('val');  
	var flag=node.getAttribute('val'); 
	if(flag=="true"){
	    uriItem.pickle.innerHTML ="有感觉物体存在";  
	}
	else{
	    uriItem.pickle.innerHTML ="没有感觉物体";  
	}
  }
   function watchCallback4(uriItem, node)
  {
    // Update the inner HTML element with the 'display' part of oBIX
    
	var flag=node.getAttribute('val'); 
	   uriItem.pickle.innerHTML = node.getAttribute('val');  
  }


  function ajaxRequest(){
   $.ajax({
   type: "POST",
   url: "/obix/config/Test2/Bw1/set/",
   data: '<bool val="false" />',
   success: function(msg){
     //alert( "data: " + msg );
   }
   });
  }

   function ajaxRequest3(method,httpurl,arg1,arg2){
	  $.ajax({
    type: method,
    url: httpurl,
    data: '<'+ arg1+' val="'+arg2+'"/>',
    success: function(msg){
     //alert( "data: " + msg );
   }
   });
  }


</script> 
</head>

<body onload="start()" onunload="stop()">
<div>
 
  
   <div>
     <fieldset style="width: 500">
     <h1 align="center">灯泡控制</h1><br />
    <table border="1" width="500" height="220" >
    <tr>
      <th>名称</th>
      <th>灯泡状态</th>
      <th colspan="2">控制开关</th>
    </tr>
    <tr>
      <td>灯1</td>
      <td><a id='abc001'>-wait-</a></td>
	  <td> <input type="button" value="开灯" onclick='ajaxRequest3("Post","/obix/config/Test/Light1/set/","real",5 )' /></td>
	  <td>  <input type="button" value="关灯" onclick='ajaxRequest3("post","/obix/config/Test/Light1/set/","real",0 )' /></td>
    </tr>
    <tr>
    <td>灯2</td>
      <td><a id='abc002'>-wait-</a></td>
	 <td> <input type="button" value="开灯" onclick='ajaxRequest3("Post","/obix/config/Test/Light2/set/","real",5 )' /></td>
	  <td>  <input type="button" value="关灯" onclick='ajaxRequest3("post","/obix/config/Test/Light2/set/","real",0 )' /></td>
    </tr>
    <tr>
      <td>灯3</td>
      <td><a id='abc003'>-wait-</a></td>
	  <td> <input type="button" value="开灯" onclick='ajaxRequest3("Post","/obix/config/Test/Light3/set/","real",5 )' /></td>
	  <td><input type="button" value="关灯" onclick='ajaxRequest3("post","/obix/config/Test/Light3/set/","real",0 )' /></td>
    </tr>
    </table>
	  </fieldset>
    </div>
	</div>
</br>
<hr/>
<div>
 <div style="float: left">
   <fieldset style="width: 200">
 <h1 align="center">电机机控制</h1><br />
       <a id='abc004'>-wait-</a>
<table width="200">
  <tr>
   <td>
   <input type="button" value="打开电机" onclick='ajaxRequest3("post","/obix/config/Test/Motor/set/","bool","true" )' />
   <input type="button" value="关闭电机" onclick='ajaxRequest3("post","/obix/config/Test/Motor/set/","bool","false" )' />
   <td>
  </tr>
 </table>
	  </fieldset>
    </div>

	  <div style="float: inherit">
    <fieldset style="width: 300;height:105" >
          
			<h1 align="center">红外感应</h1><br />
       <h1  align="center" style="color: red;font-size: 14"> <a id='abc005'>-wait-</a></h1>
	  </fieldset>
    </div>
	 <div style="float: inherit">
  <fieldset style="width: 300;height:105"">
 <h1  align="center">弯曲度感应</h1><br />
     <h1  align="center" style="color: red;">   <a id='abc006'>-wait-</a></h1>
	  </fieldset>
    </div>
	</div>
</body>
</html>

 用页面的话,延迟会有一些,不如那个applet好,但这样我们就可以操作页面显示更好点,如何要查看调用的节点的路径我们就的看http://localhost/obix/