- API is a medium with which two applications communicate with each other. Anything you do on the internet, sending a message, check weather on your phone, etc deals with an API.
Look at API as a service instead of any program. We use that service to get our job done.
What is our job? As a user, it is our job to send a request to the API service with a specific URL which has the instructions already present in it.
Example API URL - https://cloud.boltiot.com/remote/b71b13c6-cab1-456a-aa4e-8e61cb2c01aa/digitalWrite?pin=0&state=LOW&deviceName=BOLT8021328
https://cloud.boltiot.com/remote/ - is known as the base URL
b71b13c6-cab1-456a-aa4e-8e61cb2c01aa - is the API key (unique to every Bolt account - similar to a table in a restaurant, and the only way the service will reach to you, instead of some other table)
digitalWrite?pin=0&state=LOW - is the service we are requesting to the cloud. Asking the pin 0 to be set digitally LOW (Let’s say we ordered fried rice)
deviceName=BOLT8021328 - is the DEVICE ID (it acts like the user in a table - which person to serve with fried rice)
Now, when you run this URL, it’ll follow the instructions mentioned in the URL. (Give me my fried rice, instead of somebody else)
I hope, this clears your doubt with API services. Also to mention, Bolt API is a program that is present in the Bolt Cloud, the website server.
No, Bolt Python library only uses this service, just like the products section in the Bolt Cloud uses this service when you create a new product.
- Yes, functions like analogRead(pin) are programmed inside the bolt python library in a way, so that when you put the parameters of pin and value, it generates an API URL. The API URL includes the api key and deviced id from your conf.py file with the pin and value from your digitalWrite(0, HIGH).
3,4,5 - Every product we create on Bolt Cloud, helps us with making projects faster, as we don’t have to program much. When we choose the select the GPIO, input/output, variable name and pin number. API URL gets ready instantly. We only have to use it in our code section to either control with a button or read an Analog pin.
Python on the other hand is a programming language. Even tho most of the effort was done in Bolt Python library already, it is in our hand, what logic we use to make our projects. It could be an easy program, it could include a high level algorithm to perform that.
When we write mybolt.digitalWrite(0,HIGH), mybolt was previously defined in the line mybolt = Bolt(conf.api, conf.device_id). Where api and device_id are put by you in the conf.py file.
With this line, mybolt= Bolt(api key, device id) – Our API URL is half ready.
When the program is run and digitalWrite is RUN, the python library has statement which makes an HTTP request to make the API service. What is HTTP request? Think about it as running the URL in python without the browser.
How to use functions like digitalRead, analogRead - Most of the API services return a JSON format which has the details responded back by the cloud to you (user).
Visit the API section in the cloud.boltiot.com > Choose and build necessary API request > Copy or Test the API there itself.
The value you see returned is in the JSON format. Using that, we can check whether a pin(value) is HIGH(1) or LOW(1) OR (755).
In case of writing a data like digitalWrite, it(value) always returns with a (1).
Let me know if you have doubt in any part.