Added esp32-wifi
This commit is contained in:
22
esp32-wifi/led.py
Normal file
22
esp32-wifi/led.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from machine import Pin
|
||||
import time
|
||||
|
||||
class LED:
|
||||
def __init__(self, pin_number):
|
||||
self.led = Pin(pin_number, Pin.OUT)
|
||||
|
||||
def on(self):
|
||||
self.led.value(1)
|
||||
|
||||
def off(self):
|
||||
self.led.value(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
pin = int(input("Enter pin number: "))
|
||||
led = LED(pin)
|
||||
|
||||
while True:
|
||||
led.on()
|
||||
time.sleep(0.5)
|
||||
led.off()
|
||||
time.sleep(0.5)
|
||||
17
esp32-wifi/main.py
Normal file
17
esp32-wifi/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from wifi import Wifi
|
||||
from led import LED
|
||||
|
||||
try:
|
||||
LED_PIN = 2
|
||||
SSID = "Proximus-Home-AA68_EXT"
|
||||
PASSWORD = "wcsp565un2bbw"
|
||||
|
||||
led = LED(LED_PIN)
|
||||
led.off()
|
||||
|
||||
wifi = Wifi(SSID, PASSWORD)
|
||||
wifi.connect()
|
||||
|
||||
led.on()
|
||||
except Exception as e:
|
||||
print("Unable to start", e)
|
||||
25
esp32-wifi/wifi.py
Normal file
25
esp32-wifi/wifi.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import network
|
||||
|
||||
class Wifi:
|
||||
def __init__(self, ssid, pwdk):
|
||||
self.ssid = ssid
|
||||
self.pwdk = pwdk
|
||||
self.sta_if = network.WLAN(network.STA_IF)
|
||||
|
||||
def connect(self):
|
||||
if not self.sta_if.isconnected():
|
||||
print("Connecting...")
|
||||
self.sta_if.active(True)
|
||||
self.sta_if.connect(self.ssid, self.pwdk)
|
||||
while not self.sta_if.isconnected():
|
||||
pass
|
||||
print("Network configuration:", self.sta_if.ifconfig())
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ssid = input("Enter WiFi SSID: ")
|
||||
pwdk = input("Enter WiFi password: ")
|
||||
|
||||
wifi = Wifi(ssid, pwdk)
|
||||
wifi.connect()
|
||||
Reference in New Issue
Block a user