回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

DFRobot Beetle ESP32-C3 开箱 刷Micropython固件 点灯 连WiFi 简单

头像 米菲爸爸 2023.05.17 86 6

官方文档

Beetle ESP32-C3(RISC-V芯片)-Beetle微型控制器

https://www.dfrobot.com.cn/goods-3494.html

DFROBOT DFR0868 Beetle ESP32 C3 产品资料 使用教程

https://wiki.dfrobot.com.cn/_SKU_DFR0868_Beetle_ESP32_C3#target_15

固件下载地址

MicroPython - Python for microcontrollers

https://micropython.org/download/esp32c3-usb/

代码
import network
import ujson
import urequests
import utime

# 读取本地配置文件
with open('config.txt') as f:
  config = ujson.load(f)

# 连接WiFi
wlan = network.WLAN(network.STA_IF)
if not wlan.isconnected():
    wlan.active(False)
    wlan.active(True)
    wlan.scan()
    wlan.disconnect()  # 断开之前的连接

    wlan.connect(config['wifi_ssid'], config['wifi_password'])

'''
等待WiFi连接成功
STAT_IDLE 			– 1000 无连接,无活动,
STAT_CONNECTING 	– 1001 正在进行连接,
STAT_WRONG_PASSWORD – 202  由于密码错误而失败,
STAT_NO_AP_FOUND 	– 201  失败,因为没有接入点回复,
STAT_CONNECT_FAIL 	– 由于其他问题而失败,
STAT_GOT_IP 		– 1010连接成功。
'''
while not wlan.isconnected():
  utime.sleep(1)
  if wlan.status() == network.STAT_CONNECTING:
    print('Connecting to WiFi...')
  elif wlan.status() == network.STAT_WRONG_PASSWORD:
    print('WiFi password is incorrect')
    break
  elif wlan.status() == network.STAT_NO_AP_FOUND:
    print('WiFi network is not found')
    break

# 如果WiFi连接成功,则监控 foo.com
if wlan.isconnected():
  while True:
    try:
      response = urequests.get('https://www.bilibili.com')
      if response.status_code == 200:
        print('foo.com is running normally')
      else:
        print('foo.com is not running normally')
      response.close()
    except:
      print('Could not connect to foo.com')
    utime.sleep(60)

评论

user-avatar
  • 花生编程

    花生编程2023.07.18

    赞赞赞赞

    0
    • 花生编程

      花生编程2023.07.18

      厉害厉害

      0
      • 三春牛-创客

        三春牛-创客2023.07.15

        厉害

        0
        • 三春牛-创客

          三春牛-创客2023.07.15

          不错

          0
          • 鳄鱼

            鳄鱼2023.05.22

            帮到我了,谢谢

            0
            • hacker_

              hacker_2023.05.19

              666

              0