Created
June 25, 2022 16:08
-
-
Save Glukhoff/817439194477f507f3e021aa08b0e0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
import time | |
import network | |
from machine import Pin | |
class WIFI: | |
def __init__(self): | |
self.wlan = network.WLAN(network.STA_IF) | |
self.wlan.active(True) | |
self.led = Pin(2, Pin.OUT) | |
@staticmethod | |
def load_config_network(): | |
with open("setting.json", "r") as setting: | |
wifi_parameters = json.load(setting) | |
ssid = wifi_parameters["wifi"]["ssid"] | |
password = wifi_parameters["wifi"]["password"] | |
return ssid, password | |
def start_connection(self, ssid, password): | |
if not self.wlan.isconnected(): | |
self.wlan.connect(ssid, password) | |
count = 0 | |
while not self.wlan.isconnected() and count < 10: | |
count += 1 | |
self.led.off() | |
time.sleep(0.5) | |
self.led.on() | |
time.sleep(0.5) | |
if self.wlan.isconnected(): | |
print("Connection is successfully", self.wlan.ifconfig()) | |
for _ in range(3): | |
self.led.off() | |
time.sleep(0.2) | |
self.led.on() | |
time.sleep(0.2) | |
return | |
else: | |
if self.wlan.isconnected(): | |
print(self.wlan.ifconfig()) | |
else: | |
print("Connection is not successfully") | |
self.led.on() | |
return | |
if __name__ == "__main__": | |
wifi = WIFI() | |
ssid, password = wifi.load_config_network() | |
wifi.start_connection(ssid, password) | |
import webrepl | |
webrepl.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment