【雕爷学编程】MicroPython动手做(33)——物联网之天气预报2

天气(自然现象)

是指某一个地区距离地表较近的大气层在短时间内的具体状态。而天气现象则是指发生在大气中的各种自然现象,即某瞬时内大气中各种气象要素(如气温、气压、湿度、风、云、雾、雨、闪、雪、霜、雷、雹、霾等)空间分布的综合表现。

天气过程就是一定地区的天气现象随时间的变化过程。各种天气系统都具有一定的空间尺度和时间尺度,而且各种尺度系统间相互交织、相互作用。许多天气系统的组合,构成大范围的天气形势,构成半球甚至全球的大气环流。天气系统总是处在不断新生、发展和消亡过程中,在不同发展阶段有着其相对应的天气现象分布。

天气预报

是应用大气变化的规律,根据当前及近期的天气形势,对某一地未来一定时期内的天气状况进行预测。它是根据对卫星云图和天气图的分析,结合有关气象资料、地形和季节特点、群众经验等综合研究后作出的。如我国中央气象台的卫星云图,就是我国制造的"风云一号"气象卫星摄取的。利用卫星云图照片进行分析,能提高天气预报的准确率。天气预报就时效的长短通常分为三种:短期天气预报(2~3天)、中期天气预报(4~9天),长期天气预报(10~15天以上),中央电视台每天播放的主要是短期天气预报。

天气预报的主要内容是一个地区或城市未来一段时期内的阴晴雨雪、最高最低气温、风向和风力及特殊的灾害性天气。就中国而言,气象台准确预报寒潮、台风、暴雨等自然灾害出现的位置和强度,就可以直接为工农业生产和群众生活服务。天气预报是根据气象观测资料,应用天气学、动力气象学、统计学的原理和方法,对某区域或某地点未来一定时段的天气状况作出定性或定量的预测。它是大气科学研究的一个重要目标。对人们生活有重要意义。


6、当地天气预报及六项生活指数

python 复制代码
#MicroPython动手做(33)------物联网之天气预报
#当地天气预报及六项生活指数

from mpython import *
import network
import json
import urequests

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")

def get_seni_weather(_url, _location):
    _url = _url + "&location=" + _location.replace(" ", "%20")
    response = urequests.get(_url)
    json = response.json()
    response.close()
    return json


w1 = get_seni_weather("https://api.seniverse.com/v3/weather/daily.json?key=SSY9pi-U4QH-ZDrf", "ip")
w2 = get_seni_weather("https://api.seniverse.com/v3/life/suggestion.json?key=SSY9pi-U4QH-ZDrf", "ip")
oled.fill(0)
oled.DispChar((''.join([str(x) for x in [w1["results"][0]["location"]["name"], "   ", w1["results"][0]["daily"][0]["text_day"], "   ", w1["results"][0]["daily"][0]["low"], "  - ", w1["results"][0]["daily"][0]["high"], " 度"]])), 0, 0, 1)
oled.DispChar((str("穿衣指数 : ") + str(w2["results"][0]["suggestion"]["dressing"]["brief"])), 0, 16, 1)
oled.DispChar((str("运动指数 : ") + str(w2["results"][0]["suggestion"]["sport"]["brief"])), 0, 32, 1)
oled.DispChar((str("紫外线指数 : ") + str(w2["results"][0]["suggestion"]["uv"]["brief"])), 0, 48, 1)
oled.show()

mPython X 实验图形编程

当地天气预报及六项生活指数

7、按下AB键查询今明二天的天气和生活指数

python 复制代码
#MicroPython动手做(33)------物联网之天气预报
#按下AB键查询今明二天的天气和生活指数

from mpython import *
import network
import json
import urequests
import time
import music

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")

def on_button_a_down(_):
    time.sleep_ms(10)
    if button_a.value() == 1: return
    music.play('G5:1')
    oled.fill(0)
    oled.DispChar((''.join([str(x) for x in [w1["results"][0]["location"]["name"], "今天", w1["results"][0]["daily"][0]["text_day"], "", w1["results"][0]["daily"][0]["low"], "  - ", w1["results"][0]["daily"][0]["high"], " 度", w1["results"][0]["daily"][0]["high"]]])), 0, 0, 1)
    oled.DispChar((str("穿衣指数 : ") + str(w2["results"][0]["suggestion"]["dressing"]["brief"])), 0, 16, 1)
    oled.DispChar((str("运动指数 : ") + str(w2["results"][0]["suggestion"]["sport"]["brief"])), 0, 32, 1)
    oled.DispChar((str("紫外线指数 : ") + str(w2["results"][0]["suggestion"]["uv"]["brief"])), 0, 48, 1)
    oled.show()

