So Easy MicroPython — Global Weather Station

Yungger
3 min readApr 24, 2021

*** Just simply add 2~3 lines, then your MCU (ESP8266 or ESP32) can be an IoT enabled device as a Global Weather Station. ***

from MyREST_OWM import myWeather
my_owm = myWeather(YOUR_OWM_KEY)
data = my_owm.read("New York, US")

*** MyREST_OWM is a library I designed for a MCU to read global weather/forecast/air pollution data from OpenWeatherMap platform in very easy and fast way, just as simple as the codes above***

https://openweathermap.org/

*** Before moving to next demonstration, please to have applied your OpenWeatherMap account first. ***

Step 1: Upload libraries to your MCU

First, download the libraries by its link and upload them to your MCU !

  • MyREST_OWM: A specific function library for accessing data on OpenWeatherMap platform
  • MyWifi: A basic library for WiFi connection (No need, if your MCU can connect to WiFi already by your own script)

*** If no idea how to upload files to your MCU board, you can read my other article “So Easy — ESP8266/ESP32 File Management” first. ***

Step 2: How to get Geo information

if you have no idea how to get the city/state/country name or geo information, you can just to go OpenWeatherMap official website to find them.

https://openweathermap.org/find

Step 3: Lets’ learn some examples

Example 0: Let MCU connect to your WiFi AP first

from MyWifi import myWifi
my = myWifi(YOUR_WIFI_SSID, YOUR_WIFI_PWD)
my.connect()

As an IoT device, to make your MCU connect to Internet is essentially true always. And how to do it, no matter to use your own codes or use MyWifi library. JUST connect it to WiFi !!!

*** If you want to know how easy I can simply add 2~3 lines to the script, have my MCU connect to WiFi , then you might be interested to refer my other article “So Easy MicroPython — WiFi Connection, MCU as IoT” . ***

Example 1: Current Weather Data

from MyREST_OWM import myWeather
owm = myWeather(YOUR_OWM_KEY)
print("\n\nWeather in New York", owm.read("New York, US"))
Only add these 3 lines into your code, then your MCU can read global weather data.

Example 2: Forecast Weather Data

from MyREST_OWM import myForecast
owm = myForecast(YOUR_OWM_KEY)
print("\n\nForecast weather in New York", owm.read("New York, US", 3))
Only add these 3 lines, then your MCU can read Forecast weather data, 3 records for example.

Air Pollution Data

from MyREST_OWM import myAirPollution
owm = myAirPollution(YOUR_OWM_KEY)
print("\n\nWeather by City str", owm.read("50, 50")) # "lat, lon"
Only add these 3 lines, then your MCU can read Air Pollution data

DEMO:

This demo shows how to get current weather, forecast weather, and air pollution, same as the codes of every examples above.

That’s all, so easy right ? Hope this helps !

Posted by Yungger

If it really help you, you are welcome to clap your hands clicking on top-left icon, or want to buy me a coffee to encourage me to write more, I thank you too 😘 😘 !!

--

--