boltiot

A Python module for communicating with the Bolt Cloud API.


Keywords
iot-platform, blog, bolt-cloud, internet-of-things, python-api
License
MIT
Install
pip install boltiot==1.11.2

Documentation

bolt-api-python

Goal

The goal of this library is to provide an easy to use interface of Bolt Cloud API's. The functions will be quite similar to the Raspberry Pi and Arduino functions.

Installation

  1. Users need to type just one command

    pip install boltiot

  2. The user will set the client once and he can use the same client for every operation. For example.

    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.digitalWrite('0', 'HIGH')

GPIO Functions

  1. digitalWrite Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.digitalWrite('0', 'HIGH')
  2. digitalRead Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.digitalRead('A0')
  3. analogRead Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.analogRead('A0')
  4. analogWrite Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.analogWrite('0', '100')

UART Functions

  1. serialBegin Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.serialBegin('9600')
  2. serialWrite Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.serialWrite('Hello')
  3. serialRead Command    
    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.serialRead('10')

Utility Functions

  1. isOnline Command (to check recent status of device with time when status updated)    

    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.isOnline()
  2. restart Command (to restart the Bolt)    

    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.restart()
  3. version Command (to check device version)    

    from boltiot import Bolt
    api_key = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    device_id  =BOLT1234"
    mybolt = Bolt(api_key, device_id)
    response = mybolt.version()

Alert Functions

  1. send_sms function is used to send email using twilio API .    
    from boltiot import Sms
    ssid = 'You can find SSID in your Twilio Dashboard'
    auth_token = 'You can find  on your Twilio Dashboard'
    from_number = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
    to_number = 'number to send the sms'
    sms = Sms(ssid, auth_token, to_number, from_number)
    sms.send_sms("Messge to be sent")
  2. send_email function is used to send emails using mailgun API .    
    from boltiot import Email
    mailgun_api_key = 'This is the private API key which you can find on your Mailgun Dashboard'
    sandbox_url= 'You can find this on your Mailgun Dashboard'
    sender_email = 'This would be test@your SANDBOX_URL'
    recipient_email = 'Enter your Email ID Here'
    mailer = Email(mailgun_api_key, sandbox_url, sender_email, recipient_email)
    mailer.send_email("Email Subject", "Email Body")
    

Testing

Unit testing

All the unit tests pertaining to this library are present in the /tests folder. These tests can be executed when you want to test particular functionalities of the library.

Running a unit test is simple enter your credentails in the /tests/config.py and you can run tests petaining to GPIO, UART and/or Utility functions.

Functionality testing

Running a functionality test:
  1. Setup the hardware as described in the hardware_config.txt
  2. Run functionality_testing.py

Bolt API documenation

You can find the Bolt API documentation here http://cloud.boltiot.com/api_credentials.

Contributing

Your contributions are always welcome! Please refer to the contribution guidelines.

Guidelines

  • Fork the repository on GitHub.
  • First checkout to dev branch.
  • Create a feature branch only when you are working on a new feature.
  • Write a test which shows that the bug was fixed or that the feature works as expected.
  • Never work on master branch
  • Send a pull request and wait until it gets merged and published. :)
  • Check your spelling and grammar.
  • Remove any trailing whitespaces.