So Easy MicroPython - OpenWeatherMap, Global Weather Data Platform

by Yungger Chen in Circuits > Microcontrollers

616 Views, 2 Favorites, 0 Comments

So Easy MicroPython - OpenWeatherMap, Global Weather Data Platform

header.jpg
So Easy MicroPython - OpenWeatherMap, global weather data platform

*** Just add 2~3 lines, then your MCU will be an IoT enabled device as an 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 very useful library I designed to let your MCU to read global weather data from OpenWeatherMap Cloud platform in very easy and fast way. Just as simple as the codes I wrote above ***

*** Before next demonstration, you should have your account on the cloud platform, we will not take more time to introduce it step by step since anyone can easily get help from official website ***

Upload Libraries to Your MCU

First, You need to upload the libraries to your MCU board:

MyREST_OWM: A specific function library for accessing data on OpenWeatherMap platform

MyWifi: A basic library for WiFi connection (Optional, if your code already make the MCU connect to WiFi)

*** If you have no idea how to upload File to your MCU, read my another article "So Easy MicroPython - ESP8266/ESP32 MCU File Management" first.

*** If you are interested in MyWifi library or no idea how to use it, read my another article "So Easy MicroPython - My WiFi Connection"

Example 1: Current Weather Data

weather_current.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes

from MyWifi import myWifi

my_wifi = myWifi(YOUR_WIFI_SSID, YOUR_WIFI_PWD)

my_wifi.connect()

# Only add these 3 lines, then your MCU can read current weather data

from MyREST_OWM import myWeather

my_owm = myWeather(YOUR_OWM_KEY)

print("\n\nWeather by City str", my_owm.read("New York, US"))

Example 2: Forecast Weather Data

weather_forecast.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes
from MyWifi import myWifi

my_wifi = myWifi(YOUR_WIFI_SSID, YOUR_WIFI_PWD)

my_wifi.connect()

# Only add these 3 lines, then your MCU can read Forecast weather data, 3 records for example.

from MyREST_OWM import myForecast

my_owm = myForecast(YOUR_OWM_KEY)

print("\n\nWeather by City str", my_owm.read("New York, US", 3))

Example 3: Air Pollution Data

air_pollution.jpg

# Connect to WiFi, it cab be omitted if your MCU already get on WiFi in your existing codes

from MyWifi import myWifi

my_wifi = myWifi(YOUR_WIFI_SSID, YOUR_WIFI_PWD)

my_wifi.connect()

# Only add these 3 lines, then your MCU can read Air Pollution data.

from MyREST_OWM import myAirPollution

my_owm = myAirPollution(YOUR_OWM_KEY)

print("\n\nWeather by City str", my_owm.read("50, 50")) # read(lat, lon)

That's So Easy, Hope to Help You a Little Bit !

find_your_city.jpg
NTP WeatherStation

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

Posted by Yungger

If it help you, and want to give some encouragement, just go HERE 😘 😘 !!