pico-bmc/main.c

51 lines
1.2 KiB
C
Raw Normal View History

#define TCP_PORT 80
#define DEBUG_printf printf
#include "pico_lib.h"
#include "bmc_handler.h"
#include "http_serv.h"
2024-02-14 02:01:59 +00:00
#include "secret.h"
void set_host_name(const char * hostname) {
2024-04-25 22:47:44 +00:00
cyw43_arch_lwip_begin();
struct netif *n = &cyw43_state.netif[CYW43_ITF_STA];
netif_set_hostname(n, hostname);
netif_set_up(n);
cyw43_arch_lwip_end();
}
2024-02-14 02:01:59 +00:00
int main() {
2024-03-05 05:07:18 +00:00
stdio_init_all();
2024-02-14 02:01:59 +00:00
2024-03-05 05:07:18 +00:00
if (cyw43_arch_init()) {
DEBUG_printf("[INIT] [ERR] Failed to initialise cyw43\n");
return 1;
}
2024-02-14 02:01:59 +00:00
cyw43_arch_enable_sta_mode();
set_host_name(BMC_HOSTNAME);
DEBUG_printf("[INIT] [OK ] Set hostname to %s\n", BMC_HOSTNAME);
2024-02-14 02:01:59 +00:00
2024-03-05 05:07:18 +00:00
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASS, CYW43_AUTH_WPA2_AES_PSK, 30000)){
DEBUG_printf("[INIT] [ERR] Wi-Fi failed to connect\n");
2024-02-14 02:01:59 +00:00
return -1;
}
DEBUG_printf("[INIT] [OK ] Wi-Fi connected successfully\n");
2024-02-14 02:01:59 +00:00
http_serv_init();
2024-02-14 02:01:59 +00:00
2024-02-16 22:45:10 +00:00
// init bmc handler
bmc_handler_init();
2024-02-16 22:45:10 +00:00
// set LED to on to indicate it has connected and initialized
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
2024-03-05 05:07:18 +00:00
while (!http_serv_state->complete) {
2024-02-29 22:21:31 +00:00
sleep_ms(1000);
}
2024-02-29 22:21:31 +00:00
bmc_handler_deinit();
http_serv_deinit();
2024-03-05 05:07:18 +00:00
cyw43_arch_deinit();
return 0;
2024-02-14 02:01:59 +00:00
}