Starting to add suport for server and AP mode

This commit is contained in:
Ulysse Cura 2026-02-01 18:22:24 +01:00
parent 8f0373cba7
commit abc92dfe4d
1 changed files with 39 additions and 0 deletions

View File

@ -5,9 +5,28 @@
#include <lwip/udp.h>
#include <time.h>
#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();
}