Add station-only WiFi UDP bridge with eight authenticated peers
This commit is contained in:
1 parent
7bc3aeb234
commit
5e25faa3d0
45 files changed
+2699
-35
No files matched your search
@@ -2,17 +2,20 @@
|
||||
|
||||
// Included by the infrastructure main files after the mesh and transport objects.
|
||||
#include <helpers/WirelessControl.h>
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE) || (defined(MESH_PRIMARY_ESPNOW) && MESH_PRIMARY_ESPNOW))
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE) || defined(WITH_UDP_BRIDGE) || (defined(MESH_PRIMARY_ESPNOW) && MESH_PRIMARY_ESPNOW))
|
||||
#include <WiFi.h>
|
||||
#include <helpers/esp32/WiFiRadioPolicy.h>
|
||||
#endif
|
||||
|
||||
class InfrastructureWirelessBackend : public mesh::wireless::Backend {
|
||||
bool wifi_saved_ = false, resume_web_ = false, resume_mqtt_ = false;
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
bool resume_udp_ = false;
|
||||
#endif
|
||||
public:
|
||||
uint8_t available() const override {
|
||||
uint8_t mask = 0;
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE))
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE) || defined(WITH_UDP_BRIDGE))
|
||||
mask |= mesh::wireless::WiFi;
|
||||
#endif
|
||||
#if defined(WITH_ESPNOW_BRIDGE) || (defined(MESH_PRIMARY_ESPNOW) && MESH_PRIMARY_ESPNOW)
|
||||
@@ -31,6 +34,9 @@ public:
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (the_mesh.isMqttBridgeRunning()) mask |= mesh::wireless::WiFi;
|
||||
#endif
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
if (the_mesh.isUDPBridgeNetworkEnabled()) mask |= mesh::wireless::WiFi;
|
||||
#endif
|
||||
#ifdef WITH_ESPNOW_BRIDGE
|
||||
if (the_mesh.isEspNowBridgeRunning()) mask |= mesh::wireless::EspNow;
|
||||
#endif
|
||||
@@ -56,7 +62,7 @@ public:
|
||||
}
|
||||
mesh::wireless::Result set(uint8_t service, bool on) override {
|
||||
using mesh::wireless::Result;
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE))
|
||||
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE) || defined(WITH_UDP_BRIDGE))
|
||||
if (service == mesh::wireless::WiFi) {
|
||||
if (!on) {
|
||||
if (board.isOTAUpdateRunning()) {
|
||||
@@ -69,9 +75,15 @@ public:
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
resume_mqtt_ = the_mesh.isMqttBridgeRunning();
|
||||
#endif
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
resume_udp_ = the_mesh.isUDPBridgeConfigured();
|
||||
#endif
|
||||
wifi_saved_ = true;
|
||||
}
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
if (!the_mesh.setUDPBridgeNetworkState(false)) return Result::Failed;
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (!the_mesh.setMqttBridgeState(false)) return Result::Failed;
|
||||
#endif
|
||||
@@ -97,8 +109,13 @@ public:
|
||||
}
|
||||
#ifdef WITH_WEBCONFIG
|
||||
if (the_mesh.isWebConfigStopping()) return Result::Pending;
|
||||
if (resume_web_ || (!wifi_saved_ && !(enabled() & mesh::wireless::WiFi))
|
||||
|| (wifi_saved_ && !resume_web_ && !resume_mqtt_)) {
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
const bool udp_station_requested = resume_udp_ || (!wifi_saved_ && the_mesh.isUDPBridgeConfigured());
|
||||
#else
|
||||
const bool udp_station_requested = false;
|
||||
#endif
|
||||
if (resume_web_ || (!udp_station_requested && ((!wifi_saved_ && !(enabled() & mesh::wireless::WiFi))
|
||||
|| (wifi_saved_ && !resume_web_ && !resume_mqtt_)))) {
|
||||
char reply[160];
|
||||
if (!the_mesh.startWebConfig(false, reply)) return Result::Failed;
|
||||
}
|
||||
@@ -111,6 +128,11 @@ public:
|
||||
) {
|
||||
if (!the_mesh.setMqttBridgeState(true)) return Result::Failed;
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_UDP_BRIDGE
|
||||
if ((resume_udp_ || (!wifi_saved_ && the_mesh.isUDPBridgeConfigured()))
|
||||
&& !the_mesh.setUDPBridgeNetworkState(true)) return Result::Failed;
|
||||
resume_udp_ = false;
|
||||
#endif
|
||||
wifi_saved_ = resume_web_ = resume_mqtt_ = false;
|
||||
return (enabled() & mesh::wireless::WiFi) ? Result::Done : Result::Failed;
|
||||
|
||||
Reference in new issue
Block a user