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.
This commit is contained in:
Oleg Kalachev
2025-08-27 05:01:07 +03:00
parent d47d7b8bd4
commit 10fafbc4a0
2 changed files with 4 additions and 2 deletions

View File

@@ -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();
}

View File

@@ -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));
}