ESP8266 Weather Server




About: I'm busy building machines.

If you just bought the ESP8266 and have no idea of where to start, or just wish to have the ESP (I will call the ESP8266 as ESP from now on for the sake of brevity) serve you local weather info for you and people connected to your WiFi, then this post is just for you. The ESP8266 is a low-cost Wi-Fi chip with a full TCP/IP stack and MCU (microcontroller unit) all on a single board that is available for purchase at only about $5 (varies from vendor to vendor). The ESP can do some very cool stuff, like being a web client and a server at the same time. In this instructable, we will be using the ESP to fetch local weather information from OpenWeatherMap using their free API (limited to only 60 requests per minute) and serve it to users connected to our WiFi network. Let's get started.

This project was done by me, Nikhil Raghavendra, a Diploma in Computer Engineering student from Singapore Polytechnic, School of Electrical and Electronic Engineering, under the guidance of my mentor Mr Teo Shin Jen.

Step 1: Obtaining an API Key

To use the free API provided by OpenWeatherMap, you need to know your current location (or target location if you are doing remote monitoring) and the API key. To obtain an API key head over to OpenWeatherMap and sign in. If you are not a member, register yourself and sign in. Once you have signed in, click on the API keys tab, key in the name of your API key and hit the "Generate" button. Then copy your key and save it into a text file (highly recommended) in your working directory.

Step 2: Obtaining Coordinates of Your Location

The API works well with city names, but I like to be specific and if you want to be specific as well, head over to Google Maps and check the search bar of your browser. The numbers after the '@' symbol are your coordinates and if you don't see them for some reason (you might have blocked location access), type in your city name or street address and you should have them there. Copy and paste the coordinates into the same text file where you saved your API key earlier on.

Step 3: Writing the Code

Now, connect the ESP to your computer using a USB to micro USB cable. Then open up the Arduino IDE and head over to the library manager and install the ArduinoJson library. Download the attached code and run it. Before you run it on your ESP, make sure to provide your WiFi SSID and password. The API URL is also needed for the application to work properly, if not you won't even have the weather info to serve. The API URL is in the following format:{your_lat}&lon={your_lon}&appid={API_KEY}

As you can see, you need the coordinates of your current/target location and the API key in order for the API request to function properly. To get the predicted weather info, we perform a GET request using the API URL with the appropriate parameters and then parse the response string using the ArduinoJson library. I will be covering more about the ArduinoJson library in detail, in another instructable.

Step 4: The Results

To check the IP address of your ESP, open the serial monitor and take note of the address. If you don't see anything, press the reset button on your ESP. Type in the IP address of your ESP into the browser of your choice and *boom*, you should see the predicted weather condition at your location.



    • IoT Challenge

      IoT Challenge
    • Fandom Contest

      Fandom Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest

    6 Discussions


    7 months ago

    Having a little bit of trouble; no

    "boom"! lol The ESP 12E is connecting, I see the IP;

    MDNS responder started
    HTTP server started, in my serial monitor, but that is where the information stops. I tried both the default key, and a generated key, after waiting 10 minutes, from the: site. Any suggestions on, how to remedy this, would be welcome.

    1 reply

    Reply 7 months ago

    After I re-read the final part of the instructable, I realised that the sketch was working properly, and that the weather condition, was being written to a page, accessable through a webpage, using my specific IP that was listed in the serial monitor. When I first looked at that web page, I did not realise what I was looking at, since all the page had written on it was "clear"; meaning clear skies. I though it meant clear as in no information lol. thanks


    Question 8 months ago

    can i print the data to a lcd screen?


    1 year ago

    That's a neat tool, I'd love to set up one here. The weather has been really unpredictable this winter!

    1 reply

    Reply 1 year ago

    Thank you! It's amazingly accurate too, the ESP said it would rain (I live very close to the equator so it just rains in the winter) but it was still cloudy at that time, however, a few moments later it did rain.