Data Broker: P181, Figure 6-1
SCADA ( Supervisory control and data acquisition): P186, Figure 6-3
Web based: P190, REST(representational state transfer)
COAP ( Constrained Application Protocol): P191, Figure 6-6
MQTT ( Message Queuing Telemetry Transport): P197, Figure 6-1
MQTT Message Type : P198, Table 6-2
MQTT QoS: P202, Figure 6-13
RESTfu
MQTT
Web Socket
CoAP
Create account on Colab
+ Code with
#!pip install requests
import requests
# Define the base URL and the API key
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
API_KEY = "0f157a1a2ce4e2645838ec201409db41" # Replace with your API key
# Function to fetch weather data for a given city
def get_weather(city_name):
# Construct the URL
url = f"{BASE_URL}?q={city_name}&appid={API_KEY}"
# Send GET request
response = requests.get(url)
# Check if the request was successful
print(f"Status Code {response.status_code}:")
if response.status_code == 200:
data = response.json()
# Extract relevant weather information
main = data['main']
temperature = main['temp']
pressure = main['pressure']
humidity = main['humidity']
weather_description = data['weather'][0]['description']
# Print the weather details
print(f"Weather in {city_name}:")
print(f"Temperature: {temperature}°C")
print(f"Pressure: {pressure} hPa")
print(f"Humidity: {humidity}%")
print(f"Description: {weather_description}")
else:
print("City not found, please check the name or try another city.")
# Example usage
city = "Taipei"
get_weather(city)
You can use your own Key by create account on openweathermap.org
check your api key
https://home.openweathermap.org/api_keys
A fast Access to API
http://api.openweathermap.org/data/2.5/weather?q=Taipei&appid=0f157a1a2ce4e2645838ec201409db41
Kelvin Degree converter
https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html?x=300