Html script tag Query

How do you print value of analogRead(“A0”) in html inside the script tag?
It is supposed to return LDR sensor value
we use json.loads() in python
what is its equivalent in html?

Hi @deepanjalipandit660,

If you are using the boltCommands.js https://cloud.boltiot.com/static/js/boltCommands.js and if you look closely for this function

function analogRead(pin,element_id) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            alert(xmlhttp.responseText);

            var obj = JSON.parse(xmlhttp.responseText);
            if(obj.success=="1"){
                 document.getElementById(element_id).innerHTML = "Pin Val = "+obj.value;
            }
            else{
                    document.getElementById(element_id).innerHTML = "Error = "+xmlhttp.responseText;
            }
        }
    };
    xmlhttp.open("GET",base_url+api_key+"/analogRead?pin="+pin+"&deviceName="+d_name,true);
    xmlhttp.send();
} 

The below line is doing the parsing of data.

 var obj = JSON.parse(xmlhttp.responseText);

Do let me know i case you need any other information.

1 Like