Created
October 26, 2022 01:55
-
-
Save neosarchizo/f5cf27cc6ceb30e2a29c9105b92a1e60 to your computer and use it in GitHub Desktop.
MicroPython - ESP32 WiFi 사용하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import SoftI2C, Pin | |
from ssd1306 import SSD1306_I2C | |
from network import WLAN, STA_IF | |
from time import sleep, time | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
led = Pin(2, Pin.OUT) | |
wlan = WLAN(STA_IF) | |
wlan.active(True) | |
start_time = time() | |
if not wlan.isconnected(): | |
print('Connecting to network...') | |
wlan.connect('devicemart', 'devicemart1') | |
while not wlan.isconnected(): | |
led.value(1) | |
sleep(0.3) | |
led.value(0) | |
sleep(0.3) | |
if time() - start_time > 15 : | |
print('WIFI Connected Timeout!') | |
break | |
if wlan.isconnected(): | |
led.value(1) | |
print('Network Information : ', wlan.ifconfig()) | |
display.fill(0) | |
display.text('IP/Subnet/GW:', 0, 0) | |
display.text(wlan.ifconfig()[0], 0, 20) | |
display.text(wlan.ifconfig()[1], 0, 38) | |
display.text(wlan.ifconfig()[2], 0, 56) | |
display.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment