From df2b10acd480ca6bfdd47ec961a9b7927266b503 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Sat, 10 May 2025 05:13:57 +0300 Subject: [PATCH] Make wi-fi code more consistent between the firmware and simulation --- flix/wifi.ino | 3 ++- gazebo/wifi.h | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/flix/wifi.ino b/flix/wifi.ino index 5dad3e8..8e55388 100644 --- a/flix/wifi.ino +++ b/flix/wifi.ino @@ -12,6 +12,7 @@ #define WIFI_SSID "flix" #define WIFI_PASSWORD "flixwifi" #define WIFI_UDP_PORT 14550 +#define WIFI_UDP_REMOTE_PORT 14550 WiFiUDP udp; @@ -19,7 +20,7 @@ void setupWiFi() { print("Setup Wi-Fi\n"); WiFi.softAP(WIFI_SSID, WIFI_PASSWORD); udp.begin(WIFI_UDP_PORT); - udp.beginPacket("255.255.255.255", WIFI_UDP_PORT); // broadcast packets until connected + udp.beginPacket("255.255.255.255", WIFI_UDP_REMOTE_PORT); // broadcast packets until connected } void sendWiFi(const uint8_t *buf, int len) { diff --git a/gazebo/wifi.h b/gazebo/wifi.h index 9e6046b..ba9ce66 100644 --- a/gazebo/wifi.h +++ b/gazebo/wifi.h @@ -11,8 +11,8 @@ #include #include -#define WIFI_UDP_PORT_LOCAL 14580 -#define WIFI_UDP_PORT_REMOTE 14550 +#define WIFI_UDP_PORT 14580 +#define WIFI_UDP_REMOTE_PORT 14550 int wifiSocket; @@ -21,14 +21,14 @@ void setupWiFi() { sockaddr_in addr; // local address addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(WIFI_UDP_PORT_LOCAL); + addr.sin_port = htons(WIFI_UDP_PORT); if (bind(wifiSocket, (sockaddr *)&addr, sizeof(addr))) { - gzerr << "Failed to bind WiFi UDP socket on port " << WIFI_UDP_PORT_LOCAL << std::endl; + gzerr << "Failed to bind WiFi UDP socket on port " << WIFI_UDP_PORT << std::endl; return; } int broadcast = 1; setsockopt(wifiSocket, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)); // enable broadcast - gzmsg << "WiFi UDP socket initialized on port " << WIFI_UDP_PORT_LOCAL << " (remote port " << WIFI_UDP_PORT_REMOTE << ")" << std::endl; + gzmsg << "WiFi UDP socket initialized on port " << WIFI_UDP_PORT << " (remote port " << WIFI_UDP_REMOTE_PORT << ")" << std::endl; } void sendWiFi(const uint8_t *buf, int len) { @@ -36,7 +36,7 @@ void sendWiFi(const uint8_t *buf, int len) { sockaddr_in addr; // remote address addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_BROADCAST; // send UDP broadcast - addr.sin_port = htons(WIFI_UDP_PORT_REMOTE); + addr.sin_port = htons(WIFI_UDP_REMOTE_PORT); sendto(wifiSocket, buf, len, 0, (sockaddr *)&addr, sizeof(addr)); }