2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ESP32をWifiに接続する方法

Last updated at Posted at 2020-07-23

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👍

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?