just add basic function returning a value
function my_function(val){
...
return val2;
}
ASYNCHRONOUS CALLS:
A sensor needs informations from outside
calls the lib callOutside( custom_code , key , id )
Passes custom info for the external query.
Passes a key to recognise the answer (the key is sent back with the answer).
Passes its own id, so the system knows for sure where the question comes from and where to answer to.
Then once the external call is done and the info are found, the system is ready and calls back the Input function inside the Sensor, using the caller id, adding the key in order to be recognised.
Sensors[ parseInt( id ) ].Input( arr , key );
example:
function callOutside(custom_code,key,id) {
var xmlhttp = new XMLHttpRequest();
var url = "https://www.outside.com/public?custom="+custom_code;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var arr = JSON.parse(xmlhttp.responseText);
//if no key passed uses a default key
var temp_key = ( key || "Call Outside" );
Sensors[parseInt(id)].Input( arr , temp_key );
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}