<p> </p>
<p>掌控板上显示电脑上发送的命令(字符串),并点亮红色灯;当发送“open”命令时,掌控板传送“光线值”的数据流到电脑,并点亮蓝色灯,发送“close”,蓝灯熄灭。</p>
<p> </p>
<pre>
<code>#MicroPython动手做(26)——物联网之OneNET
#在电脑查看掌控板实时的光线值
from mpython import *
import network
from umqtt.simple import MQTTClient
from machine import Timer
import machine
import ubinascii
import time
import json
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
def OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):
global _OneNET_msg_list
try: _msg = _msg.decode('utf-8', 'ignore')
except: print(_msg);return
OneNET_recv(_msg)
if _msg in _OneNET_msg_list:
eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')
tim14 = Timer(14)
_iot_count = 0
def timer14_tick(_):
global _iot, _iot_count
_iot_count = _iot_count + 1
if _iot_count == 1000: _iot.ping(); _iot_count = 0
try: _iot.check_msg()
except: machine.reset()
_iot = None
def OneNET_setup():
global _iot
_iot = MQTTClient("600844609", "183.230.40.39", 6002, "350265", "l6S0BsjGXsQACV3hBhml7=3hgCo=", keepalive=300)
_iot.set_callback(OneNET_callback)
if 1 == _iot.connect(): print('Successfully connected to MQTT server.')
tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)
def pubdata(_dic):
print(_dic)
_list = []
for _key in list(_dic.keys()):
_d = {'id':_key,'datapoints':[{'value':_dic}]}
_list.append(_d)
_data = {'datastreams': _list}
j_d = json.dumps(_data)
j_l = len(j_d)
arr = bytearray(j_l + 3)
arr = 1
arr = int(j_l / 256)
arr = j_l % 256
arr = j_d.encode('ascii')
return arr
def OneNET_recv(_msg):
oled.fill(0)
oled.DispChar(_msg, 0, 0, 1)
oled.show()
if _msg.isdigit():
rgb.fill( (int((int(_msg))), int(0), int(0)) )
rgb.write()
time.sleep_ms(1)
_OneNET_msg_list.append('open')
def OneNET_recv_6f70656e():
rgb.fill((int(0), int(0), int(153)))
rgb.write()
time.sleep_ms(1)
_OneNET_msg_list.append('close')
def OneNET_recv_636c6f7365():
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
OneNET_setup()
while True:
_iot.publish('$dp', pubdata({"light":light.read()}))
time.sleep(3)</code></pre>
<p> </p>
<p>mPython X 实验图形编程</p>
<p> </p>
<p></p>
<p>在电脑查看掌控板实时的光线值</p>
<p> </p>
<p></p>
<p></p>
<p>在电脑查看掌控板实时的光线值</p>
<p> </p>
<p></p>
<p>OneNET平台上的下发命令记录</p>
<p> </p>
<p></p>
<p>原来也能传送汉字</p>
<p> </p>
<p></p>
<p>输入数字1-255(设置字符串格式),则自动调整RGB红灯的不同亮度</p>
<p> </p>
<p></p>
<p><b>6、通过OneNET平台控制小车的进退左右</b></p>
<p> </p>
<pre>
<code>#MicroPython动手做(26)——物联网之OneNET
#通过OneNET平台控制小车的进退左右
from mpython import *
import network
my_wifi = wifi()
my_wifi.connectWiFi('zh', 'zy1567')
import music
import time
from umqtt.simple import MQTTClient
from machine import Timer
import machine
import ubinascii
def OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):
global _OneNET_msg_list
try: _msg = _msg.decode('utf-8', 'ignore')
except: print(_msg);return
OneNET_recv(_msg)
if _msg in _OneNET_msg_list:
eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')
tim14 = Timer(14)
_iot_count = 0
def timer14_tick(_):
global _iot, _iot_count
_iot_count = _iot_count + 1
if _iot_count == 1000: _iot.ping(); _iot_count = 0
try: _iot.check_msg()
except: machine.reset()
_iot = None
def OneNET_setup():
global _iot
_iot = MQTTClient('600999469', '183.230.40.39', 6002, '350265', 'l6S0BsjGXsQACV3hBhml7=3pwCo=', keepalive=300)
_iot.set_callback(OneNET_callback)
if 1 == _iot.connect(): print('Successfully connected to MQTT server.')
tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)
import parrot
def forward():
parrot.set_speed(parrot.MOTOR_1, 80)
parrot.set_speed(parrot.MOTOR_2, 80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Forward.pbm', 0), 32, 0)
oled.show()
def retreat():
parrot.set_speed(parrot.MOTOR_1, -80)
parrot.set_speed(parrot.MOTOR_2, -80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Backward.pbm', 0), 32, 0)
oled.show()
def right():
parrot.set_speed(parrot.MOTOR_1, 80)
parrot.set_speed(parrot.MOTOR_2, -0)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Right.pbm', 0), 32, 0)
oled.show()
def Left():
parrot.set_speed(parrot.MOTOR_1, -0)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Left.pbm', 0), 32, 0)
oled.show()
_OneNET_msg_list.append('进')
def OneNET_recv_e8bf9b():
rgb.fill((int(0), int(102), int(0)))
rgb.write()
time.sleep_ms(1)
forward()
_OneNET_msg_list.append('退')
def OneNET_recv_e98080():
rgb.fill((int(51), int(102), int(255)))
rgb.write()
time.sleep_ms(1)
retreat()
_OneNET_msg_list.append('左')
def OneNET_recv_e5b7a6():
rgb = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
Left()
_OneNET_msg_list.append('右')
def OneNET_recv_e58fb3():
rgb = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
right()
image_picture = Image()
oled.fill(0)
oled.DispChar(' 请准备好物联网控制', 0, 16, 1)
oled.show()
music.play('G5:1')
rgb = (int(255), int(0), int(0))
rgb.write()
time.sleep_ms(1)
OneNET_setup()
while True:
oled.fill(0)
parrot.set_speed(parrot.MOTOR_1, 0)
parrot.set_speed(parrot.MOTOR_2, 0)
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
oled.show()
time.sleep(2)</code></pre>
<p> </p>
<p>mPython 实验图形编程</p>
<p> </p>
<p></p>
<p>mPython 实验图形编程2</p>
<p> </p>
<p></p>
<p>通过OneNET平台控制小车的进退左右</p>
<p> </p>
<p></p>
<p></p>
本帖最后由 eagler8 于 2020-6-5 12:45 编辑
<p><strong>目录清单</strong><br />
MicroPython动手做(01)——春节后入手了一块K210芯片AI开发板 <br />
<a href="https://bbs.eeworld.com.cn/thread-1115786-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1115786-1-1.html</a></p>
<p>MicroPython动手做(02)——尝试搭建K210开发板的IDE环境<br />
<a href="https://bbs.eeworld.com.cn/thread-1115831-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1115831-1-1.html</a></p>
<p>MicroPython动手做(03)——零基础学MaixPy之开机运行<br />
<a href="https://bbs.eeworld.com.cn/thread-1116184-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116184-1-1.html</a></p>
<p>MicroPython动手做(04)——零基础学MaixPy之基本示例<br />
<a href="https://bbs.eeworld.com.cn/thread-1116438-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116438-1-1.html</a></p>
<p>MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏<br />
<a href="https://bbs.eeworld.com.cn/thread-1116577-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116577-1-1.html</a></p>
<p>MicroPython动手做(06)——零基础学MaixPy之单目摄像头<br />
<a href="https://bbs.eeworld.com.cn/thread-1116591-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116591-1-1.html</a></p>
<p>MicroPython动手做(07)——零基础学MaixPy之机器视觉<br />
<a href="https://bbs.eeworld.com.cn/thread-1116617-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116617-1-1.html</a></p>
<p>MicroPython动手做(08)——零基础学MaixPy之识别颜色 <br />
<a href="https://bbs.eeworld.com.cn/thread-1116662-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116662-1-1.html</a></p>
<p>MicroPython动手做(09)——零基础学MaixPy之人脸识别<br />
<a href="https://bbs.eeworld.com.cn/thread-1116720-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116720-1-1.html</a></p>
<p>MicroPython动手做(10)——零基础学MaixPy之神经网络KPU<br />
<a href="https://bbs.eeworld.com.cn/thread-1116925-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1116925-1-1.html</a></p>
<p>MicroPython动手做(11)——搭建掌控板IDE环境<br />
<a href="https://bbs.eeworld.com.cn/thread-1117964-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1117964-1-1.html</a></p>
<p>MicroPython动手做(12)——掌控板之Hello World<br />
<a href="https://bbs.eeworld.com.cn/thread-1118180-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1118180-1-1.html</a></p>
<p>MicroPython动手做(13)——掌控板之RGB三色灯 <br />
<a href="https://bbs.eeworld.com.cn/thread-1118275-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1118275-1-1.html</a></p>
<p>MicroPython动手做(14)——掌控板之OLED屏幕<br />
<a href="https://bbs.eeworld.com.cn/thread-1118389-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1118389-1-1.html</a></p>
<p>MicroPython动手做(15)——掌控板之AB按键<br />
<a href="https://bbs.eeworld.com.cn/thread-1118496-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1118496-1-1.html</a></p>
<p>MicroPython动手做(16)——掌控板之图片图像显示<br />
<a href="https://bbs.eeworld.com.cn/thread-1118945-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1118945-1-1.html</a></p>
<p>MicroPython动手做(17)——掌控板之触摸引脚<br />
<a href="https://bbs.eeworld.com.cn/thread-1119462-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1119462-1-1.html</a></p>
<p>MicroPython动手做(18)——掌控板之声光传感器<br />
<a href="https://bbs.eeworld.com.cn/thread-1119583-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1119583-1-1.html</a></p>
<p>MicroPython动手做(19)——掌控板之蜂鸣器与音乐<br />
<a href="https://bbs.eeworld.com.cn/thread-1119668-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1119668-1-1.html</a></p>
<p>MicroPython动手做(20)——掌控板之三轴加速度<br />
<a href="https://bbs.eeworld.com.cn/thread-1119998-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1119998-1-1.html</a></p>
<p>MicroPython动手做(21)——掌控板之磁场传感器<br />
<a href="https://bbs.eeworld.com.cn/thread-1120188-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1120188-1-1.html</a></p>
<p>MicroPython动手做(22)——掌控板之无线广播<br />
<a href="https://bbs.eeworld.com.cn/thread-1120835-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1120835-1-1.html</a></p>
<p>MicroPython动手做(23)——掌控板之WiFi与蓝牙<br />
<a href="https://bbs.eeworld.com.cn/thread-1120934-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1120934-1-1.html</a></p>
<p>MicroPython动手做(24)——掌控板之拓展掌控宝 <br />
<a href="https://bbs.eeworld.com.cn/thread-1121208-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1121208-1-1.html</a></p>
<p>MicroPython动手做(25)——语音合成与语音识别<br />
<a href="https://bbs.eeworld.com.cn/thread-1123752-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1123752-1-1.html</a></p>
<p>MicroPython动手做(26)——物联网之OneNET<br />
<a href="https://bbs.eeworld.com.cn/thread-1125172-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1125172-1-1.html</a></p>
<p>MicroPython动手做(27)——物联网之微信小程序<br />
<a href="https://bbs.eeworld.com.cn/thread-1125520-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1125520-1-1.html</a></p>
<p>MicroPython动手做(28)——物联网之Yeelight<br />
<a href="https://bbs.eeworld.com.cn/thread-1125939-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1125939-1-1.html</a></p>
<p>MicroPython动手做(29)——物联网之SIoT<br />
<a href="https://bbs.eeworld.com.cn/thread-1126090-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1126090-1-1.html</a></p>
<p>看着好高级,中国移动的开放平台吗</p>
hotsauce1861 发表于 2020-6-3 08:16
看着好高级,中国移动的开放平台吗
<p><img height="50" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/onion/Onion--2.gif" width="50" /> 中移动的开放平台,也是第一次接触,感觉还行</p>
页:
1
[2]