Esp8266 Weather Data Parser Openweathermap

7,458

9

16

Introduction: Esp8266 Weather Data Parser Openweathermap

Hello friends!

In this short instructable i would like to present my first Esp8266 project.

It is a weather data parser.

Step 1: Before We Begin

Back in a few weeks i was reading many articles about the Esp8266 and the weather data parsing,encoding, decoding and printing it to an LCD. So i decided to make my own minimal looking weather data parser with Nodemcu and i thought i share it.

Step 2: Openweathermap

The https://openweathermap.org/ is a relatively big and accurate weather forecast site. I have been using it for a time now. All my Android apps and esp8266 boards use the API keys provided by the site. I am using the free API key, but you can purchase more options if you are willing to pay some money for it.

The most interesting thing is, that you can generate multiple API keys with your account. This way you can use more IoT boards at the same time.

https://home.openweathermap.org/api_keys

Step 3: Materials

Parts needed:

- Esp8266 compatible board

- ILI9341 SPI TFT LCD

- F-F jumper wires

Step 4: Software

In order to make our weather station work we will need the included libraries and sketch.

I am providing the sketch and the library for the tft lcd that i have used.

Plus we will need the Openweathermap API key.

https://github.com/Lacybad/ESP8266-OWM-Station

Step 5: Connections

The connections are the following:

TFT DC Digital 3

TFT CS Digital 8

TFT MOSI Digital 7

TFT SCK Digital 5

TFT RESET Reset or 3.3V

VCC - 3.3 Volts

GND - Ground

LED - 3.3 Volts

In the sketch don't change the pinout!!!!!

Step 6: Weather Station Running

OK! After assembling the hardware and uploading the sketch the Esp board is connecting to the internet and parsing the weather data.

What wee see:

- The first line indicates when the board is connected to the wifi network.

- Second line is showing the location according to the city ID.

- Third line is the weather description.

- Fourth line is the temperature and humidity.

- Fifth line is the barometric pressure.

- Sixth line is the wind speed in m/s.

- Below it is the Temperature min and max , wind angle in degrees.

- The visibility in meters

- And last the local IP Address

The esp8266 is connecting to the internet every 10 minutes to update the conditions.

Step 7: Done!

You are done.

Use it as you like :)

If you want to use a more advenced weather station pls take a look at the videos below.