def on_button_b_down(_):
    time.sleep_ms(10)
    if button_b.value() == 1: return
    music.play('B5:1')
    oled.fill(0)
    oled.DispChar((''.join([str(x) for x in [w1["results"][0]["location"]["name"], "明天", w1["results"][0]["daily"][1]["text_day"], "  ", w1["results"][0]["daily"][1]["low"], "  - ", w1["results"][0]["daily"][1]["high"], " 度", w1["results"][0]["daily"][1]["high"]]])), 0, 0, 1)
    oled.DispChar((str("穿衣指数 : ") + str(w2["results"][0]["suggestion"]["dressing"]["brief"])), 0, 16, 1)
    oled.DispChar((str("感冒指数 : ") + str(w2["results"][0]["suggestion"]["flu"]["brief"])), 0, 32, 1)
    oled.DispChar((str("旅游指数 : ") + str(w2["results"][0]["suggestion"]["travel"]["brief"])), 0, 48, 1)
    oled.show()

def get_seni_weather(_url, _location):
    _url = _url + "&location=" + _location.replace(" ", "%20")
    response = urequests.get(_url)
    json = response.json()
    response.close()
    return json

button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)


w1 = get_seni_weather("https://api.seniverse.com/v3/weather/daily.json?key=SSY9pi-U4QH-ZDrf", "ip")
w2 = get_seni_weather("https://api.seniverse.com/v3/life/suggestion.json?key=SSY9pi-U4QH-ZDrf", "ip")
rgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('E5:1')
oled.fill(0)
oled.DispChar("按下AB键查询天气预报", 0, 16, 1)
oled.show()

mPython X 实验图形编程


按下AB键查询今明二天的天气和生活指数

8、使用mindplus sever服务器获取天气预报

无需注册,不用密钥,不要设置,挺简单的一个办法

python 复制代码
#MicroPython动手做(33)------物联网之天气预报
#使用mindplus sever服务器获取天气预报

from mpython import *
import urequests
import network
import ntptime
import music
import json


brightness=9

weather_serveraddr = "http://server.mindplus.top"

weather_appid = "31982666"

weather_appsecret = "E6MtBcxQ"

def weather_getWeather(_weather, _city):
  if weather_serveraddr=="http://www.tianqiapi.com":
    nowResult = urequests.get(weather_serveraddr+"/api/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
    json=nowResult.json()
    nowResult.close()
    return json[_weather]
  else:
    nowResult = urequests.get(weather_serveraddr+"/api/weather/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
    json=nowResult.json()
    nowResult.close()
    return json[_weather]


my_wifi = wifi()
my_wifi.connectWiFi("zhz","zy156721")
while not (my_wifi.sta.isconnected()):
  pass
rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
rgb.write()
music.pitch(392, 50)
oled.fill(0)
oled.DispChar("福建 福州", 0, (1-1)*16, 1)
oled.show()
ntptime.settime(8, "ntp.ntsc.ac.cn")
oled.DispChar(weather_getWeather("wea", "101230101"), 0, (2-1)*16, 1)
oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101230101"))), 0, (3-1)*16, 1)
oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101230101"))), 0, (4-1)*16, 1)
oled.show()

使用mindplus sever服务器获取天气预报

Mind+ 实验图形编程

相关推荐
可愛小吉10 分钟前
Python 课程10-单元测试
开发语言·python·单元测试·tdd·unittest
luckyluckypolar10 分钟前
STM32 -中断
stm32·单片机·嵌入式硬件·物联网
student.J16 分钟前
傅里叶变换
python·算法·傅里叶
无名之逆23 分钟前
计算机专业的就业方向
java·开发语言·c++·人工智能·git·考研·面试
CV-杨帆28 分钟前
大语言模型-教育方向数据集
人工智能·语言模型·自然语言处理
Freak嵌入式1 小时前
全网最适合入门的面向对象编程教程:50 Python函数方法与接口-接口和抽象基类
java·开发语言·数据结构·python·接口·抽象基类
Jackilina_Stone1 小时前
【AI】简单了解AIGC与ChatGPT
人工智能·chatgpt·aigc
paixiaoxin1 小时前
学术新手进阶:Zotero插件全解锁,打造你的高效研究体验
人工智能·经验分享·笔记·机器学习·学习方法·zotero
破晓的历程1 小时前
【机器学习】:解锁数据背后的智慧宝藏——深度探索与未来展望
人工智能·机器学习
AiBoxss1 小时前
AI工具集推荐,简化工作流程!提升效率不是梦!
人工智能