Hope you enjoyed the intro video and the first episode of ESPSMS – your own personal assistant. Now in this second episode, we will be learning how we can ask ESPSMS about temperature and weather information of the cities of the world. So lets get started……..
In all the episodes on this topic, one thing will remain same i.e. calling or requesting an API through the board, because this is the only way through which the WiFi board can fetch the answer from the database.
History of this trick
Initially for this trick, I started making unique API for each city using thingspeak.com and when I googled about cities in India I found that the number is around 4000. And this number is only about India, what about the cities of the world?????
Than I thought about the database which other assistants have. I was trying to get access to the database of others but didn’t find any way to do that.
After that I changed the track and started searching about some websites which provides API of temperature and weather information. Initially I found some if the websites providing this data but they ask for money in return.
So after a lot of surfing I found 1 website providing this details for free and this is the one which we gonna use for our assistant.
This is the website in which you’ll get all the weather details for free,but we need to use it accordingly. Here you’ll get the details like,
city.coord.lonCity geo location, longitude
city.coord.latCity geo location, latitude
city.countryCountry code (GB, JP etc.)
temperature.minMinimum temperature at the moment of calculation. This is deviation from ‘temp’ that is possible for large cities and megalopolises geographically expanded (use these parameter optionally).
temperature.maxMaximum temperature at the moment of calculation. This is deviation from ‘temp’ that is possible for large cities and megalopolises geographically expanded (use these parameter optionally).
temperature.unitUnit of measurements. Possilbe valure is Celsius, Kelvin, Fahrenheit.
wind.speed.valueWind speed, mps
wind.speed.nameType of the wind
wind.direction.valueWind direction, degrees (meteorological)
wind.direction.codeCode of the wind direction. Possilbe value is WSW, N, S etc.
wind.direction.nameFull name of the wind direction.
clouds.nameName of the cloudiness
precipitation.modePossible values are ‘no”, name of weather phenomena as ‘rain’, ‘snow’
weather.numberWeather condition id
weather.valueWeather condition name
weather.iconWeather icon id
But the catch here is it’s plan. openweathermap offers various plans for accessing this information. Out of them,we gonna use its default and the free subscription. But we can only use particular hits per minute.
But initially for the project purpose, I think this is the best plan. Further if you want to do business with this, than you can definitely spend money on this. And it is worth also as by just entering the city name as query, we can get the whole weather information in response.
Getting started with openweathermap.org
Create you account in and log In to your account. When you create an account in this, you are by default subscribed to the default plan i.e. the free subscription. You can upgrade you plan later if you want.
After signing in, first find out your API key and keep it secret as you have got limited number of hits per minute so don’t let it used by others…..
After that, click on API on the top just adjacent to Maps and than scroll down and click on By city name under Current weather data.
After that, you will be redirected to a page on that you’ll get the required link which you need to request to get the response. Below image shows the page which you will get after clicking on By city name and the link which is highlighted is the one which we gonna use in our project.
Requesting this link, you’ll get error as you need to attach your API key along with this link.So the proper sequence or the format of this link is,
Just add the City Name and API key and request it through your browser, you will get all the weather details of the particular city. The response you will get in JSON format.
So this is the response, and on the code side, we need to filter this data as to present in proper form.
Same as we did in the first episode for answering the basic questions and calculator trick, we gonna compare or wait for some specific input from the user to do the particular function. In weather information, I have divided it into two tricks,
- Temperature Information
- Weather Information
You can anytime type help format in the serial monitor to know the format of any trick. So for temperature trick the format is,
temperature of City_Name
and for whole weather information the format is,
weather information of City_Name
In the code, you’ll get the response in JSON format as we got in our browser. So for proper display ,we will be filtering the data. The whole filtering process is done inside weather library. So after filtering, we will get the response in this form,
So this is it about the second episode. Hope you liked it and if you know any trick which we can add to our ESPSMS, than do mail us on email@example.com.
Subscribe my YouTube channel for regular notifications
and Join the community on my website to give some contribution to the world by sharing your knowledge.
Stay excited for the next episode. Till then,
explore | learn | share