{“success”: “0”, “value”: “Invalid API call. Please use the Bolt Cloud API via API key.”}
What are you trying to do? Can you show that first?
This coad for LDR sensor via api…how to connect api
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js">
</script>
<script>
setKey('{{ApiKey}}','{{Name}}');
</script>
//Add above in head tag
But it won’t be enough, you need a JS code to display the output from the function.
/analogRead?pin=A0 is not a location, it is part of the remote API URL used to GET data in JSON format. For more info - https://docs.boltiot.com/docs/read-analog-input
If you are well versed with HTML, and JS, you can use AJAX or getElementById to call the data and use/print it on the webpage.
If you’re a beginner, I suggest you to stick to the training module.
Meanwhile, you can use my below script and tinker with it.
(Below script will only work in Bolt Cloud)
<html>
<head>
<title>Bolt IoT</title>
<script src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
<script>
setKey('{{ApiKey}}','{{Name}}');
setDebug(true);
</script>
</head>
<body>
<style>
body{
background-color: green;
padding-top:50px;
}
span{
background-color: lightblue;
font-family: 'BankGothic MD BT';font-size: 20px;
border: none;
color: black;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 16px;
}
.button {
background-color: lightgreen;
font-family: 'BankGothic MD BT';font-size: 20px;
border: none;
color: black;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 16px;
}
.button:hover {background-color: gray}
.button:active {
background-color: black;
box-shadow: 0 5px #666;
color: white;
transform: translateY(4px);
}
#grad1 {
height: 500px;
background-color: red; /* For browsers that do not support gradients */
background-image: linear-gradient(to bottom right, blue,aqua); /* Standard syntax (must be last) */
</style>
</style>
<script>
var myVar;
function analogReadcustom(pin,element_id) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
//document.getElementById(element_id).innerHTML = xmlhttp.responseText;
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//document.getElementById("javascript_response").innerHTML = "Javascript Response : "+xmlhttp.responseText;
var obj = JSON.parse(xmlhttp.responseText);
if(obj.success=="1")
{
document.getElementById(element_id).innerHTML = "Pin Val = "+obj.value;
alert(obj.value);
}
}
};
xmlhttp.open("GET",base_url+api_key+"/analogRead?pin="+pin+"&deviceName="+d_name,true);
xmlhttp.send();
}
function myFunc()
{
analogReadcustom('A0','output');
}
</script>
<center>
<button class="button"; onclick="myFunc()">Read Sensor</button><br><br><br>
<span id='output'>Pin Value = </span>
</centre>
</body>
</html>
1 Like