8749| 35
|
[MP动手做] MicroPython动手做(31)——物联网之Easy IoT |
1、物联网的诞生 美国计算机巨头微软(Microsoft)创办人、世界首富比尔盖茨,在1995年出版的《未来之路》一书中,提及“物物互联”。1998年麻省理工学院提出,当时被称作EPC系统的物联网构想。2005年11月,国际电信联盟发布《ITU互联网报告2005:物联网》,正式提出物联网时代来临。 物联网(IoT)一词是由Kevin Ashton 于1999年在Proctor&Gamble的一次演讲中创造的 。他是麻省理工学院Auto-ID实验室的联合创始人。他率先将RFID(用于条形码检测器)用于供应链管理领域。他还创立了Zensi,一家生产能量传感和监测技术的公司。 所以,让我首先向您介绍Kevin Ashton的一句话,他在2009年为RFID期刊撰写了这篇文章。这将有助于您从核心理解物联网。 如果我们拥有能够了解所有事情的计算机 - 使用他们在没有我们任何帮助的情况下收集的数据 - 我们将能够跟踪和计算所有内容,并大大减少浪费,损失和成本。我们知道什么时候需要更换,修理或召回,以及它们是新鲜的还是过去的。 我们需要用他们自己的收集信息的方式赋予计算机权力,这样他们就可以随意地看到,听到和闻到这个世界。 上面凯Kevin的应用会让你了解物联网发展背后的意识形态。现在让我们尝试进一步简化这个术语,从根本上理解物联网。在此之后,我们将继续前进,并寻求物联网的好处。 |
#MicroPython动手做(31)——物联网之Easy IoT #使用移动端EasyIoT小程序控制RGB灯 [mw_shl_code=python,false]#MicroPython动手做(31)——物联网之Easy IoT #使用移动端EasyIoT小程序控制RGB灯 from mpython import * import network from umqtt.simple import MQTTClient import time import music from machine import Timer import ubinascii my_wifi = wifi() my_wifi.connectWiFi("zh", "zy1567") mqtt = MQTTClient("0805e3d04f3b34e7", "182.254.130.180", 1883, "qlZ0uezGR", "3_W0uezGgz", keepalive=30) try: mqtt.connect() print('Connected') except: print('Disconnected') mqtt.set_last_will("TvkJXezMR", "Ready!") def mqtt_topic_54766b4a58657a4d52(_msg): oled.DispChar((str(_msg)), 55, 24, 1) oled.show() if "on" == _msg: music.play('D5:1') rgb.fill((int(255), int(0), int(0))) rgb.write() time.sleep_ms(1) oled.DispChar("开灯", 52, 36, 1) oled.show() elif "off" == _msg: music.play('F5:1') rgb.fill( (0, 0, 0) ) rgb.write() time.sleep_ms(1) oled.DispChar("关灯", 52, 36, 1) oled.show() def mqtt_callback(topic, msg): try: topic = topic.decode('utf-8', 'ignore') _msg = msg.decode('utf-8', 'ignore') eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")') except: print((topic, msg)) mqtt.set_callback(mqtt_callback) mqtt.subscribe("TvkJXezMR") def timer14_tick(_): mqtt.ping() tim14 = Timer(14) tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick) oled.invert(0) oled.DispChar("移动版EasyIoT小程序", 5, 10, 1) oled.show() rgb[1] = (int(0), int(102), int(0)) rgb.write() time.sleep_ms(1) music.play('G5:1') while True: mqtt.wait_msg()[/mw_shl_code] |
10、输入数字远距离画空心园 [mw_shl_code=python,false]#MicroPython动手做(31)——物联网之Easy IoT #输入数字远距离画空心园 from mpython import * import network from umqtt.simple import MQTTClient import music import time from machine import Timer import ubinascii my_wifi = wifi() my_wifi.connectWiFi("zh", "zy1567") mqtt = MQTTClient("664fa81baa7fe777", "182.254.130.180", 1883, "qlZ0uezGR", "3_W0uezGgz", keepalive=30) mqtt.set_last_will("ZlB0tWZMg", "Hello, world!") try: mqtt.connect() print('Connected') except: print('Disconnected') def mqtt_topic_5a6c423074575a4d67(_msg): if int(_msg) < 32: rgb.fill((int(0), int(0), int(153))) rgb.write() time.sleep_ms(1) music.play('E5:1') oled.fill(0) oled.circle(64, 32, (int(_msg)), 1) oled.show() else: rgb.fill((int(102), int(0), int(0))) rgb.write() time.sleep_ms(1) oled.fill(0) oled.DispChar("请输入正整数", 30, 12, 1) oled.DispChar("数值应小于32", 30, 24, 1) oled.show() def mqtt_callback(topic, msg): try: topic = topic.decode('utf-8', 'ignore') _msg = msg.decode('utf-8', 'ignore') eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")') except: print((topic, msg)) mqtt.set_callback(mqtt_callback) mqtt.subscribe("ZlB0tWZMg") def timer14_tick(_): mqtt.ping() tim14 = Timer(14) tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick) music.play('D5:1') rgb[1] = (int(0), int(102), int(0)) rgb.write() time.sleep_ms(1) oled.invert(0) oled.DispChar("远距画空心圆", 30, 12, 1) oled.show() while True: mqtt.wait_msg()[/mw_shl_code] |
9、通过Easy IoT平台远距控制开关RGB灯 [mw_shl_code=python,false]#MicroPython动手做(31)——物联网之Easy IoT #通过Easy IoT平台远距控制开关RGB灯 from mpython import * import network my_wifi = wifi() my_wifi.connectWiFi('zh', 'zy1567') from umqtt.simple import MQTTClient mqtt = MQTTClient('0805e3d04f3b34e7', '182.254.130.180', 1883, 'qlZ0uezGR', '3_W0uezGgz', keepalive=30) try: mqtt.connect() print('Connected') except: print('Disconnected') mqtt.set_last_will('TvkJXezMR', 'Ready!') import time import music from machine import Timer import ubinascii def mqtt_topic_54766b4a58657a4d52(_msg): oled.DispChar((str(_msg)), 55, 24, 1) oled.show() if 'on' == _msg: music.play('D5:1') rgb.fill((int(255), int(0), int(0))) rgb.write() time.sleep_ms(1) oled.DispChar('开灯', 52, 36, 1) oled.show() elif 'off' == _msg: music.play('F5:1') rgb.fill( (0, 0, 0) ) rgb.write() time.sleep_ms(1) oled.DispChar('关灯', 52, 36, 1) oled.show() def mqtt_callback(topic, msg): try: topic = topic.decode('utf-8', 'ignore') _msg = msg.decode('utf-8', 'ignore') eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")') except: print((topic, msg)) mqtt.set_callback(mqtt_callback) mqtt.subscribe("TvkJXezMR") def timer14_tick(_): mqtt.ping() tim14 = Timer(14) tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick) oled.invert(0) oled.DispChar('Hello, world!', 24, 10, 1) oled.show() rgb[1] = (int(0), int(102), int(0)) rgb.write() time.sleep_ms(1) music.play('G5:1') while True: mqtt.wait_msg()[/mw_shl_code] |
2、什么是物联网? 大家在听到物联网时,脑海中会出现一个什么样的印象呢?物联网的英语是Internet of Things,缩写为IoT,这里的“物”指的是我们身边一切能与网络相连的物品。例如您身上穿着的衣服、戴着的 手表、家里的家用电器和汽车,或者是房屋本身,甚至正在读的这本书,只要能与网络相连,就都是物联网说的“物”。 物联网(Internet of Things,缩写IoT)是一个基于互联网、传统电信网等信息承载体,让所有能够被寻找网络联机的对象,实现互联互通的网络。就像我们用互联网在彼此之间传递信息一样,物联网就是“物”之间通过连接互联网来共享信息并产生有用的信息,而且无需人为管理就 能运行的机制。他们可以互相感知和沟通。现在想象一下,无生命的物体是否可以在没有任何人为干预的情况下感知并相互作用。听起来很神奇不是吗? |
4、Easy IoT是什么 Easy IoT是一个国际化物联网服务平台 https://iot.dfrobot.com.cn/,可以对联网的传感器/执行器数据进行实时监控和反馈,统计和分析已经接收的数据,并向传感器/执行器发送数据,帮助实现控制效果。 为什么用Easy IoT ——Easy IoT PC端和移动端 上手简单,即看即用 有pc端和移动端,国内国外随时随地使用 兼容多种硬件 支持HTTP或MQTT通信 提供配套硬件(Obloq)、库文件和示例程序 完善的使用示例文档 帮助入门者迅速开始一个物联网项目的实践 |
8、测试Easy IoT平台发送消息 [mw_shl_code=python,false]#MicroPython动手做(31)——物联网之Easy IoT #测试Easy IoT平台发送消息 from mpython import * import network from umqtt.simple import MQTTClient import music import time from machine import Timer import ubinascii my_wifi = wifi() my_wifi.connectWiFi("zh", "zy1567") mqtt = MQTTClient("664fa81baa7fe777", "182.254.130.180", 1883, "qlZ0uezGR", "3_W0uezGgz", keepalive=30) mqtt.set_last_will("TvkJXezMR", "I am offline") try: mqtt.connect() print('Connected') except: print('Disconnected') def mqtt_topic_54766b4a58657a4d52(_msg): rgb[1] = (int(102), int(0), int(0)) rgb.write() time.sleep_ms(1) oled.invert(0) oled.DispChar((str(_msg)), 0, 0, 1) oled.show() def mqtt_topic_5a6c423074575a4d67(_msg): rgb[2] = (int(51), int(51), int(255)) rgb.write() time.sleep_ms(1) oled.fill_rect(0, 16, 128, 16, 0) oled.DispChar((str(_msg)), 0, 16, 1) oled.show() def mqtt_callback(topic, msg): try: topic = topic.decode('utf-8', 'ignore') _msg = msg.decode('utf-8', 'ignore') eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")') except: print((topic, msg)) mqtt.set_callback(mqtt_callback) mqtt.subscribe("TvkJXezMR") def timer14_tick(_): mqtt.ping() tim14 = Timer(14) tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick) mqtt.subscribe("ZlB0tWZMg") music.play('D5:1') rgb[0] = (int(0), int(102), int(0)) rgb.write() time.sleep_ms(1) mqtt.publish("TvkJXezMR", "hello") mqtt.publish("ZlB0tWZMg", "world") while True: mqtt.wait_msg()[/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed