Bolt IoT Javascript library

3rd Party JS library to control your Bolt devices.

❗️

Warning!

This is a third party library which is NOT created and maintained by Bolt IoT. Use it at your own caution. Bolt IoT will NOT be providing any support for the library and will not be responsible for any errors arising from the use of this library.

One of our customer's, Pranay Dutta has created a JS library which can be used to control your Bolt devices.

The JS library can be loaded in the head tag of your HTML document using the code,

<script src="https://unpkg.com/bolt-iot-wrapper/umd/boltIotWrapper.min.js"></script>

Once you have added the tag to include the script, you will need to first add the Bolt device using the device ID and API key. After this, you can control your Bolt device or get information about the device.
Supported functions are,

  1. Initialise using
    Devices.add("BOLTXXXX", "API_KEY");

  2. Add Device(Optional)
    const instance = Devices.read("BOLTXXXX", "API_KEY");
    Use this function to add another device.

  3. Analog Functions
    ⋅⋅1. instance.Analog.read() // reads analog pin data return a promise
    ⋅⋅2. instance.Analog.loopRead({milliseconds},{callback}) // reads analog pin continously in particular interval

  4. Digital Functions
    ⋅⋅1. instance.Digital.read({pin: "" | pins: []}) // read Digital signals of single or multiple pins. returns a promise
    ⋅⋅2. instance.Digital.write({pin: "", state: ""}) // write digital signals
    ⋅⋅3. instance.Digital.loopRead({pin | pins[]},{milliseconds},{callback}) // read digital singals in particular interval

  5. UART Functions
    ⋅⋅1. instance.UART.begin({baudRate}) // sets the baud rate
    ⋅⋅2. instance.UART.read({till}) // reads till
    ⋅⋅3. instance.UART.write({data}) // writes data
    ⋅⋅4. instance.UART.readWrite({data},{till}) // reads and writes data

  6. Utility Functions
    ⋅⋅1. instance.Utility.isOnline() // returns a promise with resolved valueas true/false
    ⋅⋅2. instance.Utility.restart() // restarts the Bolt device
    ⋅⋅3. instance.Utility.version() // returns the device version details

Here is a sample code to illustrate its working. The page will ask you to enter your Bolt ID and the API key and use it to switch on/off the Digital pin of your choice.

<html>
<head>
    <!-- CDN script tag-->
    <script src="https://unpkg.com/bolt-iot-wrapper/umd/boltIotWrapper.min.js"></script>
</head>

<body>
    <h1>LED Tester</h1>

    Bolt ID: <input type="text" id="bolt_id" value="BOLT">
    <br>
    API Key: <input type="text" id="api_key" value="">
    <br>
    Digital Pin: <input type="number" id="pin" value=0>
    <br>
    <button onclick="make_led_as('HIGH')">ON</button>
    <button onclick="make_led_as('LOW')">OFF</button>

    <script>
        var bolt = null;
        function setUpBolt() {
            console.log("Setting up Bolt");
            let deviceName = document.getElementById("bolt_id").value;
            let deviceKey = document.getElementById("api_key").value;
            return boltApi.Devices.add(deviceName, deviceKey);
        }
        
        function make_led_as(state){
            if(window.bolt == null){
                window.bolt = setUpBolt();
            }
            let pin = document.getElementById("pin").value;
            LED(pin, state);
        }

        function LED(pin, state) {
            bolt.Digital.write({ pin: pin, state: state });
        }
    </script>

</body>

</html>

For more information, you can visit the project here.