from machine import Pin
from time import sleep
import network
import urequests
led_red = Pin(21, Pin.OUT)
led_green = Pin(17, Pin.OUT)
url = 'http://10.50.7.45:5000/verificar_nome?nome=João'
print("Conectando ao WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
sleep(0.1)
print("Conectado!")
try:
response = urequests.get(url)
while True:
if response.status_code == 200:
response_json = response.json()
if response_json['encontrado']:
led_green.on()
print('Nome encontrado!')
sleep(0.5)
else:
print('Nome não encontrado!')
led_red.off()
sleep(0.5)
except Exception as e:
print("Erro durante a requisição:", e)