please help me getting the error… i want to store value of proximity error( numeric as 1 or 0) in a variable…how can i do that? so that i can use that varible to do other functionings.
Hi @shreemoyrocksmishra9 ,
Please post your code here (not the screenshot of code )so that I can edit your code.
Copy your code here and select the code and then click on </>
icon from text formatting menu.
<html>
<head>
<script type="text/javascript" src="http://cloud.boltiot.com/static/js/boltCommands.js">
</script>
<script type="text/javascript">
setKey('{{ApiKey}}','{{Name}}');
setDebug(true);
function showvalue(msg)
{
if(msg=='show')
{
var result= digitalRead(4,'output');
console.log(result);
}
}
</script>
</head>
<body>
<center>
<button onclick="showvalue("show");">ON</button>
</center>
</body>
</html>
Hi, try with below code and let me know whether it’s working or not
<html>
<head>
<script type="text/javascript" src="http://cloud.boltiot.com/static/js/boltCommands.js">
</script>
</head>
<body>
<center>
<button onclick="showvalue('show');">ON</button>
</center>
<script type="text/javascript">
setKey('{{ApiKey}}','{{Name}}');
setDebug(true);
function showvalue(msg)
{
if(msg=='show')
{
var result= digitalRead(4,'output');
console.log(result);
}
}
</script>
</body>
</html>
yes it is, but i want the success value (1 or 0) to be stored in result(the variable)…and the result should be displayed there…i.e 1 or 0 when i do console.log
Hi @shreemoyrocksmishra9 digitalRead() function does not return any value http://cloud.boltiot.com/static/js/boltCommands.js. You can write your own js function that will return sensor value.
Please refer this code snippet and let me know in case you need further assitance.
<html>
<head>
<script type="text/javascript" src="http://cloud.boltiot.com/static/js/boltCommands.js"></script>
</head>
<body>
<center>
<button onclick="showvalue('show');">ON</button>
<span id="output"></span>
</center>
<script type="text/javascript">
setKey('{{ApiKey}}','{{Name}}');
setDebug(true);
function showvalue(msg)
{
if(msg=='show')
{
var result= digitalWriteCustom(4,'output');
console.log(result);
}
}
function digitalWriteCustom(pin,val){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && debug == 1) {
alert(xmlhttp.responseText);
var obj = JSON.parse(xmlhttp.responseText);
if(obj.success=="1"){
return obj.value;
}
}
};
xmlhttp.open("GET","http://cloud.boltiot.com/remote/"+api_key+"/digitalWrite?pin="+pin+"&state="+val+"&deviceName="+d_name,true);
xmlhttp.send();
}
</script>
</body>
</html>
the value it is telling invalid state…how to print that value in my html page?