Logic of the program
The code of this project is simple to understand. First we arrange all the necessary API's, Hardware and Software services.
The program will fetch the Real-time weather details in your locality and indicate you about the weather
Lets under understand it step by step
Set up software services- Set up Bolt cloud and get API and Device ID
Login to Bolt Cloud
In the API section you can get you API and DEVICE ID
- Set up Twilio
Login/sign up to Twilio
Get you Email and Phone number verified
Follow the Onboarding process
Trial number is the FROM number. FROM number is the number you will receive SMS from
Now get you SID, AUTH_TOKEN and FROM number.
- Set up OpenWeatherMap
https://openweathermap.org/ go to this site and login.
Get you account verified
Go to API section and subscribe Current Weather Data
Once you subscribe to Current Weather Data you can use it for Real-time tracking of weather of you locality
Go to the Api Docs Section of Current Weather Data and you would see all the information regarding the Api usage and Json format of API
Find out you longitude and latitude of you locatice and mention it in the parameter of your API
Lets have look at the response of the API
This is the response of our API, as seen its in JSON format
Set up Hardware connectionUse Breadboard to form the circuit
However you can connect the positive side of the buzzer and LED to any of the Pins ( '0' '1' '2' '3' '4' ). But make sure you mention the correct pin number in the Code
Understanding the Code- Create conf.py file which contains all your API's and ID's
SID = "Write your twillio SSID here" #generated when you have created your twillio account"
AUTH_TOKEN = "write your twillio auth_token here" #you can access it from your twillio account dashboard
FROM_NUMBER = "This is the number generated by twillio"
TO_NUMBER = "This is your personal mobile number"#must add +91 in the beginning
BOLT_API = "This your bolt api key"
DEVICE_ID = "This your bolt device id like BOLTXXXXXXXX"
- Start with importing libraries and files
pass API_KEY and DEVICE_ID from conf.py file to Bolt and use mybolt variable
pass AUTH_TOKEN,TO_NUMBER and FROM_NUMBER from conf.py file to Sms and use sms variable
- Fetch the Real-time weather report using the OpenWeatherMap site API
use requests.get( ) method to get the real-time data. We know that OpenWeather site will get us the data of weather in json format. So we use api_data=api_link.json( ) as to fetch each weather data by api_data variable.
If you want you can print api_data and see the result of how the data is displayed.
- Now we get the data we require
Since we get the data in json format which is nothing but object notation. so we access the Value of the object and store it into different variables corresponding to it.
https://www.w3schools.com/js/js_json_intro.asp You can visit this site to know more about Json and how to access the value of the object.
- Main logic of the program
Now we have come to the main logic part. This block of code is simple If, Else-If method of python. We first check IF the status of the weather is 'Rain' or 'Drizzle' or 'Thunderstorm' and if the condition is true then this block of code will be executed and Buzzer starts to beep hence the following things will be printed.
Else-If we check if the status of the weather is 'Clouds' or 'Clear' and print the following. If this case is true then it indicates that Weather is suitable to dry our cloths and for this reason LED starts to glow.
- Now the last block of code
With out the except method our try method will not work so be careful about this. The except Exception as e statement is a statement that defines an argument to the except statement. e in the latter statement is utilized to create an instance of the given Exception in the code and makes all of the attributes of the given Exception object accessible to the user.
I have given time.sleep as to induce time delay. Then in the end mybolt.digitalWrite('4, 'LOW') is for turning off the buzzer or LED
Full code viewWe have completed our project. You can use the same logic and methods to do various other projects. I hope you found it helpful.
Thank you
Comments