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

这篇具有很好参考价值的文章主要介绍了【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

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

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
天气预报
是应用大气变化的规律,根据当前及近期的天气形势,对某一地未来一定时期内的天气状况进行预测。它是根据对卫星云图和天气图的分析,结合有关气象资料、地形和季节特点、群众经验等综合研究后作出的。如我国中央气象台的卫星云图,就是我国制造的“风云一号”气象卫星摄取的。利用卫星云图照片进行分析,能提高天气预报的准确率。天气预报就时效的长短通常分为三种:短期天气预报(2~3天)、中期天气预报(4~9天),长期天气预报(10~15天以上),中央电视台每天播放的主要是短期天气预报。

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

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

9、使用三轴传感器选择城市天气预报

向前倾斜为安徽合肥,向后为福建福州
向左为上海,向右为北京

#MicroPython动手做(33)——物联网之天气预报
#使用三轴传感器选择城市天气预报

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("zh","zy1567")
while not (my_wifi.sta.isconnected()):
  pass
rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
rgb.write()
music.pitch(165, 50)
ntptime.settime(8, "ntp.ntsc.ac.cn")
while True:
  if (accelerometer.get_x() < -0.3):
    music.pitch(196, 50)
    oled.fill(0)
    oled.DispChar("安徽 合肥", 0, (1-1)*16, 1)
    oled.DispChar(weather_getWeather("wea", "101220101"), 0, (2-1)*16, 1)
    oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101220101"))), 0, (3-1)*16, 1)
    oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101220101"))), 0, (4-1)*16, 1)
    oled.show()
  if (accelerometer.get_x() > 0.3):
    music.pitch(262, 50)
    oled.fill(0)
    oled.DispChar("福建 福州", 0, (1-1)*16, 1)
    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()
  if (accelerometer.get_y() > 0.3):
    music.pitch(392, 50)
    oled.fill(0)
    oled.DispChar("上海", 0, (1-1)*16, 1)
    oled.DispChar(weather_getWeather("wea", "101020100"), 0, (2-1)*16, 1)
    oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101020100"))), 0, (3-1)*16, 1)
    oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101020100"))), 0, (4-1)*16, 1)
    oled.show()
  if (accelerometer.get_y() < -0.3):
    music.pitch(659, 50)
    oled.fill(0)
    oled.DispChar("北京", 0, (1-1)*16, 1)
    oled.DispChar(weather_getWeather("wea", "101010100"), 0, (2-1)*16, 1)
    oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101010100"))), 0, (3-1)*16, 1)
    oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101010100"))), 0, (4-1)*16, 1)
    oled.show()

Mind+ 实验图形编程

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

10、全球天气API平台

链接:http://www.tianqiapi.com

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

注册全球天气API平台账号

链接:http://www.tianqiapi.com/user/register

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

登录全球天气API平台

链接:http://www.tianqiapi.com/user/index

激活账号,获取APPID和APPSecret(密钥)

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

11、六位触摸按键选择城市天气预报

P 上海 Y 福州 T 北京 H 重庆 O 深圳 N 济南

#MicroPython动手做(33)——物联网之天气预报
#六位触摸按键选择城市天气预报

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


touch_threshold = {'P': 400, 'Y': 400, 'T': 400, 'H': 400, 'O': 400, 'N': 400}

tim12 = Timer(12)
_status_p = _status_y = _status_t = _status_h = _status_o = _status_n = 0
def on_touchpad_P_pressed():pass
def on_touchpad_P_unpressed():pass
def on_touchpad_Y_pressed():pass
def on_touchpad_Y_unpressed():pass
def on_touchpad_T_pressed():pass
def on_touchpad_T_unpressed():pass
def on_touchpad_H_pressed():pass
def on_touchpad_H_unpressed():pass
def on_touchpad_O_pressed():pass
def on_touchpad_O_unpressed():pass
def on_touchpad_N_pressed():pass
def on_touchpad_N_unpressed():pass

def timer12_tick(_):
  global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n
  try:
    touchPad_P.read();pass
  except:
    return
  if touchPad_P.read() < touch_threshold['P']:
    if 1 != _status_p:_status_p = 1;on_touchpad_P_pressed()
  elif 0 != _status_p:_status_p = 0;on_touchpad_P_unpressed()
  if touchPad_Y.read() < touch_threshold['Y']:
    if 1 != _status_y:_status_y = 1;on_touchpad_Y_pressed()
  elif 0 != _status_y:_status_y = 0;on_touchpad_Y_unpressed()
  if touchPad_T.read() < touch_threshold['T']:
    if 1 != _status_t:_status_t = 1;on_touchpad_T_pressed()
  elif 0 != _status_t:_status_t = 0;on_touchpad_T_unpressed()
  if touchPad_H.read() < touch_threshold['H']:
    if 1 != _status_h:_status_h = 1;on_touchpad_H_pressed()
  elif 0 != _status_h:_status_h = 0;on_touchpad_H_unpressed()
  if touchPad_O.read() < touch_threshold['O']:
    if 1 != _status_o:_status_o = 1;on_touchpad_O_pressed()
  elif 0 != _status_o:_status_o = 0;on_touchpad_O_unpressed()
  if touchPad_N.read() < touch_threshold['N']:
    if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
  elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()

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]

brightness=9

weather_serveraddr = "http://www.tianqiapi.com"

weather_appid = "85215611"