Be the First to Share

    Recommendations

    • Make it Fly Challenge

      Make it Fly Challenge
    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge

    16 Comments

    0
    Pilot_ted
    Pilot_ted

    6 weeks ago

    Further to my questions a couple of days ago, I thought the follownig comments/issues might be useful, particularly for other would be constructors of this great project.
    1. Despite several attempts and modifications, the code presented seems only to work when using Windows 10. (Windows 7 is a no no).
    2. The dreaded error message produced :- " Error compiling for Node MCU 1.0 " is taken care of in Windows 10.
    3. The error message produced during the compile phase using "ArduinoJson.h" version 6.xx is produced from the installed library, however you can downgrade this version (try 5.13.43) via Library Manager etc which will then compile clean. Alternatively, you can upgrade the sketch by following closely, the message produced "Migrating from Version 5 to 6.
    Any issues re the above mail me.

    0
    Pilot_ted
    Pilot_ted

    Question 6 weeks ago

    Hello again,
    Sorry to trouble you but 2 questions:
    What is/are the differences between V2 ino and the ordinary version?
    Also neither version will compile under windows 7 pro, but both compile in windows 10 pro!
    Wondering if there are quick fixes for these issues?

    My thanks of course.

    Ted

    0
    NoOne38
    NoOne38

    Question 4 months ago

    Hello,
    Forgive
    me for bothering you but I'm still doing your great project and I'm
    having trouble understanding the refresh of the screens to put it simply
    I started by using the S0 screen (without openweather) I added an outside temperature DHT22 via nrf24l01 (you are bme280)
    if this one appears normally after 2 minutes approx but it takes + 40 minutes to be erased when I cut the connection
    is this a pb with millis () or with the nrf24l01?

    thank you so much
    cordially

    20210321_120221-1.jpg
    0
    Lacybad
    Lacybad

    Answer 4 months ago

    It think it is with the screen update. Pls try to print the nrf module values to the serial monitor with low refresh time.That way you could see which is not updating 😕

    0
    NoOne38
    NoOne38

    Reply 4 months ago

    Hello,
    Thank you for answering
    I
    have already done what you suggest (time nrf = 5mn) but the time is
    still very long (approx 30mn) when I lose the connection with the module
    nrf24l01 and I did not find in the sketch 'meteo_320_240' of equivalent
    time
    I look for ....
    thanks again
    cordially

    0
    NoOne38
    NoOne38

    4 months ago

    Bonjour,

    I am progressing (...) but I have a lot of problems with the management of screens
    the temperature and humidity (DHT22) that I added on the S2 and S0 screens slow down the program.
    So I will need your help to know how you managed the time of displays and measurements on the screens.
    thanks again
    cordially

    20210308_153112-1.jpg
    0
    Lacybad
    Lacybad

    Reply 4 months ago

    This WS is based on a simple API call sample sketch. It was written on an old IDE version.
    Esp connects and reads data, displays it on the screen. Timer begins 10x60 seconds and starts all over again.
    Of course i noticed everything is delayed, because it has a minute delay /delay(60000)/ at the end of the void loop.
    Earlier i experimented with sensors myself. I created a seperate loop for the sensor readings with 0.5 or 1 second delay and declared it in the void loop. So i managed to reduce the delay time.
    Maybe it is worth a try, at the moment this is the advice i can give. Pls note that i am only a hobbist and not a pro programmer. Dont have much time to play with Arduino lately, pls forgive me for that :(

    0
    NoOne38
    NoOne38

    Reply 4 months ago

    Thank you for answering
    I am continuing the project because I am just starting out and I have not yet understood all of the int () mechanisms to allow sensor readings
    But I'm a taker of new ideas
    In addition to this, you need to know more about it.
    Thanks again
    Regards
    0
    NoOne38
    NoOne38

    5 months ago

    Hello,
    Very nice project and thank you for it, I'm working on the one with 4 and 240x320 TFT screens
    and
    I want to add the IAQ Air Quality index on the S2 screen but without
    result, I have the correct information in the sensor_fn sketch but not
    on the screen
    so i would need your help
    thanks again

    0
    Lacybad
    Lacybad

    Reply 5 months ago

    You are working on a WS with multiple displays?

    0
    NoOne38
    NoOne38

    Reply 5 months ago

    No, I only work with 1 screen
    I reduced the minutes display in the S2 screen (space problem), to put the air quality display there via BME680 but I have display difficulties
    Bravo again for this project !!

    20210307_085639-1.jpg
    0
    Lacybad
    Lacybad

    Reply 5 months ago

    Are you getting readings from the BME680 sensor?
    Did you specify the I2C address in the void setup //Wire.begin (0x77)for eg.?
    For the BME280 i always do.
    Looks very neat :)

    0
    NoOne38
    NoOne38

    Reply 5 months ago

    Yes, in fact, I read the sensor via the function 'void do_read_bme ()' and (I specify that the sensor is not remote but directly on the PCB)

    *****************************************************************************************
    #ifdef bme280
    void do_read_bme()
    {
    static time_t t_period_bme=0;
    float measured_temp; // mesure de la température à l'aide d'un capteur de température
    float measured_humi; // Mesure de l'humidité à l'aide d'un capteur de débit
    float measured_gas;
    float DewpointTemperature;
    float adjusted_temp;
    float adjusted_humi;
    float hum_score, gas_score, temp_score,score;
    if (millis()//5min
    float temperature=200, humidity=200, pressure=200;
    if (! bme.performReading())
    {
    Serial.println("Failed to perform reading :(");
    return;
    }
    // Calcul point de rosée
    measured_temp = bme.temperature;
    measured_humi = bme.humidity;
    measured_gas = bme.gas_resistance;
    double a_dp = 17.271; //constantes nécessaires pour le calcul du point de rosée
    double b_dp = 237.7;
    double tempcalc_dp;
    tempcalc_dp = (a_dp * measured_temp) / (b_dp + measured_temp) + log(measured_humi * 0.01);
    DewpointTemperature = (b_dp * tempcalc_dp) / (a_dp - tempcalc_dp);
    Serial.print("Point de rosée : ");
    Serial.print(DewpointTemperature);
    Serial.println("°C; ");
    // Température ajustée
    adjusted_temp = measured_temp + TEMP_CORR;
    Serial.print("Température ajustée : ");
    Serial.print(adjusted_temp);
    Serial.println("; ");
    //August-Roche-Magnus approximation (http://bmcnoldy.rsmas.miami.edu/Humidity.html)
    adjusted_humi = 100 * (exp((17.625 * DewpointTemperature) / (243.04 + DewpointTemperature)) / exp((17.625 * adjusted_temp) / (243.04 + adjusted_temp)));
    Serial.print("Humidité ajustée : ");
    Serial.print(adjusted_humi);
    Serial.println("; ");
    //** temperature brute ** //
    temp_kv=round(adjusted_temp);
    //** Humidite brute ** //
    h_kv=round(adjusted_humi);
    //*** Pression brute ** //
    pr_kv=bme.pressure/100+delta_p;
    if (pr_kv>10000)
    {
    if (log_file)
    {
    log_str="bme280 ERR P="+String(pr_kv);
    do_log();
    }
    pr_kv=200;//err
    }
    #ifdef debug
    Serial.println(F("bme brute-------------"));
    Serial.println(bme.pressure/100);
    Serial.println(bme.temperature);
    Serial.println(bme.humidity);
    Serial.println(bme.gas_resistance/1000.0);
    Serial.println(F("Altitude-------------"));
    Serial.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(F("bme ajust-------------"));
    Serial.println("T° ajustee (°C): "+String(adjusted_temp));
    Serial.println("H ajustee (%rh): "+String(adjusted_humi));
    #endif
    if (temp_kv<-50||temp_kv>70) temp_kv=200;
    if (h_kv<0||h_kv>100) h_kv=200;
    if (temp_kv!=200)
    {
    ref_kv_th=true;
    t_period_bme=millis()+t_bme_ref*1000; //5min
    }
    }
    #endif
    **************************************************************************************
    However the measurements are not 'refreshed' correctly, the 'Gas' measurement is not good
    I also specify that I test this sensor with the S0 screen so only ntp (whose measurements disappear after a few minutes (?))

    (Currently I'm trying to integrate a 'local' temperature and humidity measurement with DHT022 instead of BME680 it might be easier)

    sorry for my english .......i'm french
    cordially
    0
    Lacybad
    Lacybad

    Reply 5 months ago

    The air quality index results are not printed on the display i guess.

    Interesting, never thought of it before.
    You got me with the question right now 😕

    0
    clueless17
    clueless17

    Question 1 year ago

    Almost everything works--but the size seems too big to fit all of the items within the screen. I tried to fix it through the TFT_eSPI-3 file, but could not really reduce it properly. Any suggestions will be greatly appreciated. Thanks!

    IMG_1653.jpg
    0
    Lacybad
    Lacybad

    Answer 1 year ago

    I did not experiment with the 1.8" tft, the only advice i can give is try to use a small font for the display if you can.With the standard ST7735 library i would not be a problem. The 128X160 pixel resolution is usually not really enough for the Nodemcu.