@@ -33,7 +33,8 @@ class BridgeUDP final: public UDP {
3333
3434 uint16_t _port; // local port to listen on
3535
36- IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
36+ // IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
37+ String _remoteHost;
3738 uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
3839 uint16_t _offset; // offset into the packet being sent
3940 uint16_t _remaining; // remaining bytes of incoming packet yet to be processed
@@ -51,13 +52,48 @@ class BridgeUDP final: public UDP {
5152 }
5253
5354 k_mutex_lock (&udp_mutex, K_FOREVER);
55+
56+ String hostname = " 0.0.0.0" ;
57+ const bool resp = bridge->call (UDP_CONNECT_METHOD, connection_id, hostname, port);
58+
59+ if (!resp) {
60+ atomic_set (&_connected, 0 );
61+ k_mutex_unlock (&udp_mutex);
62+ return 0 ;
63+ }
64+ atomic_set (&_connected, 1 );
65+
5466 _port = port;
5567 k_mutex_unlock (&udp_mutex);
5668
5769 return 1 ;
5870 }
5971
60- uint8_t beginMulticast (IPAddress, uint16_t ) override ;
72+ uint8_t beginMulticast (IPAddress ip, uint16_t port) override {
73+
74+ if (connected ()) return 1 ;
75+
76+ if (!init ()) {
77+ return 0 ;
78+ }
79+
80+ k_mutex_lock (&udp_mutex, K_FOREVER);
81+
82+ String hostname = ip.toString ();
83+ const bool resp = bridge->call (UDP_CONNECT_MULTI_METHOD, connection_id, hostname, port);
84+
85+ if (!resp) {
86+ atomic_set (&_connected, 0 );
87+ k_mutex_unlock (&udp_mutex);
88+ return 0 ;
89+ }
90+ atomic_set (&_connected, 1 );
91+
92+ _port = port;
93+ k_mutex_unlock (&udp_mutex);
94+
95+ return 1 ;
96+ }
6197
6298 void stop () override {
6399 k_mutex_lock (&udp_mutex, K_FOREVER);
@@ -79,15 +115,8 @@ class BridgeUDP final: public UDP {
79115
80116 k_mutex_lock (&udp_mutex, K_FOREVER);
81117
82- String hostname = host;
83- const bool resp = bridge->call (UDP_CONNECT_METHOD, connection_id, hostname, port);
84-
85- if (!resp) {
86- atomic_set (&_connected, 0 );
87- k_mutex_unlock (&udp_mutex);
88- return 0 ;
89- }
90- atomic_set (&_connected, 1 );
118+ _remoteHost = host;
119+ _remotePort = port;
91120
92121 k_mutex_unlock (&udp_mutex);
93122
0 commit comments