Adding a variable to store the sensor output in HTML

What is the way for adding a variable to store the sensor output in HTML ?
Thanks !

OK the question is not clear.
HTML is used to render and show stuff not store data.

You store data in JavaScript.
var x=0;
At the top and x will be accessible from everywhere.
Or if you want to store a collection of values.
var data =[];
And use the following to add data
data.push(21);
To append 21 to the collection.
If you still want to store data in HTML use a input type hidden but itā€™s not the best way

HTML is a markup language, it cannot be used to store a variable.
Javascript is a scripting language, you can always store data in variable using JS. Thanks

After a lot of trial and error, I found this code to workā€¦

function fetchSensorData() {
fetch(https://cloud.boltiot.com/remote/${apiKey}/digitalRead?pin=x&deviceName=${deviceId}) // instead of x type the sensor pin
.then(response => response.json())
.then(data => {
document.getElementById(ā€œsensor1Statusā€).innerText = "Sensor : " + data.value;
})
.catch(error => console.error(ā€˜Error:ā€™, error));
}

initialize the api key and deviceID before hand. This code is used for digital data. It doesnt use the input variable directly but displays sensor data on html page.

Hope it helps!

1 Like

Hi

Thank you for your help!

After a lot of trial and error, I found this code to workā€¦

function fetchSensorData() {
fetch(https://cloud.boltiot.com/remote/${apiKey}/digitalRead?pin=x&deviceName=${deviceId}) // instead of x type the sensor pin
.then(response => response.json())
.then(data => {
document.getElementById(ā€œsensor1Statusā€).innerText = "Sensor : " + data.value;
})
.catch(error => console.error(ā€˜Error:ā€™, error));
}

initialize the api key and deviceID before hand. This code is used for digital data. It doesnt use the input variable directly but displays sensor data on html page.

Hope it helps!