4290浏览
楼主: 驴友花雕

[MP动手做] MicroPython动手做(26)——物联网之OneNET

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 07:32:47

OneNET平台上的下发命令记录

MicroPython动手做(26)——物联网之OneNET图1




回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 08:14:09

在电脑查看掌控板实时的光线值


MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 11:22:29

原来也能传送汉字


MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 11:38:11

输入数字1-255(设置字符串格式),则自动调整RGB红灯的不同亮度

MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 13:07:24


6、通过OneNET平台控制小车的进退左右

[mw_shl_code=python,false]#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[0] = (int(0), int(102), int(0))
    rgb.write()
    time.sleep_ms(1)
    Left()

_OneNET_msg_list.append('右')
def OneNET_recv_e58fb3():
    rgb[2] = (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[1] = (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)[/mw_shl_code]
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 13:16:21

mPython 实验图形编程


MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 13:28:39

mPython 实验图形编程2


MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 13:45:06

通过OneNET平台控制小车的进退左右

MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-6-2 13:50:34

MicroPython动手做(26)——物联网之OneNET图1
回复

使用道具 举报

12
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail