Skip to content

Commit

Permalink
REST demo in place
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed May 12, 2016
1 parent 40c1e37 commit ebe8814
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 90 deletions.
26 changes: 23 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@

<!-- JQuery -->
<script type="text/javascript" src="js/jquery/2.2.1/jquery-2.2.1.min.js"></script>

<!-- Bootstrap -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="js/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="js/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- VSCP UX version -->
<script type="text/javascript" src="js/version.js"></script>

<!-- Favorite icon -->
<link rel="icon" href="favicon.ico">

<script type="text/javascript">
(function() {

// Wait until the whole website is loaded
$( document ).ready( function() {
// Set version
$("#version").text("Version: " + vscp_ux_version.full );
});

})();
</script>



</head>
<body>
<div class="container-fluid">
Expand All @@ -23,6 +40,9 @@
</p>

<hr />

<div id="version">
</div>

<h1>It works!</h1>
<p>
Expand Down Expand Up @@ -95,8 +115,8 @@ <h3 class="panel-title">The important first test</h3>
<h3 class="panel-title">Demo time</h3>
</div>
<div class="panel-body">
When the login works as of above you can test the user interface components by
<a href="testws/index.html">clicking on this link</a>.
OK login works, click the demo button and start exploring
<input type="button" class="btn btn-warning" value="GO TO DEMO" onclick="window.location.href='testws/index.html';" enabled />
</div>
</div>

Expand Down
159 changes: 88 additions & 71 deletions rest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -506,50 +506,48 @@
};

///////////////////////////////////////////////////////////////////////
// do_readVariable
// do_sendMeasurement
//

var do_readVariable = function() {
var do_sendMeasurement = function() {

var txtVariableName = window.prompt("Name of variable to read:","test");
var txtValue = window.prompt("Send CLASS2.MEASUREMENT_FLOAT. Type=6 (temperature) i degrees Celsius:","23.98");

if ( VscpSessionKey.length > 0 ) {
$.ajax({
url: VscpServer + '/vscp/rest?vscpsession=' + VscpSessionKey +
'&format=jsonp&op=readvar&variable=' + txtVariableName,
'&format=jsonp&op=measurement&value=' + txtValue +
'&guid=""' + // GUID (use GUID of interface)
'&type=6' + // Temperature
'&level=2' + // Level II
'&sensoridx=2' + // Sensor number 2
'&unit=1' + // Unit = 1 Degrees Celsius
'&zone=22' + // Zone = 22
'&subzone=33', // Sub Zone = 33
type : "GET",
jsonpCallback: 'handler',
cache: true,
dataType: 'jsonp',
success: function(response) {

// response will be a javascript
// array of objects
console.log("-----------------------------------------------------------");
console.log(" do_readVariable");
console.log(" do_sendMeasurement");
console.log("-----------------------------------------------------------");
console.log("Success = " + response.success );
console.log("Code = " + response.code );
console.log("Message = " + response.message );
console.log("Description = " + response.description );
console.log("Info = " + response.info );
console.log("Variable name = " + response.varname );
console.log("Variable value = " + response.varvalue );
console.log("Variable type = " + response.vartype );
console.log("Variable type code = " + response.vartypecode );
console.log("Variable percistence = " + response.varpersistence );

if ( response.success ) {
$("#events").html( response.varname + " = " + response.varvalue + ", type = " +
response.vartype + ", typecode = " + response.vartypecode +
", peristence = " + response.varpersistence );
}
else {
$("#events").html( "Unable to read variable" );
}
$("#events").html( "OK Variable written" );
}

},
error: function( xhr, status, error ) {
console.log( "do_readVariable:" + error + " Status:" + status );
console.log( "Close:" + error + " Status:" + status );
}
});
}
Expand All @@ -560,19 +558,27 @@
};

///////////////////////////////////////////////////////////////////////
// do_writeVariable
// do_createVariable
//

var do_writeVariable = function() {

var txtVariableName = window.prompt("Name of variable to write:","test");
var txtVariableValue = window.prompt("New value:","");
var do_createVariable = function() {

var txtVariableName = window.prompt("Name of variable to create:","newvar");
if ( null == txtVariableName ) return;
var txtVariableValue = window.prompt("Value:","This is a new string");
if ( null == txtVariableValue ) return;
var txtVariableType = window.prompt("Type:","string");
if ( null == txtVariableType ) return;
var txtVariablePersistent = window.prompt("Persistent (true/false):","false");
if ( null == txtVariablePersistent ) return;

if ( VscpSessionKey.length > 0 ) {
$.ajax({
url: VscpServer + '/vscp/rest?vscpsession=' + VscpSessionKey +
'&format=jsonp&op=writevar&variable=' + txtVariableName +
'&value=' + txtVariableValue,
'&format=jsonp&op=createvar&variable=' + txtVariableName +
'&value=' + txtVariableValue +
'&type=' + txtVariableType +
'&persistent=' + txtVariablePersistent,
type : "GET",
jsonpCallback: 'handler',
cache: true,
Expand All @@ -581,7 +587,7 @@
// response will be a javascript
// array of objects
console.log("-----------------------------------------------------------");
console.log(" do_writeVariable");
console.log(" do_createVariable");
console.log("-----------------------------------------------------------");
console.log("Success = " + response.success );
console.log("Code = " + response.code );
Expand All @@ -606,27 +612,17 @@
};

///////////////////////////////////////////////////////////////////////
// do_createVariable
// do_readVariable
//

var do_createVariable = function() {

var txtVariableName = window.prompt("Name of variable to create:","newvar");
if ( null == txtVariableName ) return;
var txtVariableValue = window.prompt("Value:","This is a new string");
if ( null == txtVariableValue ) return;
var txtVariableType = window.prompt("Type:","string");
if ( null == txtVariableType ) return;
var txtVariablePersistent = window.prompt("Persistent (true/false):","false");
if ( null == txtVariablePersistent ) return;
var do_readVariable = function() {

var txtVariableName = window.prompt("Name of variable to read:","test");

if ( VscpSessionKey.length > 0 ) {
$.ajax({
url: VscpServer + '/vscp/rest?vscpsession=' + VscpSessionKey +
'&format=jsonp&op=createvar&variable=' + txtVariableName +
'&value=' + txtVariableValue +
'&type=' + txtVariableType +
'&persistent=' + txtVariablePersistent,
'&format=jsonp&op=readvar&variable=' + txtVariableName,
type : "GET",
jsonpCallback: 'handler',
cache: true,
Expand All @@ -635,21 +631,31 @@
// response will be a javascript
// array of objects
console.log("-----------------------------------------------------------");
console.log(" do_createVariable");
console.log(" do_readVariable");
console.log("-----------------------------------------------------------");
console.log("Success = " + response.success );
console.log("Code = " + response.code );
console.log("Message = " + response.message );
console.log("Description = " + response.description );
console.log("Info = " + response.info );
console.log("Variable name = " + response.varname );
console.log("Variable value = " + response.varvalue );
console.log("Variable type = " + response.vartype );
console.log("Variable type code = " + response.vartypecode );
console.log("Variable percistence = " + response.varpersistence );

if ( response.success ) {
$("#events").html( "OK Variable written" );
}
$("#events").html( response.varname + " = " + response.varvalue + ", type = " +
response.vartype + ", typecode = " + response.vartypecode +
", peristence = " + response.varpersistence );
}
else {
$("#events").html( "Unable to read variable" );
}

},
error: function( xhr, status, error ) {
console.log( "Close:" + error + " Status:" + status );
console.log( "do_readVariable:" + error + " Status:" + status );
}
});
}
Expand All @@ -660,18 +666,19 @@
};

///////////////////////////////////////////////////////////////////////
// do_deleteVariable
// do_writeVariable
//

var do_deleteVariable = function() {
var txtVariableName = window.prompt("Name of variable to delete:","test");
if ( null == txtVariableName ) return;
var do_writeVariable = function() {

var txtVariableName = window.prompt("Name of variable to write:","test");
var txtVariableValue = window.prompt("New value:","");

if ( VscpSessionKey.length > 0 ) {
$.ajax({
url: VscpServer + '/vscp/rest?vscpsession=' + VscpSessionKey +
'&format=jsonp&op=deletevar&variable=' + txtVariableName,
'&format=jsonp&op=writevar&variable=' + txtVariableName +
'&value=' + txtVariableValue,
type : "GET",
jsonpCallback: 'handler',
cache: true,
Expand All @@ -680,7 +687,7 @@
// response will be a javascript
// array of objects
console.log("-----------------------------------------------------------");
console.log(" do_deleteVariable");
console.log(" do_writeVariable");
console.log("-----------------------------------------------------------");
console.log("Success = " + response.success );
console.log("Code = " + response.code );
Expand All @@ -689,7 +696,7 @@
console.log("Info = " + response.info );

if ( response.success ) {
$("#events").html( "OK Variable deleted" );
$("#events").html( "OK Variable written" );
}

},
Expand All @@ -704,35 +711,30 @@

};



///////////////////////////////////////////////////////////////////////
// do_sendMeasurement
// do_deleteVariable
//

var do_sendMeasurement = function() {

var txtValue = window.prompt("Send CLASS2.MEASUREMENT_FLOAT. Type=6 (temperature) i degrees Celsius:","23.98");
var do_deleteVariable = function() {

var txtVariableName = window.prompt("Name of variable to delete:","test");
if ( null == txtVariableName ) return;

if ( VscpSessionKey.length > 0 ) {
$.ajax({
url: VscpServer + '/vscp/rest?vscpsession=' + VscpSessionKey +
'&format=jsonp&op=measurement&value=' + txtValue +
'&guid=""' + // GUID (use GUID of interface)
'&type=6' + // Temperature
'&level=2' + // Level II
'&sensoridx=2' + // Sensor number 2
'&unit=1' + // Unit = 1 Degrees Celsius
'&zone=22' + // Zone = 22
'&subzone=33', // Sub Zone = 33
'&format=jsonp&op=deletevar&variable=' + txtVariableName,
type : "GET",
jsonpCallback: 'handler',
cache: true,
dataType: 'jsonp',
success: function(response) {

// response will be a javascript
// array of objects
console.log("-----------------------------------------------------------");
console.log(" do_sendMeasurement");
console.log(" do_deleteVariable");
console.log("-----------------------------------------------------------");
console.log("Success = " + response.success );
console.log("Code = " + response.code );
Expand All @@ -741,7 +743,7 @@
console.log("Info = " + response.info );

if ( response.success ) {
$("#events").html( "OK Variable written" );
$("#events").html( "OK Variable deleted" );
}

},
Expand All @@ -756,6 +758,8 @@

};



/*
function getQueryParams(qs) {
Expand Down Expand Up @@ -797,7 +801,14 @@
</nav>

<div class="container-fluid">
<h1>VSCP REST interface demo code</h1>
<h3>VSCP REST interface demo code</h3>

<p>
This demo demonstrates the VSCP daemon REST interface functionality. The VSCP daemon REST interface is documented
<a href="http://www.vscp.org/docs/vscpd/doku.php?id=vscp_daemon_vscp_daemon_rest_interface">here</a> and you can find the code for this example at
<a href="https://github.com/grodansparadis/vscp-ux">GitHub.</a>
</p>
<!--
<a href="#" onclick="do_setServer();" >Set server</a> |
<a href="#" onclick="do_open();" >Open</a> |
<a href="#" onclick="do_close();" >Close</a> |
Expand All @@ -815,8 +826,14 @@ <h1>VSCP REST interface demo code</h1>
<a href="#" onclick="do_deleteVariable();" >Delete variable</a> |
<a href="#" onclick="do_sendMeasurement();" >Send measurement</a> |
<a href="#" onclick="do_getTable();" >Get table</a>

<p>You should open the console log window of your browser to see status from this demo<p>
-->
<p>
Open a session and possible define a server (set Server) before you start to work with the other available menu items.
</p>
<p>
Open the console log window of your browser to see status from this demo as it use log functionality for info about what is done under
the hood.
<p>
<hr>
<p id="host">Host: </p>
<p id="sessionkey">Sessionkey: </p>
Expand Down
Loading

0 comments on commit ebe8814

Please sign in to comment.