UDP not AP client should work now
This commit is contained in:
parent
64241e856e
commit
43f2b45262
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"env": {
|
"env": {
|
||||||
"myDefaultIncludePath": [
|
"myDefaultIncludePath": [
|
||||||
|
"${workspaceFolder}/src/include/",
|
||||||
"${env:PICO_SDK_PATH}/src/**/include/",
|
"${env:PICO_SDK_PATH}/src/**/include/",
|
||||||
|
"${workspaceFolder}/lib/*/src/",
|
||||||
"${env:PICO_SDK_PATH}/lib/**/include/",
|
"${env:PICO_SDK_PATH}/lib/**/include/",
|
||||||
"${workspaceFolder}/build/generated/pico_base/",
|
"${workspaceFolder}/build/generated/pico_base/"
|
||||||
"${workspaceFolder}/src/include/"
|
|
||||||
],
|
],
|
||||||
"myCompilerPath": "/usr/bin/arm-none-eabi-gcc"
|
"myCompilerPath": "/usr/bin/arm-none-eabi-gcc"
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
"udp_client.h": "c",
|
"udp_client.h": "c",
|
||||||
"udp_payload.h": "c",
|
"udp_payload.h": "c",
|
||||||
"udp.h": "c",
|
"udp.h": "c",
|
||||||
"opt.h": "c"
|
"opt.h": "c",
|
||||||
|
"cyw43_arch.h": "c",
|
||||||
|
"wifi_operator.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,8 +44,8 @@
|
||||||
#define LINK_STATS 0
|
#define LINK_STATS 0
|
||||||
// #define ETH_PAD_SIZE 2
|
// #define ETH_PAD_SIZE 2
|
||||||
#define LWIP_CHKSUM_ALGORITHM 3
|
#define LWIP_CHKSUM_ALGORITHM 3
|
||||||
#define LWIP_DHCP 1
|
#define LWIP_DHCP 0
|
||||||
#define LWIP_DHCP_SERVER 1
|
#define LWIP_DHCP_SERVER 0
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV4 1
|
||||||
#define LWIP_TCP 1
|
#define LWIP_TCP 1
|
||||||
#define LWIP_UDP 1
|
#define LWIP_UDP 1
|
||||||
|
|
|
@ -12,6 +12,13 @@ int robot_init(void)
|
||||||
{
|
{
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
|
if(cyw43_arch_init())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||||
|
|
||||||
udp_client_init();
|
udp_client_init();
|
||||||
wifi_operator_init();
|
wifi_operator_init();
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,71 @@ void wifi_operator_init(void)
|
||||||
{
|
{
|
||||||
// Mode client
|
// Mode client
|
||||||
cyw43_arch_enable_sta_mode();
|
cyw43_arch_enable_sta_mode();
|
||||||
cyw43_arch_wifi_connect_timeout_ms(WIFI_OPERATOR_SSID, WIFI_OPERATOR_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000);
|
|
||||||
puts("Connexion au réseau Wi-Fi...");
|
// Désactiver le mode d'économie d'énergie
|
||||||
int status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA);
|
cyw43_wifi_pm(&cyw43_state, CYW43_NO_POWERSAVE_MODE);
|
||||||
while (status != CYW43_LINK_UP)
|
|
||||||
|
// Afficher les paramètres de connexion
|
||||||
|
printf("Tentative de connexion à: SSID='%s'\n", WIFI_OPERATOR_SSID);
|
||||||
|
|
||||||
|
// Configuration IP
|
||||||
|
ip4_addr_t ip, netmask, gateway;
|
||||||
|
IP4_ADDR(&ip, 192, 168, 128, 2);
|
||||||
|
IP4_ADDR(&netmask, 255, 255, 255, 0);
|
||||||
|
IP4_ADDR(&gateway, 192, 168, 128, 1);
|
||||||
|
|
||||||
|
// Configuration réseau avant connexion
|
||||||
|
netif_set_up(netif_default);
|
||||||
|
netif_set_addr(netif_default, &ip, &netmask, &gateway);
|
||||||
|
|
||||||
|
puts("Configuration IP effectuée");
|
||||||
|
|
||||||
|
int connect_result = 1;
|
||||||
|
// Tentative de connexion
|
||||||
|
puts("Attente avant connexion...");
|
||||||
|
sleep_ms(2000); // Attendre 2 secondes que le WiFi soit bien initialisé
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
sleep_ms(500);
|
serialDebug("Tentative de connexion au réseau Wi-Fi...");
|
||||||
puts("Connexion en cours...");
|
connect_result = cyw43_arch_wifi_connect_timeout_ms(ssid, password, CYW43_AUTH_WPA2_AES_PSK, 10000);
|
||||||
status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA);
|
|
||||||
|
if(connect_result != 0)
|
||||||
|
{
|
||||||
|
char error_message[100];
|
||||||
|
snprintf(error_message, sizeof(error_message), "Échec de la connexion WiFi - Code d'erreur: %d", connect_result);
|
||||||
|
serialDebug(error_message);
|
||||||
|
|
||||||
|
const char *error_description;
|
||||||
|
switch (connect_result)
|
||||||
|
{
|
||||||
|
case -1:
|
||||||
|
error_description = "Erreur générale";
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
error_description = "Point d'accès non trouvé";
|
||||||
|
break;
|
||||||
|
case -3:
|
||||||
|
error_description = "Mot de passe incorrect";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error_description = "Erreur inconnue";
|
||||||
|
}
|
||||||
|
puts(error_description);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
puts("Connexion établie!");
|
while(connect_result);
|
||||||
|
|
||||||
|
// Configuration de l'interface réseau
|
||||||
|
if(!netif_default)
|
||||||
|
{
|
||||||
|
puts("Erreur: Interface réseau non disponible");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
netif_set_up(netif_default);
|
||||||
|
netif_set_link_up(netif_default);
|
||||||
|
netif_set_addr(netif_default, &ip, &netmask, &gateway);
|
||||||
|
|
||||||
|
puts("Connexion établie avec succès!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue