#include <stdio.h>
#include "pico/stdlib.h"
#include "wifi_handler.h"
#include "http_client.h"
#include "hardware/gpio.h"
static bool http_requested = false; // Garante que a requisição seja feita apenas uma vez
int main() {
stdio_init_all();
leds_init();
// Conecta ao WiFi
if (wifi_connect() != 0) {
printf("Falha na conexão WiFi. Abortando.\n");
return -1;
}
// Envia a requisição HTTP uma vez
if (!http_requested) {
printf("Fazendo requisição HTTP...\n");
http_client();
http_requested = true;
}
// Loop infinito (aguardando a conclusão da requisição)
/*while (true) {
sleep_ms(100);
}*/
while (true) {
// Simula o recebimento de um comando externo (substitua isso pela lógica real do servidor HTTP)
char command[12];
printf("Digite 'color_on' ou 'color_off', exemplo: 'red_on' ");
scanf("%s", command);
if (strcmp(command, "green_on") == 0) {
led_green_on();
} else if (strcmp(command, "green_off") == 0) {
led_green_off();
} else if (strcmp(command, "yellow_on") == 0) {
led_yellow_on();
} else if (strcmp(command, "yellow_off") == 0) {
led_yellow_off();
} else if (strcmp(command, "red_on") == 0) {
led_red_on();
} else if (strcmp(command, "red_off") == 0) {
led_red_off();
}
sleep_ms(100);
}
return 0;
}