Support for Node.js

Is there a method of writing the python programs in the course with javascript via node.js? Suppose I make a frontend HTML for toggling the LED, is there a way of writing the equivalent boltIoT program on node.js and make a website out of it?

Hi @rishabhajay24,

Bolt Cloud provides Bolt Cloud API. Once you have the API, you can build your own Website, App on top of it. Each programming language provide a method to trigger(GET, POST etc) the API.

For example: Check the below code for node.js using axios library.

var axios = require('axios');

var config = {
  method: 'get',
  url: 'https://cloud.boltiot.com/remote/1cdfabea-306f-413f-a84b-552938aa8c5d/digitalWrite?pin=2&state=LOW&deviceName=BO7488206',
  headers: { }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

Do let me know in case you need further assitance.

Thank you sir @rahul.singh1 . This implementation works. Is there a documentation for this that I can refer to?

Is there a way to dynamically load the axios API request sir? Suppose I want to read the sensor data continuously, how would I set that up in node without restarting the node server each time?

Hi @rishabhajay24,

Just use the infinite while loop and it will keep fetching the data https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while

For example:

while(true){

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

}

Do not forget to use setTimeout to limit the number of requests per second https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

Do let me know in case you need further assistance.

Thank you very much sir. The setInterval() method is dynamically passing bolt API data to the backend.

Hi @rishabhajay24,

Bolt Cloud API has know information about setInterval. It just counts how many requests you are sending per minute. So you have to control this part from the App, website, or script. For example: If you are using python then you can use time.sleep() to limit the number of requests per second.

1 Like