mirror of
https://github.com/meshtastic/firmware.git
synced 2026-02-03 15:42:02 +00:00
Compare commits
3 Commits
m5-shutdow
...
udp-cleanu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a08e7f07ff | ||
|
|
c8a9cdc148 | ||
|
|
644fa5b54e |
@@ -2213,8 +2213,8 @@ bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location,
|
||||
} else if (location == meshtastic_AdminMessage_BackupLocation_SD) {
|
||||
// TODO: After more mainline SD card support
|
||||
}
|
||||
return success;
|
||||
#endif
|
||||
return success;
|
||||
}
|
||||
|
||||
/// Record an error that should be reported via analytics
|
||||
|
||||
@@ -22,10 +22,14 @@
|
||||
class UdpMulticastHandler final
|
||||
{
|
||||
public:
|
||||
UdpMulticastHandler() { udpIpAddress = IPAddress(224, 0, 0, 69); }
|
||||
UdpMulticastHandler() : isRunning(false) { udpIpAddress = IPAddress(224, 0, 0, 69); }
|
||||
|
||||
void start()
|
||||
{
|
||||
if (isRunning) {
|
||||
LOG_DEBUG("UDP multicast already running");
|
||||
return;
|
||||
}
|
||||
if (udp.listenMulticast(udpIpAddress, UDP_MULTICAST_DEFAUL_PORT, 64)) {
|
||||
#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO)
|
||||
LOG_DEBUG("UDP Listening on IP: %u.%u.%u.%u:%u", udpIpAddress[0], udpIpAddress[1], udpIpAddress[2], udpIpAddress[3],
|
||||
@@ -34,11 +38,24 @@ class UdpMulticastHandler final
|
||||
LOG_DEBUG("UDP Listening on IP: %s", WiFi.localIP().toString().c_str());
|
||||
#endif
|
||||
udp.onPacket([this](AsyncUDPPacket packet) { onReceive(packet); });
|
||||
isRunning = true;
|
||||
} else {
|
||||
LOG_DEBUG("Failed to listen on UDP");
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
if (!isRunning) {
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("Stopping UDP multicast");
|
||||
#if !defined(ARCH_NRF52)
|
||||
udp.close();
|
||||
#endif
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
void onReceive(AsyncUDPPacket packet)
|
||||
{
|
||||
size_t packetLength = packet.length();
|
||||
@@ -92,5 +109,6 @@ class UdpMulticastHandler final
|
||||
private:
|
||||
IPAddress udpIpAddress;
|
||||
AsyncUDP udp;
|
||||
bool isRunning;
|
||||
};
|
||||
#endif // HAS_UDP_MULTICAST
|
||||
@@ -391,6 +391,11 @@ static void WiFiEvent(WiFiEvent_t event)
|
||||
LOG_INFO("Disconnected from WiFi access point");
|
||||
#ifdef WIFI_LED
|
||||
digitalWrite(WIFI_LED, LOW);
|
||||
#endif
|
||||
#if HAS_UDP_MULTICAST
|
||||
if (udpHandler) {
|
||||
udpHandler->stop();
|
||||
}
|
||||
#endif
|
||||
if (!isReconnecting) {
|
||||
WiFi.disconnect(false, true);
|
||||
@@ -417,6 +422,11 @@ static void WiFiEvent(WiFiEvent_t event)
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
LOG_INFO("Lost IP address and IP address is reset to 0");
|
||||
#if HAS_UDP_MULTICAST
|
||||
if (udpHandler) {
|
||||
udpHandler->stop();
|
||||
}
|
||||
#endif
|
||||
if (!isReconnecting) {
|
||||
WiFi.disconnect(false, true);
|
||||
syslog.disable();
|
||||
|
||||
Reference in New Issue
Block a user