Пример #1
0
from boot import do_connect
if (do_connect()):
    import page
else:
    print("Not Connected")
Пример #2
0
    client = MQTTClient(client_id, MQTT_SERVER)
    client.set_callback(sub_cb)
    client.connect()
    client.subscribe('servo')

    print('Connected to MQTT')
    client.publish('esp32', 'connected!')

    return client


try:
    client = connect_and_subscribe()
except OSError as e:
    print('Failed to connect to MQTT broker. Reconnecting...')
    time.sleep(10)
    machine.reset()


while True:
    if not wlan.isconnected():
        do_connect()

    client.check_msg()

    if servo_state != servo_on:
        print('Servo toggle')
        servo.duty(115 if servo_state else 40)
        servo_state = servo_on
        time.sleep(1)
Пример #3
0
                    speed_r = 300
                elif key4.value() == Key.GND:
                    speed_l = 300
                    speed_r = -300
                else:
                    if key5.value() == Key.VDD:
                        speed_l = 500
                        speed_r = 500
                    elif key5.value() == Key.GND:
                        speed_l = -500
                        speed_r = -500

                uc.send(('control_cmd:speed_l=' + str(speed_l) + ':speed_r=' +
                         str(speed_r)).encode())
                time.sleep_ms(90)
    else:
        print('main.py : ESP32 & ESP8266')
        ap = network.WLAN(network.AP_IF)  # create access-point interface
        ap.config(essid='ROBOT', password='******')
        ap.active(True)  # activate the interface

        # 如果连接到局域网,设置固定IP xx:xx:xx:13
        sta = network.WLAN(network.STA_IF)
        ifconfig = sta.ifconfig()
        if ifconfig[0] != '0.0.0.0':
            new_ip = ifconfig[3][:-1] + '13'
            new_ifc = (new_ip, ifconfig[1], ifconfig[2], ifconfig[3])
            boot.do_connect(ifconfig=new_ifc, reconnection=True)

        car.run()