- When the login works as of above you can test the user interface components by
- clicking on this link.
+ OK login works, click the demo button and start exploring
+
diff --git a/rest/index.html b/rest/index.html
index 90e4c5a7..1db3aac6 100644
--- a/rest/index.html
+++ b/rest/index.html
@@ -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 );
}
});
}
@@ -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,
@@ -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 );
@@ -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,
@@ -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 );
}
});
}
@@ -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,
@@ -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 );
@@ -689,7 +696,7 @@
console.log("Info = " + response.info );
if ( response.success ) {
- $("#events").html( "OK Variable deleted" );
+ $("#events").html( "OK Variable written" );
}
},
@@ -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 );
@@ -741,7 +743,7 @@
console.log("Info = " + response.info );
if ( response.success ) {
- $("#events").html( "OK Variable written" );
+ $("#events").html( "OK Variable deleted" );
}
},
@@ -756,6 +758,8 @@
};
+
+
/*
function getQueryParams(qs) {
@@ -797,7 +801,14 @@
-
VSCP REST interface demo code
+
VSCP REST interface demo code
+
+
+ This demo demonstrates the VSCP daemon REST interface functionality. The VSCP daemon REST interface is documented
+ here and you can find the code for this example at
+ GitHub.
+
+
+
+ Open a session and possible define a server (set Server) before you start to work with the other available menu items.
+
+
+ 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.
+