From 10fafbc4a06e10323b13993a39972a7e361bab69 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Wed, 27 Aug 2025 05:01:07 +0300 Subject: [PATCH] Send udp packets in unicast after connection is established This makes qgc connection faster. Add WIFI_UDP_REMOTE_ADDR macro for default remote address for both the firmware and simulation. --- flix/wifi.ino | 3 ++- gazebo/wifi.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flix/wifi.ino b/flix/wifi.ino index e0d2957..e003375 100644 --- a/flix/wifi.ino +++ b/flix/wifi.ino @@ -13,6 +13,7 @@ #define WIFI_PASSWORD "flixwifi" #define WIFI_UDP_PORT 14550 #define WIFI_UDP_REMOTE_PORT 14550 +#define WIFI_UDP_REMOTE_ADDR "255.255.255.255" WiFiUDP udp; @@ -24,7 +25,7 @@ void setupWiFi() { void sendWiFi(const uint8_t *buf, int len) { if (WiFi.softAPIP() == IPAddress(0, 0, 0, 0) && WiFi.status() != WL_CONNECTED) return; - udp.beginPacket(WiFi.softAPBroadcastIP(), WIFI_UDP_REMOTE_PORT); + udp.beginPacket(udp.remoteIP() ? udp.remoteIP() : WIFI_UDP_REMOTE_ADDR, WIFI_UDP_REMOTE_PORT); udp.write(buf, len); udp.endPacket(); } diff --git a/gazebo/wifi.h b/gazebo/wifi.h index ba9ce66..426f2d8 100644 --- a/gazebo/wifi.h +++ b/gazebo/wifi.h @@ -13,6 +13,7 @@ #define WIFI_UDP_PORT 14580 #define WIFI_UDP_REMOTE_PORT 14550 +#define WIFI_UDP_REMOTE_ADDR "255.255.255.255" int wifiSocket; @@ -35,7 +36,7 @@ void sendWiFi(const uint8_t *buf, int len) { if (wifiSocket == 0) setupWiFi(); sockaddr_in addr; // remote address addr.sin_family = AF_INET; - addr.sin_addr.s_addr = INADDR_BROADCAST; // send UDP broadcast + addr.sin_addr.s_addr = inet_addr(WIFI_UDP_REMOTE_ADDR); addr.sin_port = htons(WIFI_UDP_REMOTE_PORT); sendto(wifiSocket, buf, len, 0, (sockaddr *)&addr, sizeof(addr)); }