diff --git a/src/main.c b/src/main.c index c2d9bd7..dee34ed 100644 --- a/src/main.c +++ b/src/main.c @@ -5,9 +5,28 @@ #include #include +#define CLIENT +//#define SERVER +#define STA_MODE +//#define AP_MODE + +#ifdef STA_MODE + #define SSID "thinkpad-T440p" #define PASSWORD "CDuKaka2000!" +#endif // STA_MODE + +#ifdef AP_MODE + +#define AP_SSID "PicoAP" +#define AP_PASSWORD "PicoPassword!" +#define AP_CHANNEL 3 + +#endif // AP_MODE + +#ifdef CLIENT + #define CLIENT_PORT 4243 static void udp_recv_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) @@ -21,6 +40,8 @@ static void udp_recv_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, co pbuf_free(p); } +#endif // CLIENT + int main() { stdio_init_all(); @@ -43,6 +64,7 @@ int main() puts("CYW43 arch initialized"); +#ifdef STA_MODE cyw43_arch_enable_sta_mode(); @@ -77,6 +99,20 @@ int main() puts("WiFi connected"); +#endif // STA_MODE + +#ifdef AP_MODE + + cyw43_arch_enable_ap_mode(AP_SSID, AP_PASSWORD, CYW43_AUTH_WPA2_AES_PSK); + + cyw43_wifi_ap_set_channel(&cyw43_state, AP_CHANNEL); + + puts("AP mode enabled"); + +#endif //AP_MODE + +#ifdef CLIENT + struct udp_pcb *pcb = udp_new(); if(!pcb) @@ -93,12 +129,14 @@ int main() return -1; } +#endif // CLIENT // ========================== Main loop ========================== while(true) { cyw43_arch_poll(); +#ifdef STA_MODE int ret = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); if(ret != CYW43_LINK_JOIN) { @@ -127,6 +165,7 @@ int main() } puts(status_message); } +#endif // STA_MODE tight_loop_contents(); }