from machine import Pin, I2C
from neopixel import NeoPixel
from ssd1306 import SSD1306_I2C
from rede import Rede

i2c = I2C(0)

oled = SSD1306_I2C(128, 64, i2c)

oled.text('Teste de rede', 10, 10)      
oled.show()

np = NeoPixel(Pin(17, Pin.OUT), 1)

def indica (arg):
    global np
    np[0] = arg
    np.write()

def indica2 (arg):
    global oled
    oled.fill(0)
    oled.text(arg, 10, 10)      
    oled.show()

indica((255,0,0))
indica2(arg='Inicio')

net = Rede('Wokwi-GUEST','', cb=indica2)

indica((255,128,0))
indica2(arg='Desconectando')

net.desconectar()

indica((255,255,0))
indica2(arg='Conectando')

if not net.conectado:
    # A linha 40 é específica para o wokwi. Verificar se necessário na prática
    net.configurar('192.168.0.204', '255.255.255.0', '192.168.0.1', '8.8.8.8')
    net.conectar()
  
if net.conectado:
    indica((0,0,255))
else:
    indica((255,0,0))