1
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

Organization

ESP32をWifiに接続する方法

Wifi繋げてしまう(簡単!)

ESP32をWifiに接続する方法を以下に記します
bowling_alley.png

SSID_NAME = "SSID"
SSID_PASS = "PASS"

import utime
import network

def connect_wifi(ssid, passkey, timeout=10):
    wifi= network.WLAN(network.STA_IF)
    if wifi.isconnected() :
        print('already Connected.    connect skip')
        return wifi
    else :
        wifi.active(True)
        wifi.connect(ssid, passkey)
        while not wifi.isconnected() and timeout > 0:
            print('.')
            utime.sleep(1)
            timeout -= 1

    if wifi.isconnected():
        print('Connected')
        return wifi
    else:
        print('Connection failed!')
        return null

wifi = connect_wifi(SSID_NAME, SSID_PASS)
if not wifi :
    sys.exit(0)

変数SSID_NAMEにはSSID名を,変数SSID_PASSにはSSIDのパスワードを入れてください

最後にConnectedと表示されれば接続完了です

本当はパスワードなどはソースコード上に入れるべきではないのだと承知していますが,今回はWifiに接続できればいいのでご容赦ください(__)

起動時に自動的にWifiにつなげたい!

上記のプログラムをboot.pyに入れてあげればOK👍

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
1
Help us understand the problem. What are the problem?