weather_appsecret = "Kx8r5ZCY "

# 事件回调函数
def on_touchpad_P_pressed():
  global g_my_variable
  music.pitch(147, 500)
  oled.fill(0)
  oled.DispChar("上海", 0, (1-1)*16, 1)
  oled.DispChar(weather_getWeather("wea", "101020100"), 0, (2-1)*16, 1)
  oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101020100"))), 0, (3-1)*16, 1)
  oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101020100"))), 0, (4-1)*16, 1)
  oled.show()
def on_touchpad_H_pressed():
  global g_my_variable
  music.pitch(175, 500)
  oled.fill(0)
  oled.DispChar("重庆", 0, (1-1)*16, 1)
  oled.DispChar(weather_getWeather("wea", "101040100"), 0, (2-1)*16, 1)
  oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101040100"))), 0, (3-1)*16, 1)
  oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101040100"))), 0, (4-1)*16, 1)
  oled.show()
def on_touchpad_Y_pressed():
  global g_my_variable
  music.pitch(247, 500)
  oled.fill(0)
  oled.DispChar("福州", 0, (1-1)*16, 1)
  oled.DispChar((str("天气情况:") + str(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()
def on_touchpad_O_pressed():
  global g_my_variable
  music.pitch(196, 500)
  oled.fill(0)
  oled.DispChar("深圳", 0, (1-1)*16, 1)
  oled.DispChar(weather_getWeather("wea", "101280601"), 0, (2-1)*16, 1)
  oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101280601"))), 0, (3-1)*16, 1)
  oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101280601"))), 0, (4-1)*16, 1)
  oled.show()
def on_touchpad_T_pressed():
  global g_my_variable
  music.pitch(165, 500)
  oled.fill(0)
  oled.DispChar("北京", 0, (1-1)*16, 1)
  oled.DispChar(weather_getWeather("wea", "101010100"), 0, (2-1)*16, 1)
  oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101010100"))), 0, (3-1)*16, 1)
  oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101010100"))), 0, (4-1)*16, 1)
  oled.show()
def on_touchpad_N_pressed():
  global g_my_variable
  music.pitch(220, 500)
  oled.fill(0)
  oled.DispChar("济南", 0, (1-1)*16, 1)
  oled.DispChar(weather_getWeather("wea", "101120101"), 0, (2-1)*16, 1)
  oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101120101"))), 0, (3-1)*16, 1)
  oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101120101"))), 0, (4-1)*16, 1)
  oled.show()


tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)
my_wifi = wifi()
my_wifi.connectWiFi("zh","zy1567")
while not (my_wifi.sta.isconnected()):
  pass
rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
rgb.write()
music.pitch(131, 50)
ntptime.settime(8, "ntp.ntsc.ac.cn")
oled.fill(0)
oled.DispChar("触摸按键选城市", 0, (1-1)*16, 1)
oled.DispChar("P 上海   Y 福州", 0, (2-1)*16, 1)
oled.DispChar("T 北京   H 重庆", 0, (3-1)*16, 1)
oled.DispChar("O 深圳  N 济南", 0, (4-1)*16, 1)
oled.show()

Mind+ 实验图形编程

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

六位触摸按键选择城市天气预报

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板
【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板

【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3,MicroPython动手做,物联网,人工智能,单片机,嵌入式硬件,python,掌控板文章来源地址https://www.toymoban.com/news/detail-629558.html

到了这里,关于【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【雕爷学编程】MicroPython动手做(28)——物联网之Yeelight 2

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月14日
    浏览(31)
  • 【雕爷学编程】MicroPython动手做(28)——物联网之Yeelight 3

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月14日
    浏览(33)
  • 【雕爷学编程】MicroPython动手做(30)——物联网之Blynk 3

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月14日
    浏览(38)
  • 【雕爷学编程】MicroPython动手做(31)——物联网之Easy IoT

    1、物联网的诞生 美国计算机巨头微软(Microsoft)创办人、世界首富比尔盖茨,在1995年出版的《未来之路》一书中,提及“物物互联”。1998年麻省理工学院提出,当时被称作EPC系统的物联网构想。2005年11月,国际电信联盟发布《ITU互联网报告2005:物联网》,正式提出物联网时代

    2024年02月14日
    浏览(36)
  • 【雕爷学编程】MicroPython动手做(27)——物联网之掌控板小程序

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月12日
    浏览(26)
  • 【雕爷学编程】MicroPython动手做(31)——物联网之Easy IoT 2

    1、物联网的诞生 美国计算机巨头微软(Microsoft)创办人、世界首富比尔盖茨,在1995年出版的《未来之路》一书中,提及“物物互联”。1998年麻省理工学院提出,当时被称作EPC系统的物联网构想。2005年11月,国际电信联盟发布《ITU互联网报告2005:物联网》,正式提出物联网时代

    2024年02月14日
    浏览(30)
  • 【雕爷学编程】MicroPython动手做(25)——语音合成与语音识别

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月12日
    浏览(32)
  • 【雕爷学编程】MicroPython动手做(25)——语音合成与语音识别2

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月14日
    浏览(32)
  • 【雕爷学编程】MicroPython动手做(13)——掌控板之RGB三色灯2

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月15日
    浏览(36)
  • 【雕爷学编程】MicroPython动手做(13)——掌控板之RGB三色灯3

    知识点:什么是掌控板? 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器

    2024年02月15日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包