Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Add parameter WIFI_BROADCAST for always broadcasting mode May be used in some cases, like multiple gcs

Oleg Kalachev070eb8a0de57
diff --git a/flix/parameters.ino b/flix/parameters.ino
index ebabaaf..25c74a5 100644
--- a/flix/parameters.ino
+++ b/flix/parameters.ino
@@ -9,7 +9,7 @@
extern int channelZero[16], channelMax[16];
extern int rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel;
extern int rcRxPin, voltagePin;
-extern int wifiMode, wifiLongRange, udpLocalPort, udpRemotePort, espnowChannel;
+extern int wifiMode, wifiLongRange, wifiBroadcast, udpLocalPort, udpRemotePort, espnowChannel;
extern float rcLossTimeout, descendTime, disarmTilt;
extern float voltageScale;
extern LowPassFilter<float> voltageFilter;
@@ -112,6 +112,7 @@ Parameter parameters[] = {
{"WIFI_PORT_LOC", &udpLocalPort},
{"WIFI_PORT_REM", &udpRemotePort},
{"WIFI_LONG_RANGE", &wifiLongRange},
+ {"WIFI_BROADCAST", &wifiBroadcast},
// espnow
{"ESPNOW_CHANNEL", &espnowChannel},
// mavlink
diff --git a/flix/wifi.ino b/flix/wifi.ino
index 253a1a0..778e422 100644
--- a/flix/wifi.ino
+++ b/flix/wifi.ino
@@ -17,6 +17,7 @@ const int W_DISABLED = 0, W_AP = 1, W_STA = 2, W_ESPNOW = 3;
int wifiMode = W_AP;
int wifiLongRange = 0;
+int wifiBroadcast = 0; // 0 - broadcast until connected, 1 - always broadcast
int udpLocalPort = 14550;
int udpRemotePort = 14550;
IPAddress udpRemoteIP = "255.255.255.255";
@@ -64,7 +65,8 @@ void sendWiFi(const uint8_t *buf, int len) {
if (WiFi.softAPgetStationNum() == 0 && !WiFi.isConnected()) return;
- udp.beginPacket(t - mavlinkTime < 5 ? udpRemoteIP : IPAddress(255, 255, 255, 255), udpRemotePort); // broadcast if lost connection
+ bool broadcast = wifiBroadcast || !(t - mavlinkTime < 5); // broadcast if lost connection
+ udp.beginPacket(broadcast ? IPAddress(255, 255, 255, 255) : udpRemoteIP, udpRemotePort);
udp.write(buf, len);
udp.endPacket();
}