Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello world support for UDP broadcasts over the LAN on ESP32 #5779

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

thebentern
Copy link
Contributor

Couple of remarks:
I have this hardcoded to the address IPAddress(224, 0, 0, 69), which seems to be fine (for now). I have also pegged the port to 4403 because we know this port already on the TCP api side of things.

I would like to test this out over something like a Tailscale VPN to see if it can work over such network boundaries potentially. I'm not too well versed in lower level socket communications, so we'll see. I'd also like to make a client proxy mode for this too, so that we can enable BLE and serial only devices to play as well.
image

The easiest way to test this locally is to join a couple of ESP32 nodes to your Wifi and set lora.tx_enabled to false

arch/esp32/esp32.ini Show resolved Hide resolved
int32_t runOnce() override
{
canSleep = true;
// TODO: Might consider a heartbeat for discovery or keep alive?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would align this with the store&forward heartbeat mechanism. Could also include a display symbol for the available transports in the long term.

@@ -624,6 +630,12 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
// After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet
if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt)
mqtt->onSend(*p_encrypted, *p, p->channel);
#endif
#if HAS_UDP_MULTICAST
if ((decoded || p_encrypted->pki_encrypted) && !isFromUs(p) && udpThread &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic should be different than for MQTT. The reason for MQTT it is also sending everything it receives is because MQTT is used not only for transport (bridging) but also as client. So a packet directed towards you, which is not rebroadcasted, also ends up on the MQTT server. For UDP I think we should only use onSend() when the Router sends, and thus remove the isFromUs() there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this as well. It makes sense to remove the isFromUs check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to remove isFromUs(p) from Router::send() and remove the complete block out of Router::handleReceived() (since packets received via UDP already arrive here). This way it only sends via UDP if it would via LoRa.
However, if you want it to always rebroadcast over UDP (without decrementing the hop limit, before adding yourself to the traceroute, etc.) then we could do it the same as for MQTT. So depends on whether we see this as a normal hop or more a virtual one.

@GUVWAF
Copy link
Member

GUVWAF commented Jan 7, 2025

Very cool. Eventually we could use this also for control packets like Request-To-Send to better coordinate between multiple nodes without LoRa overhead.

There's some tricky things here since we have only one Router, so the logic for, e.g., retransmissions or (refraining from) rebroadcasting is influenced by all protocols, even if for pure LoRa transport you didn't receive any implicit ACK (same is true for MQTT now).

@Talie5in
Copy link
Contributor

Talie5in commented Jan 8, 2025

Looks like this should be able to work with the RAK13800 ETH Board as well?

https://github.com/RAKWireless/RAK13800-W5100S/blob/main/examples/RAK13800_Ethernet_UDP_W5100S/RAK13800_Ethernet_UDP_W5100S.ino

If so, and how i am reading this PR is... ability to say join, 1-2 or 3 nodes on the same network and allow them to send the packets to/from each other to pass messages around the network? Is that the intention or just one of?

I would like to test this out over something like a Tailscale VPN

UDP Multicast wont go across "interfaces", Tailscale, doesnt support Multicast/Broadcast UDP tailscale/tailscale#11134

OpenVPN and WireGuard "kinda can" with a helper application such as https://github.com/synfinatic/udp-proxy-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants